Repository navigation
Conversation
Text that matched the trailing-space branch of the text handler skipped `state.safe`, so escapes such as `\#`, `1\.` and a `\|` between code spans in a table cell were lost on save. Keep the outer whitespace raw and pass only the text between it through `state.safe`. Closes Milkdown#2527
|
@0z5a is attempting to deploy a commit to the Milkdown Team on Vercel. A member of the Team first needs to authorize it. |
|
This branch has not been deployed
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.
Summary
Closes #2527
The
texthandler inremark-handlers.tsreturns text that matches/^[^*_\\]*\s+$/as it is, withoutstate.safe. That branch came in with #2058 to stop a trailing space from turning into . But text in front of inline code, a link or emphasis often ends with a space, so its escapes get dropped too.\# not a heading `code`comes back as a heading, and`boolean` \| `string`in a table cell comes back as two cells.With this change the branch still keeps the leading and trailing whitespace raw, so #2058 keeps working. The text between them now goes through
state.safe, with the whitespace passed asbefore/afterso the unsafe patterns see the right context.How I found it
I round-tripped 500 README files through an editor with
commonmark+gfmand compared the markdown-it render of each source with the render of the output, block by block. Three files lost blocks this way: a props table with`number` \| `string`in its type column got extra cells, a wrapped paragraph with a line that starts with1.turned into an ordered list, and wrapped lines that start with-inside a list item turned into a nested list. In each case the text ends with a space before a code span or**strong**.Where this can show up in practice
Option tables in docs often have a type column like
`boolean` \| `string`. Loading one of those into the editor and typing anything rewrites the table with an extra column. I haven't seen a field report.How did you test this change?
preset-commonmark(15 tests) andpreset-gfm(4 tests). They cover\#,1\.,\-,\>,\&,\~\~, a\|between code spans in a table cell (from markdown and from a doc built in code), and text before a link and before**strong**. All 19 fail onmainand pass with the change. Each case checks the markdown output and that parsing it again gives the same doc."a b "and" a b "and the linea **b** cserialize exactly as onmain, and that" # x "before a code span keeps both outer spaces.vitest runinpreset-commonmark(147 passed),preset-gfm(40 passed) andcore(4 passed).tsc -b packages/plugins/preset-gfm/tsconfig.jsonexits 0 (it includes core and commonmark).oxfmt --checkis clean on the changed files.oxlint --deny-warningsreports nothing in the changed files; repo-wide it shows the same 76 warnings in other packages onmainand with this change. in the output did not change.\n(a newline then a space) now gets for that space, which is what the non-fast path already did. The parser does not produce such a node (it turns the line break into ahardbreak), so I could only reach it from a doc built in code. Onmainthat space is lost when the output is parsed again.Platform: macOS