@@ -16,6 +16,11 @@ let unescape_omd =
16
16
17
17
let transform_text = escape_mrkdwn
18
18
19
+ let transform_code s =
20
+ (* * Omd.to_markdown escapes Text elements but not Code elements, so we do the same for
21
+ Code elements so that unescape_omd can be applied uniformly to the whole string later *)
22
+ String. substr_replace_all ~pattern: " \\ " ~with_: " \\\\ " @@ escape_mrkdwn s
23
+
19
24
let rec transform_list = List. map ~f: transform
20
25
21
26
and transform_flatten = List. map ~f: transform_list
@@ -43,9 +48,10 @@ and transform = function
43
48
| Html_block _ as e -> Code_block (" " , to_markdown [ e ])
44
49
| Blockquote t -> Blockquote (transform_list t)
45
50
| Img (alt , src , title ) -> transform @@ Url (src, [ Text alt ], title)
46
- | Code_block (_ , str ) -> Code_block (" " , str)
51
+ | Code_block (_ , str ) -> Code_block (" " , transform_code str)
52
+ | Code (_ , str ) -> Code (" " , transform_code str)
47
53
| Text s -> Text (transform_text s)
48
- | (Code _ | Br | Hr | NL | Ref _ | Img_ref _ | Raw _ | Raw_block _ | X _ ) as e -> e
54
+ | (Br | Hr | NL | Ref _ | Img_ref _ | Raw _ | Raw_block _ | X _ ) as e -> e
49
55
50
56
(* unescaping here is a workaround of to_markdown escaping parentheses in text (bug?) *)
51
57
let mrkdwn_of_markdown str = unescape_omd @@ to_markdown @@ transform_list @@ of_string str
0 commit comments