From 02dbe1af375591a8ae75b66f7096e2daf5227a6a Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Fri, 10 Mar 2023 15:48:04 +0100 Subject: [PATCH 1/2] adapt to omd 2.0.0 alpha3, which adds a Table constructor --- builder-web.opam | 2 +- lib/utils.ml | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builder-web.opam b/builder-web.opam index 5dfd9a0..c7c4273 100644 --- a/builder-web.opam +++ b/builder-web.opam @@ -45,7 +45,7 @@ depends: [ "cmdliner" {>= "1.1.0"} "uri" "fmt" {>= "0.8.7"} - "omd" + "omd" {>= "2.0.0~alpha3"} "tar" "owee" "solo5-elftool" {>= "0.3.0"} diff --git a/lib/utils.ml b/lib/utils.ml index c3bd6d2..bb4fa3f 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -74,6 +74,30 @@ module Omd = struct Some (Omd.Definition_list (attr, def_elts)) | Omd.Code_block _ | Omd.Thematic_break _ as v -> Some v + | Omd.Table (attr, inline_alignments, inlines) -> + let inline_alignments = + 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 []) inline_alignments + in + Option.map + (fun inline_alignments -> + let inlines = + 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) + inlines + in + Omd.Table (attr, inline_alignments, inlines)) + inline_alignments and safe_def_elts { term ; defs } = let defs = List.filter_map safe_inline defs in safe_inline term From 92fb616980057462637d3c232d917a5998e3067f Mon Sep 17 00:00:00 2001 From: Robur Date: Mon, 13 Mar 2023 11:41:59 +0000 Subject: [PATCH 2/2] Update omd to 2.0.0~alpha3 --- lib/utils.ml | 16 ++++++++-------- test/markdown_to_html.ml | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/utils.ml b/lib/utils.ml index bb4fa3f..57cc779 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -74,19 +74,19 @@ module Omd = struct Some (Omd.Definition_list (attr, def_elts)) | Omd.Code_block _ | Omd.Thematic_break _ as v -> Some v - | Omd.Table (attr, inline_alignments, inlines) -> - let inline_alignments = + | 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 []) inline_alignments + (Some []) header_row in Option.map - (fun inline_alignments -> - let inlines = + (fun header_row -> + let rows = List.filter_map (fun row -> List.fold_left (fun acc cell -> match acc with @@ -94,10 +94,10 @@ module Omd = struct | Some xs -> Option.map (fun cell -> xs @ [ cell ]) (safe_inline cell)) (Some []) row) - inlines + rows in - Omd.Table (attr, inline_alignments, inlines)) - inline_alignments + Omd.Table (attr, header_row, rows)) + header_row and safe_def_elts { term ; defs } = let defs = List.filter_map safe_inline defs in safe_inline term diff --git a/test/markdown_to_html.ml b/test/markdown_to_html.ml index 4ad62ce..e9c3b17 100644 --- a/test/markdown_to_html.ml +++ b/test/markdown_to_html.ml @@ -3,12 +3,12 @@ let markdown_to_html = Builder_web__Utils.Omd.html_of_string let test_simple () = let markdown = {|# Hello world|} in let html = markdown_to_html markdown in - Alcotest.(check string "simple html" "

Hello world

\n" html) + Alcotest.(check string "simple html" "

Hello world

\n" html) let test_html_script () = let markdown = {|# |} in let html = markdown_to_html markdown in - Alcotest.(check string "html script header" "

Hello world

\n" html) + Alcotest.(check string "html script header" "

Hello world

\n" html) let test_preserve_span_content () = let markdown = {|* My ref