Skip to content

Commit 2efbb8f

Browse files
committed
mrkdwn: use correct escape function
1 parent 29bd179 commit 2efbb8f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/mrkdwn.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ let escape_mrkdwn =
1111
| '&' -> "&"
1212
| c -> String.make 1 c)
1313

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"
1816
https://spec.commonmark.org/0.30/#backslash-escapes
19-
17+
2018
This pertains to '\\', '[', ']', '(', ')', '`', '*' unconditionally,
2119
and '.', '-', '+', '!', '<', '>', '#' depending on chars before/after.
2220
Argument escapeworthy_map can be left blank because escaped chars are
2321
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:'\\'
2626

2727
let transform_text = escape_mrkdwn
2828

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
3333

3434
let rec transform_list = List.map ~f:transform
3535

0 commit comments

Comments
 (0)