Skip to main content

escape_md

Function escape_md 

Source
pub fn escape_md(value: &str) -> String
Expand description

Escape a string for inclusion in a Markdown table cell.

Table cells render through GitHub-Flavored Markdown and GitLab Flavored Markdown as inline content, so cell-internal markers can flip the cell to emphasis, link, image, code, HTML, or strikethrough. Newlines collapse to spaces because a literal newline terminates the table row. The escape set covers every CommonMark inline construct that can fire mid-cell:

  • \ (escape character itself)
  • ` (inline code)
  • * _ (emphasis / strong)
  • [ ] ( ) (link / image syntax)
  • ! (image when followed by [)
  • < > (raw HTML / autolinks)
  • # (cell rendered as heading when first character of the cell)
  • | (table cell separator)
  • ~ (strikethrough on GFM)
  • & (HTML numeric / named entity decode: &#42; would otherwise render as * after our escape and reintroduce the bypass)

Line-start markers (., -, +, 1.) are intentionally NOT escaped: they are only meaningful at the start of a block-level line, and table cells render as paragraph-equivalent inline content where these are inert. Escaping them produces visually noisy output (fallow/test\-only-dep) without correctness benefit.