Repository navigation
Conversation
Text nodes were written straight into the output, so prose containing
Markdown punctuation was re-interpreted as formatting the next time it was
rendered.
Escape the inline characters that can open a construct, escape a leading
character that would turn a paragraph or list item into a heading, list,
blockquote or thematic break, and size inline code delimiters to be longer
than any backtick run they contain.
Underscores are only escaped at word boundaries so identifiers such as
file_name_here stay readable, and an ordered marker is neutralised on its
delimiter ("1\.") because a backslash before a digit is not an escape
sequence and would render literally.
Escaping is skipped inside pre and inline code, where the content is
already literal.
Fixes #16
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b721ad5f-9add-4f55-b9c8-7e6d7b0fb3e7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16.
Problem
Text nodes went straight into the output with no escaping, so prose containing Markdown punctuation was re-read as formatting on the next render.
Change
Three escaping passes, all skipped where content is already literal (
<pre>, inline<code>, and URLs):\`*[]always;~~runs;_only at word boundaries.#,>,-,+, an ordered marker, or a---/===run gets neutralised.Two deliberate refinements:
_is not escaped inside words.file_name_herestays readable rather than becomingfile\_name\_here; intra-word underscores do not open emphasis.1\. text, not\1. text, because a backslash before a digit is not an escape sequence and would render literally.Verification
<p>… multiply 2 * 3 * 4</p>2 * 3 * 42 \* 3 \* 4<p># not a heading</p># not a heading(renders as H1)\# not a heading<p>1. not ordered</p>1. not ordered(renders as a list)1\. not ordered<p>… file_name_here …</p>file_name_herefile_name_here(unchanged)<code>ab``a ` b`(broken)``ab`` `<p>call <code>a_b_c</code></p>`a_b_c``a_b_c`(unchanged)I also ran a full Markdown → HTML → Markdown round trip over a document with headings, emphasis, links, nested lists, tables, a blockquote and a fenced block: no content is corrupted or over-escaped.
dotnet build -c Release -r win-x64succeeds with 0 warnings.Note
That round trip surfaced three further pre-existing defects unrelated to escaping, filed separately as #32, #33 and #34.