fix(storage-walker): keep <br/> inside list items as a hard line break - #248
Merged
Merged
Conversation
A <br/> inside a list item rendered as a newline, which the item's inline whitespace collapse then turned into a single space. While walking whitespace-collapsed inline content (list items, table cells, task bodies), <br/> now emits a private-use HARD_BREAK sentinel (U+E002) that survives the collapse; the outermost such context resolves it: - list items and task bodies emit a CommonMark backslash hard break with the continuation indented to the content column, and escape continuation lines that would otherwise start a block (list marker, heading, blockquote, fence, setext underline, thematic break); - table cells emit inline <br>, since GFM rows cannot span lines. Both forms convert back to <br /> on markdown → storage. <br/> inside a code span and at the top level keeps its previous output. Literal U+E002 in user content is reversibly escaped like the other sentinels. Fixes #242
- Move HARD_BREAK to U+E003 so it does not collide with the U+E002 sentinel planned for blockquote handling. - Double an odd trailing backslash run before a hard break (`C:\temp\<br/>`) so it stays literal and the break survives the round trip. - Escape a continuation line that is a GFM table delimiter row, which would otherwise turn the item's text into a table. - Extract renderInlineRun for the shared collapse + resolve pipeline. - Tighten tests to exact output and full round trips, and cover header and multi-cell rows, 10. markers, link labels, inline HTML, ac:link-body, lists in callouts/blockquotes and <pre> in cells.
# Conflicts: # lib/markdown-cleanup.js # lib/storage-walker.js # tests/macro-converter.test.js # tests/markdown-cleanup.test.js
|
🎉 This PR is included in version 2.25.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Pull Request Template
Description
Fixes #242. In storage → markdown,
<br/>inside a list item became a space. The walker emitted\n, and the item's inline whitespace collapse (added in #239) then erased it.While the walker is inside whitespace-collapsed inline content (list items, table cells, task bodies),
<br/>now emits a private-useHARD_BREAKsentinel (U+E003) that survives the collapse. The outermost such context resolves it:<ul><li>line1<br/>line2</li></ul>- line1\line2<li>line1<br />line2</li>…<ac:task-body>a<br/>b</ac:task-body>…- [ ] a\b<li>[ ] a<br />b</li><td>a<br/>b</td>| a<br>b |<td><p>a<br />b</p></td>LIST_INDENT. A trailing-two-space break would be stripped bycleanupOutsideFence. Continuation lines that CommonMark would otherwise parse as a new block are backslash-escaped:-,*,+,1.,2),#,>, a backtick or tilde fence,---,===,* * *, and GFM table delimiter rows such as--- | ---. An odd run of trailing backslashes before a break (C:\temp\) gets one more\so it stays literal and the break survives. Inline syntax such as**bold**or a code span is left alone.<br>, because GFM rows cannot span lines.markdownToStoragealready normalizes<br>to<br />([BUG] Markdown line breaks generate invalid XHTML <br> instead of <br /> (fails on Confluence On-Premise) #210). Lists and tasks nested in a cell leave the sentinel for the cell to resolve.<br/>still emits\n, which is a soft break. This is the same asmainand out of scope for this PR.<br/>inside<code>stays a space, since a code span cannot hold a line break.decodeEntities, like U+E000/U+E001/U+E002 (QUOTE_MARK, fix(storage-walker): keep code blocks inside blockquotes and callouts byte-exact #249). Task bodies use the shared list-item path from fix(storage-walker): preserve nested task lists in storage → markdown #245, so their breaks go through the same code.Important
Behavior change (release notes): this affects every
<br/>inside a table cell, not just ones in list items. That includes header cells and<p>, headings, blockquotes, panels, lists, tasks, links and<pre>inside cells, as well as tables nested in lists. Cells previously rendered those breaks as a space and now render them as inline<br>, which round-trips to<br />. For example,| > a > b |becomes| > a<br>b |.Type of Change
Testing
npx jest: 1453/1453 passed (after merging currentmain).npx eslint lib tests: clean. The new#242suite intests/macro-converter.test.jsasserts exact output and markdown → storage → markdown round trips. 27 of its cases fail onmain.Checklist
Screenshots (if applicable)
N/A
Additional Context
07-tables.expected.mdchanges intentionally:line one line twobecomesline one<br>line two.lib/html-to-markdown.jsis a separate converter and still renders<br>as a space in list items and table cells. That is a follow-up.