Skip to content

Commit

Permalink
Copy images in <picture> tags too
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidDev committed Jun 20, 2024
1 parent 240e7ba commit 8e5367a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/doc_emit/html_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ let emit_link ~options c l =
(** If [link] is a relative path, then resolve the file (relative to [md_file]) and
{!Html_assets.find_asset copy it into the destination directory} *)
let resolve_asset_link ~md_file ~(options : Html_options.t) link =
print_endline ("Resolving " ^ link);
let uri = Uri.of_string link in
match
(Uri.scheme uri, Uri.userinfo uri, Uri.host uri, Uri.port uri, Uri.query uri, Uri.fragment uri)
Expand Down Expand Up @@ -217,16 +218,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
Expand Down

0 comments on commit 8e5367a

Please sign in to comment.