Markdown source can never reach the reader as markup
A markdown-to-HTML conversion usually runs over text a language model wrote, so the encoding is a safety boundary rather than a formatting nicety. Encoding the whole input once, before any block or inline pattern is applied, is the arrangement that makes the promise hold on every arm: escaping at each emission point has been shown to miss the blocks a converter rebuilds from its buffer, and to miss any block whose first character is already a tag.
The rule
- Every text node a markdown-to-HTML conversion emits must be HTML-encoded: prose, list items, blockquote lines, headings and code alike.
- Markup present in the markdown source must never reach the reader as markup, including where a block opens with a tag.
What it means
Encoding happens over the whole input before any block or inline pattern is applied — not at each place text later gets written out. The clause that bites is the one about where a block starts: a block whose very first character is a tag does not get a free pass just because it looks, at that point, like it is already built. Nothing survives from the source that the conversion did not write itself, wherever in the block it sits.
Example
Markup buried inside a line of prose:
"Hello <script>alert(1)</script> there""<p>Hello <script>alert(1)</script> there</p>"The same holds when the tag is the very first thing in the block, not something the paragraph wraps around:
"<script>alert(1)</script>""<p><script>alert(1)</script></p>"