Skip to content

Commit 1713e7e

Browse files
committed
mrkdwn: document commonmark escaping behavior
1 parent 0003f45 commit 1713e7e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/mrkdwn.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ 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"
18+
https://spec.commonmark.org/0.30/#backslash-escapes
19+
20+
This pertains to '\\', '[', ']', '(', ')', '`', '*' unconditionally,
21+
and '.', '-', '+', '!', '<', '>', '#' depending on chars before/after.
22+
Argument escapeworthy_map can be left blank because escaped chars are
23+
unescaped to themselves. *)
1424
let unescape_omd =
15-
Staged.unstage @@ String.Escaping.unescape_gen_exn ~escapeworthy_map:[ '(', '('; ')', ')' ] ~escape_char:'\\'
25+
Staged.unstage @@ String.Escaping.unescape_gen_exn ~escapeworthy_map:[] ~escape_char:'\\'
1626

1727
let transform_text = escape_mrkdwn
1828

@@ -53,5 +63,4 @@ and transform = function
5363
| Text s -> Text (transform_text s)
5464
| (Br | Hr | NL | Ref _ | Img_ref _ | Raw _ | Raw_block _ | X _) as e -> e
5565

56-
(* unescaping here is a workaround of to_markdown escaping parentheses in text (bug?) *)
5766
let mrkdwn_of_markdown str = unescape_omd @@ to_markdown @@ transform_list @@ of_string str

0 commit comments

Comments
 (0)