fix(mdxish): tone down empty line addition preprocessing after html blocks#1344
Conversation
| [/block] | ||
| </div> | ||
| `); | ||
| }) |
There was a problem hiding this comment.
| }) | |
| }); |
| \`\`\``); | ||
| }); | ||
| }); | ||
| }) |
There was a problem hiding this comment.
| }) | |
| }); |
|
|
||
| it('does not catastrophically backtrack on malformed tags with spaces', () => { | ||
| const input = `<a${' '.repeat(1000)}`; | ||
| it('does not add a blank line after an opening that that already has a blank line after it', () => { |
There was a problem hiding this comment.
| it('does not add a blank line after an opening that that already has a blank line after it', () => { | |
| it('does not add a blank line after an opening tag that already has a blank line after it', () => { |
| (STANDALONE_HTML_LINE_REGEX.test(lines[i]) || HTML_LINE_WITH_CONTENT_REGEX.test(lines[i])) && | ||
| lines[i + 1].trim().length > 0 | ||
| ) { | ||
| if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ')) { |
There was a problem hiding this comment.
| if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ')) { | |
| if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ') || lines[i + 1].startsWith('\t')) { | |
can you add this as well, it looks like we are only considering when spaces start the next line but would be great to cover for \t cases as well
you can use this test case, the top one uses \t and the bottom uses spaces
<div>
<a class="glossary-letter" href="#a">A</a> |
<a class="glossary-letter" href="#b">B</a> |
</div>
---
<div>
<a class="glossary-letter" href="#a">A</a> |
<a class="glossary-letter" href="#b">B</a> |
</div>
There was a problem hiding this comment.
Really good catch thanks!
maximilianfalco
left a comment
There was a problem hiding this comment.
derefering to kevin and rafe for final approval!
| continue; | ||
| } | ||
|
|
||
| const isCurrentLineHtml = STANDALONE_HTML_LINE_REGEX.test(lines[i]) || HTML_LINE_WITH_CONTENT_REGEX.test(lines[i]); |
There was a problem hiding this comment.
small nit (not blocking): these could be DRY'ed up a bit with a small util isLineHtml that accepts the line and runs both the conditionals
| (STANDALONE_HTML_LINE_REGEX.test(lines[i]) || HTML_LINE_WITH_CONTENT_REGEX.test(lines[i])) && | ||
| lines[i + 1].trim().length > 0 | ||
| ) { | ||
| if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ') || lines[i + 1].startsWith('\t')) { |
There was a problem hiding this comment.
nit: i find a comment helpful when there are lots of conditionals to resolve in an if statement!
## Version 13.2.0 ### ✨ New & Improved * **demo:** add a markdown view in demo app when stripComments is on ([#1348](#1348)) ([a7a8726](a7a8726)) * extend regex to cover more cases ([#1338](#1338)) ([3e8efc8](3e8efc8)) ### 🛠 Fixes & Updates * **mdxish:** add missing toMarkdown extension for MDX expressions in stripComments ([#1347](#1347)) ([02ddfce](02ddfce)) * properly escape escaped chars when expression parsing fails ([#1325](#1325)) ([136f7af](136f7af)) * **mdxish:** tone down empty line addition preprocessing after html blocks ([#1344](#1344)) ([e4e7362](e4e7362)), closes [#1336](#1336) <!--SKIP CI-->
This PR was released!🚀 Changes included in v13.2.0 |


🧰 Changes
Tightens up the preprocessing logic in mdxish to add blank lines after HTML construct lines introduced in #1336 to no longer do so if the next line is an HTML construct or not indented.
The previous logic was causing a regression where the new blank line caused an HTML line after an opening HTML tag, that was 4 tabs indented, to get rendered as a code block instead of an html element. In common mark, lines with at least 4 indents are treated as code blocks (see here), but if it's right under a line with an HTML construct (opened or closed), it won't get treated as a code block. Hence the additional blank line caused the customer HTML to break.
The adjusted conditions here removes adding blank lines where we don't want it to be added, and also where it's not really needed (if the next line is indented as it already doesn't get consumed by the previous line HTML flow)
🧬 QA & Testing