pub fn escape_html_syntax(text: &str) -> StringExpand description
text with what a Markdown reader would take for HTML escaped: a < that can open a tag,
a comment, a declaration, a processing instruction or an autolink, and a & that starts
a character reference.
Text written into Markdown is read for inline HTML (CommonMark §6.6–6.7): Vec<String>
shows as Vec with an unknown tag swallowed, a <b>bold</b> turns bold, AT&T
shows as AT&T. A < is escaped unless the character after it cannot start any of those
— a space, a digit, =, … — and a < that ends text is escaped too, since the next
piece written after it may start with a letter. A & is escaped only where a character
reference starts (&name;, &#…;), so R&D and a & b are left alone.
text may already be escaped for Markdown (\\ for a backslash); apply this after that.
use unparser_shared::markdown::escape_html_syntax;
assert_eq!(escape_html_syntax("Vec<String>"), r"Vec\<String>");
assert_eq!(escape_html_syntax("a <b>bold</b>"), r"a \<b>bold\</b>");
assert_eq!(escape_html_syntax("AT&T, R&D, 1 < 2"), r"AT\&T, R&D, 1 < 2");