From 7f3a6719e23677147c8e5de0ca442ba083a00ff0 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Thu, 14 Dec 2023 15:10:12 +0100 Subject: [PATCH] require cmarkit 0.3 work around the issue reported at https://github.com/dbuenzli/cmarkit/issues/14 add a second table test, fix the tests for the 0.3 fixed layouting --- builder-web.opam | 2 +- lib/utils.ml | 3 ++- test/markdown_to_html.ml | 42 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/builder-web.opam b/builder-web.opam index 6ee4de6..756f2f6 100644 --- a/builder-web.opam +++ b/builder-web.opam @@ -45,7 +45,7 @@ depends: [ "cmdliner" {>= "1.1.0"} "uri" "fmt" {>= "0.8.7"} - "cmarkit" + "cmarkit" {>= "0.3.0"} "tar" "owee" "solo5-elftool" {>= "0.3.0"} diff --git a/lib/utils.ml b/lib/utils.ml index c815724..9802ec9 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -61,7 +61,8 @@ let md_to_html ?adjust_heading ?(safe = true) data = in let h' = make ?id ~layout ~level:(level + lvl) inline in Mapper.ret (Block.Heading (h', meta)) - | _ -> Mapper.default + | Block.Blocks _ -> Mapper.default + | x -> Mapper.ret x in let mapper = Mapper.make ~block () in Mapper.map_doc mapper doc) diff --git a/test/markdown_to_html.ml b/test/markdown_to_html.ml index 75e3849..6c56fd3 100644 --- a/test/markdown_to_html.ml +++ b/test/markdown_to_html.ml @@ -112,30 +112,65 @@ let test_table () = |__} in let html = markdown_to_html ~adjust_heading:2 markdown in - (* NB: the maximum heading is 6 in cmarkit, thus we reduce the structure *) let exp = {|
+ - + - + + +
a b c d e
entry bla.file other.file
another entry another.file another.other
|} in + Alcotest.(check string "table is rendered as html" exp html) + +let test_table2 () = + let markdown = {__|| a | | b | c | d | e | +| --------------------- |-| -------------- | -------------- | --------------- | ------ | +| entry | | | | **bla.file** | **other.file** | +| _another entry_ | | | **another.file** | **another.other** | | +|__} + in + let html = markdown_to_html ~adjust_heading:2 markdown in + let exp = {|
+ + + + + + + + + + + + + + + + + + + + + +
abcde
entrybla.fileother.file
another entryanother.fileanother.other
|} in @@ -157,6 +192,7 @@ let markdown_tests = [ Alcotest.test_case "fragment link" `Quick test_fragment_link; Alcotest.test_case "heading adjustment" `Quick test_heading_adjustment; Alcotest.test_case "table" `Quick test_table; + Alcotest.test_case "table2" `Quick test_table2; ] let () =