Skip to content

Commit f9d9bd1

Browse files
committed
add back ticks to doc comment code spans
1 parent 63dc67a commit f9d9bd1

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/markdown/generator.ml

+34-10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ let take_code l =
149149
in
150150
(c, rest)
151151

152+
let rec acc_text (l : Block.t) : string =
153+
match l with
154+
| [] -> ""
155+
| h :: rest -> (
156+
match h.desc with Paragraph i -> inline_text i ^ acc_text rest | _ -> "")
157+
158+
and inline_text (i : Inline.t) =
159+
match i with
160+
| [] -> ""
161+
| h :: rest -> (
162+
match h.desc with
163+
| Text s -> s ^ inline_text rest
164+
| Source s ->
165+
let rec source_text (s' : Source.t) =
166+
match s' with
167+
| [] -> ""
168+
| t :: rest_t -> (
169+
match t with
170+
| Elt i -> inline_text i ^ source_text rest_t
171+
| _ -> "")
172+
in
173+
code_span (source_text s)
174+
| _ -> "")
175+
152176
let rec documented_src (l : DocumentedSrc.t) args nbsps =
153177
let nbsps' = nbsps ++ (nbsp ++ nbsp) in
154178
let noop = paragraph noop in
@@ -176,7 +200,11 @@ let rec documented_src (l : DocumentedSrc.t) args nbsps =
176200
| _ -> Stop_and_keep)
177201
in
178202
let f (content, doc, (anchor : Odoc_document.Url.t option)) =
179-
let doc = match doc with [] -> noop | doc -> block doc args in
203+
let doc =
204+
match doc with
205+
| [] -> noop
206+
| doc -> paragraph (text (acc_text doc))
207+
in
180208
let content =
181209
match content with
182210
| `D code (* for record fields and polymorphic variants *) ->
@@ -216,22 +244,18 @@ and item (l : Item.t list) args nbsps =
216244
| Heading h -> blocks (heading' h args) (continue rest)
217245
| Declaration { attr = _; anchor; content; doc } ->
218246
let decl = documented_src content args nbsps in
219-
let doc = match doc with [] -> noop | doc -> block doc args in
247+
let doc =
248+
match doc with [] -> noop | doc -> paragraph (text (acc_text doc))
249+
in
220250
let item' = blocks decl doc in
221251
if args.generate_links then
222252
let anchor = match anchor with Some x -> x.anchor | None -> "" in
223253
blocks (blocks (paragraph (anchor' anchor)) item') (continue rest)
224254
else blocks item' (continue rest)
225-
| Include
226-
{ attr = _; anchor = _; content = { summary; status; content }; doc }
227-
->
255+
| Include { content = { summary; status; content }; _ } ->
228256
let d =
229257
if inline_subpage status then item content args nbsps
230-
else
231-
let s = source_code summary args in
232-
match doc with
233-
| [] -> paragraph s
234-
| doc -> blocks (paragraph s) (block doc args)
258+
else paragraph (source_code summary args)
235259
in
236260
blocks d (continue rest))
237261

0 commit comments

Comments
 (0)