Skip to main content

escape_djot_inline

Function escape_djot_inline 

Source
pub fn escape_djot_inline(s: &str) -> String
Expand description

Backslash-escape every character that can trigger Djot inline markup, so arbitrary text survives a re-parse verbatim.

jotdown turns \x into an Escape event followed by the literal character, so over-escaping is always round-trip-safe — which is why this takes the whole punctuation set rather than trying to be clever about which occurrences are actually syntactic. Being clever there means tracking Djot’s inline state machine, and being wrong about it silently rewrites the writer’s text.

Block-start markers (#, >, -, …) are not covered here — they are only meaningful at the start of a line, and escaping them mid-sentence would litter ordinary prose with backslashes. Use guard_djot_block_start for those.