Skip to content

Commit 7a2b9fb

Browse files
committed
fix: the tests were not passing anymore
Due to recent deep-but-small changes, some tests were not passing anymore. This commit fixes what is important to fix, the test battery is not fully passing but the cases with known issues are minor issues. Implementation details: this fix mainly concerns `\n`-related issues at the backend level. modified: omd_backend.ml modified: omd_parser.ml
1 parent add10db commit 7a2b9fb

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/omd_backend.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ let rec html_and_headers_of_md
221221
loop indent tl
222222
end
223223
end
224+
| Paragraph [] :: tl -> loop indent tl
224225
| Paragraph md as e :: tl ->
225226
begin match override e with
226227
| Some s ->
@@ -234,7 +235,7 @@ let rec html_and_headers_of_md
234235
begin
235236
Buffer.add_string b "<p>";
236237
Buffer.add_string b (remove_trailing_blanks s);
237-
Buffer.add_string b "</p>";
238+
Buffer.add_string b "</p>\n";
238239
end);
239240
loop indent tl
240241
end
@@ -876,14 +877,15 @@ let rec markdown_of_md md =
876877
| Img_ref(rc, name, alt, fallback) :: tl ->
877878
if !references = None then references := Some rc;
878879
loop list_indent (Raw(fallback#to_string)::tl)
880+
| Paragraph [] :: tl -> loop list_indent tl
879881
| Paragraph md :: tl ->
880882
if is_in_list then
881883
if fst_p_in_li then
882884
add_spaces (list_indent-2)
883885
else
884886
add_spaces list_indent;
885887
loop ~fst_p_in_li:false list_indent md;
886-
if tl <> [] then Printf.bprintf b "\n\n";
888+
Printf.bprintf b "\n\n";
887889
loop ~fst_p_in_li:false list_indent tl
888890
| Img(alt, src, title) :: tl ->
889891
Printf.bprintf b "![%s](%s \"%s\")" alt src title;
@@ -1071,8 +1073,8 @@ let rec markdown_of_md md =
10711073
| (Html_block(tagname, attrs, body))::tl ->
10721074
let is_p =
10731075
match tl with
1074-
| NL :: Paragraph _ :: _
1075-
| Paragraph _ :: _ -> true
1076+
| NL :: Paragraph p :: _
1077+
| Paragraph p :: _ -> p <> []
10761078
| _ -> false
10771079
in
10781080
if body = [] && StringSet.mem tagname html_void_elements then
@@ -1137,9 +1139,10 @@ let rec markdown_of_md md =
11371139
Buffer.add_string b "\n";
11381140
loop list_indent tl
11391141
| NL :: tl ->
1140-
if Buffer.length b > 1 &&
1141-
not(Buffer.nth b (Buffer.length b - 1) = '\n'
1142-
&& Buffer.nth b (Buffer.length b - 2) = '\n')
1142+
if Buffer.length b = 1
1143+
|| (Buffer.length b > 1 &&
1144+
not(Buffer.nth b (Buffer.length b - 1) = '\n'
1145+
&& Buffer.nth b (Buffer.length b - 2) = '\n'))
11431146
then
11441147
Buffer.add_string b "\n";
11451148
loop list_indent tl

src/omd_parser.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,6 @@ struct
620620
List.rev accu
621621
| Blockquote b1 :: Blockquote b2 :: tl ->
622622
loop cp accu (Blockquote(b1@b2):: tl)
623-
| Blockquote b1 :: (NL|Br as x) :: Blockquote b2 :: tl ->
624-
loop cp accu (Blockquote(b1@(x::b2)):: tl)
625623
| Blockquote b :: tl ->
626624
let e = Blockquote(loop [] [] b) in
627625
(match cp with
@@ -2163,13 +2161,16 @@ let read_until_space ?(bq=false) ?(no_nl=false) l =
21632161
| Newline::Greaterthan::Spaces n::tl ->
21642162
assert(n>0);
21652163
loop (Newline::cl@block) [Spaces(n-1)] tl
2164+
2165+
(* multi paragraph blockquotes with empty lines *)
21662166
| Newlines 0::Greaterthan::Space::tl ->
21672167
loop (Newlines 0::cl@block) [] tl
21682168
| Newlines 0::Greaterthan::Spaces 0::tl ->
21692169
loop (Newlines 0::cl@block) [Space] tl
21702170
| Newlines 0::Greaterthan::Spaces n::tl ->
21712171
assert(n>0);
21722172
loop (Newlines 0::cl@block) [Spaces(n-1)] tl
2173+
21732174
| (Newlines _::_ as l) | ([] as l) -> fix(List.rev(cl@block)), l
21742175
| e::tl -> loop block (e::cl) tl
21752176
in

0 commit comments

Comments
 (0)