From ded21b9131f58eabc2bb16b4875d56a8c1ec61d0 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 22 Nov 2023 12:13:42 +0100 Subject: [PATCH] Enable non-strict mode for cmarkit to render tables --- lib/utils.ml | 2 +- test/markdown_to_html.ml | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/utils.ml b/lib/utils.ml index de7062a..c815724 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -47,7 +47,7 @@ let compare_pkgs p1 p2 = let md_to_html ?adjust_heading ?(safe = true) data = let open Cmarkit in - let doc = Doc.of_string ~heading_auto_ids:true data in + let doc = Doc.of_string ~strict:false ~heading_auto_ids:true data in let doc = Option.fold ~none:doc ~some:(fun lvl -> diff --git a/test/markdown_to_html.ml b/test/markdown_to_html.ml index 950af28..75e3849 100644 --- a/test/markdown_to_html.ml +++ b/test/markdown_to_html.ml @@ -104,6 +104,43 @@ let test_heading_adjustment () = |} in Alcotest.(check string "header adjustment works fine" exp html) +let test_table () = + 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 + (* NB: the maximum heading is 6 in cmarkit, thus we reduce the structure *) + let exp = {|
+ + + + + + + + + + + + + + + + + + + + + + + + +
abcde
entrybla.fileother.file
another entryanother.fileanother.other
|} in + Alcotest.(check string "table is rendered as html" exp html) + let markdown_tests = [ Alcotest.test_case "Simple" `Quick test_simple; Alcotest.test_case "script header" `Quick test_html_script; @@ -119,6 +156,7 @@ let markdown_tests = [ Alcotest.test_case "absolute image with script alt" `Quick test_absolute_image_script_alt; 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; ] let () =