···
(* Inline elements - preserve space tracking *)
+
(* Add space before if needed *)
+
if !need_space then begin
+
match last_char () with
+
| Some (' ' | '\n') -> ()
+
| _ -> Buffer.add_char buffer ' '
Buffer.add_string buffer "**";
Soup.children elem |> Soup.iter process_node;
Buffer.add_string buffer "**";
+
(* Add space before if needed *)
+
if !need_space then begin
+
match last_char () with
+
| Some (' ' | '\n') -> ()
+
| _ -> Buffer.add_char buffer ' '
Buffer.add_string buffer "*";
Soup.children elem |> Soup.iter process_node;
Buffer.add_string buffer "*";
+
(* Add space before if needed *)
+
if !need_space then begin
+
match last_char () with
+
| Some (' ' | '\n') -> ()
+
| _ -> Buffer.add_char buffer ' '
Buffer.add_string buffer "`";
Soup.children elem |> Soup.iter process_node;
···
let href = Soup.attribute "href" elem in
+
(* Add space before link if needed *)
+
if !need_space then begin
+
match last_char () with
+
| Some (' ' | '\n') -> ()
+
| _ -> Buffer.add_char buffer ' '
+
(* Add the link markdown *)
Buffer.add_string buffer (Printf.sprintf "<%s>" href)
Buffer.add_string buffer (Printf.sprintf "[%s](%s)" text href);
+
(* Mark that space may be needed after link *)
···
Buffer.add_string buffer "\n\n";
+
(* Add space before if needed *)
+
if !need_space then begin
+
match last_char () with
+
| Some (' ' | '\n') -> ()
+
| _ -> Buffer.add_char buffer ' '
let alt = Soup.attribute "alt" elem |> Option.value ~default:"" in
let src = Soup.attribute "src" elem |> Option.value ~default:"" in
Buffer.add_string buffer (Printf.sprintf "" alt src);