From 43ee16c379ae60dc1ebc65d665f2418522bf9f25 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 20 Jun 2024 18:06:20 +0100 Subject: [PATCH] Copy images in tags too --- src/doc_emit/html_md.ml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/doc_emit/html_md.ml b/src/doc_emit/html_md.ml index 78268f4..cd0603c 100644 --- a/src/doc_emit/html_md.ml +++ b/src/doc_emit/html_md.ml @@ -217,16 +217,19 @@ let emit_block_html ~path ~options c block = | (k', _) :: xs when k = k' -> (k, v) :: xs | kv :: xs -> kv :: set_assoc k v xs in + let replace_asset_link ~attr name attrs e = + match + List.assoc_opt ("", attr) attrs + |> CCOption.flat_map (resolve_asset_link ~md_file ~options) + with + | Some link -> `Start_element (name, set_assoc ("", attr) link attrs) + | None -> e + in let map_signal : Markup.signal -> Markup.signal = function - | `Start_element (name, attrs) as e -> - if name = (Markup.Ns.html, "img") then - match - List.assoc_opt ("", "src") attrs - |> CCOption.flat_map (resolve_asset_link ~md_file ~options) - with - | Some link -> `Start_element (name, set_assoc ("", "src") link attrs) - | None -> e - else e + | `Start_element (((ns, "img") as name), attrs) as e when ns = Markup.Ns.html -> + replace_asset_link ~attr:"src" name attrs e + | `Start_element (((ns, "source") as name), attrs) as e when ns = Markup.Ns.html -> + replace_asset_link ~attr:"srcset" name attrs e | e -> e in Stream.stream block