Skip to content

Commit 38dc061

Browse files
committed
draft
1 parent 1472a4a commit 38dc061

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/markdown/generator.ml

+19-15
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,29 @@ let make_hashes n = String.make n '#'
1515

1616
type args = { generate_links : bool }
1717

18+
let rec source_contains_text (s : Source.t) =
19+
let inline_contains_text (i : Inline.t) =
20+
let check_inline_desc (i : Inline.desc) =
21+
match i with Text "" -> false | Text _ -> true | _ -> true
22+
in
23+
List.exists (fun { Inline.desc = d; _ } -> check_inline_desc d) i
24+
in
25+
let check_source (s : Source.token) =
26+
match s with
27+
| Source.Elt i -> inline_contains_text i
28+
| Tag (_, s) -> source_contains_text s
29+
in
30+
List.exists check_source s
31+
1832
let rec source_code (s : Source.t) args =
1933
match s with
2034
| [] -> noop
2135
| h :: t -> (
22-
let continue s = if s = [] then noop else source_code s args in
36+
let continue s =
37+
if s = [] then noop
38+
else if source_contains_text s then source_code s args
39+
else noop
40+
in
2341
match h with
2442
| Source.Elt i -> inline i args ++ continue t
2543
| Tag (_, s) -> continue s ++ continue t
@@ -130,20 +148,6 @@ let take_code l =
130148
in
131149
(c, rest)
132150

133-
let rec source_contains_text (s : Source.t) =
134-
let inline_contains_text (i : Inline.t) =
135-
let check_inline_desc (i : Inline.desc) =
136-
match i with Text "" -> false | Text _ -> true | _ -> true
137-
in
138-
List.exists (fun { Inline.desc = d; _ } -> check_inline_desc d) i
139-
in
140-
let check_source (s : Source.token) =
141-
match s with
142-
| Source.Elt i -> inline_contains_text i
143-
| Tag (_, s) -> source_contains_text s
144-
in
145-
List.exists check_source s
146-
147151
let rec documented_src (l : DocumentedSrc.t) args nbsps =
148152
let nbsps' = nbsps ++ (nbsp ++ nbsp) in
149153
let noop = paragraph noop in

test/integration/markdown.t/run.t

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,57 @@
88
$ cat markdown/Test.md
99
Test
1010

11-
Module Test
11+
Module Test
1212

1313
# This is a heading
1414

1515
## This has a label
1616

1717
---
1818

19-
######    type t
19+
######    type t
2020

2121
Doc for type t .
2222

23-
######    type y'
23+
######    type y'
2424

25-
######    module Bar : sig ... end
25+
######    module Bar : sig ... end
2626

27-
######    module type Foo = sig
27+
######    module type Foo = sig
2828

29-
######        type foo
29+
######        type foo
3030

3131
docs for x
3232

33-
######        module type Foo' = sig
33+
######        module type Foo' = sig
3434

35-
######            type foo'
35+
######            type foo'
3636

37-
######            type days =
37+
######            type days =
3838

39-
######             | Mon
39+
######             | Mon
4040

4141
first day of the week.
4242

43-
######            type num = [
43+
######            type num = [
4444

45-
######             | `One
45+
######             | `One
4646

47-
######            ]
47+
######            ]
4848

49-
######        end
49+
######        end
5050

51-
######    end
51+
######    end
5252

53-
######    type name = {
53+
######    type name = {
5454

55-
######     fname : string ;
55+
######     fname : string ;
5656

5757
first name
5858

59-
######     lname : string ;
59+
######     lname : string ;
6060

61-
######    }
61+
######    }
6262

6363
## Label
6464

@@ -117,7 +117,7 @@
117117

118118
David Sheets
119119

120-
######    module Foo : sig ... end
120+
######    module Foo : sig ... end
121121

122122
The end foo end keyword in doc comment.
123123

0 commit comments

Comments
 (0)