@@ -11,25 +11,25 @@ let escape_mrkdwn =
11
11
| '&' -> " &"
12
12
| c -> String. make 1 c)
13
13
14
- (* * Unescape markdown characters escaped by Omd.to_markdown
15
-
16
- Omd behaves this way because "any ASCII punctuation character may
17
- be backslash-escaped"
14
+ (* * Unescape markdown characters escaped because "any ASCII punctuation
15
+ character may be backslash-escaped"
18
16
https://spec.commonmark.org/0.30/#backslash-escapes
19
-
17
+
20
18
This pertains to '\\', '[', ']', '(', ')', '`', '*' unconditionally,
21
19
and '.', '-', '+', '!', '<', '>', '#' depending on chars before/after.
22
20
Argument escapeworthy_map can be left blank because escaped chars are
23
21
unescaped to themselves. *)
24
- let unescape_omd =
25
- Staged. unstage @@ String.Escaping. unescape_gen_exn ~escapeworthy_map: [] ~escape_char: '\\'
22
+ let unescape_omd = Staged. unstage @@ String.Escaping. unescape_gen_exn ~escapeworthy_map: [] ~escape_char: '\\'
23
+
24
+ (* * Escape the `escape_char` '\\' for use with `unescape_omd` later *)
25
+ let escape_omd = Staged. unstage @@ String.Escaping. escape_gen_exn ~escapeworthy_map: [] ~escape_char: '\\'
26
26
27
27
let transform_text = escape_mrkdwn
28
28
29
- let transform_code s =
30
- (* * Omd.to_markdown escapes Text elements but not Code elements, so we do the same for
31
- Code elements so that unescape_omd can be applied uniformly to the whole string later *)
32
- String. substr_replace_all ~pattern: " \\ " ~with_: " \\\\ " @@ escape_mrkdwn s
29
+ (* * `Omd.to_markdown` escapes backslash (and other applicable chars) in
30
+ ` Text` elements but not ` Code` elements, so do the same for the latter so
31
+ that ` unescape_omd` can apply uniformly to the whole mrkdwn string later *)
32
+ let transform_code s = escape_omd @@ escape_mrkdwn s
33
33
34
34
let rec transform_list = List. map ~f: transform
35
35
0 commit comments