Merge pull request 'adapt to omd 2.0.0 alpha3, which adds a Table constructor' (#160) from omd-2-alpha3 into main

Reviewed-on: https://git.robur.io/robur/builder-web/pulls/160
This commit is contained in:
Reynir Björnsson 2023-03-13 11:42:35 +00:00
commit 40b31ed691
3 changed files with 27 additions and 3 deletions

View file

@ -45,7 +45,7 @@ depends: [
"cmdliner" {>= "1.1.0"} "cmdliner" {>= "1.1.0"}
"uri" "uri"
"fmt" {>= "0.8.7"} "fmt" {>= "0.8.7"}
"omd" "omd" {>= "2.0.0~alpha3"}
"tar" "tar"
"owee" "owee"
"solo5-elftool" {>= "0.3.0"} "solo5-elftool" {>= "0.3.0"}

View file

@ -74,6 +74,30 @@ module Omd = struct
Some (Omd.Definition_list (attr, def_elts)) Some (Omd.Definition_list (attr, def_elts))
| Omd.Code_block _ | Omd.Code_block _
| Omd.Thematic_break _ as v -> Some v | Omd.Thematic_break _ as v -> Some v
| Omd.Table (attr, header_row, rows) ->
let header_row =
List.fold_left (fun acc (cell, alignment) ->
match acc with
| None -> None
| Some xs ->
Option.map (fun cell -> xs @ [ cell, alignment ])
(safe_inline cell))
(Some []) header_row
in
Option.map
(fun header_row ->
let rows =
List.filter_map (fun row ->
List.fold_left (fun acc cell ->
match acc with
| None -> None
| Some xs -> Option.map (fun cell -> xs @ [ cell ])
(safe_inline cell))
(Some []) row)
rows
in
Omd.Table (attr, header_row, rows))
header_row
and safe_def_elts { term ; defs } = and safe_def_elts { term ; defs } =
let defs = List.filter_map safe_inline defs in let defs = List.filter_map safe_inline defs in
safe_inline term safe_inline term

View file

@ -3,12 +3,12 @@ let markdown_to_html = Builder_web__Utils.Omd.html_of_string
let test_simple () = let test_simple () =
let markdown = {|# Hello world|} in let markdown = {|# Hello world|} in
let html = markdown_to_html markdown in let html = markdown_to_html markdown in
Alcotest.(check string "simple html" "<h1>Hello world</h1>\n" html) Alcotest.(check string "simple html" "<h1 id=\"hello-world\">Hello world</h1>\n" html)
let test_html_script () = let test_html_script () =
let markdown = {|# <script>Hello world</script>|} in let markdown = {|# <script>Hello world</script>|} in
let html = markdown_to_html markdown in let html = markdown_to_html markdown in
Alcotest.(check string "html script header" "<h1>Hello world</h1>\n" html) Alcotest.(check string "html script header" "<h1 id=\"hello-world\">Hello world</h1>\n" html)
let test_preserve_span_content () = let test_preserve_span_content () =
let markdown = {|* <span id="myref">My ref</span> let markdown = {|* <span id="myref">My ref</span>