Skip to content

Commit

Permalink
Correctly render tightly interleaved text/code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
RohanM committed Aug 12, 2024
1 parent 823dbff commit 9c32405
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions server/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function formatCode(html) {
})

// Expand native code blocks
html = html.replace(/<p>&#xEC03;(.*?)&#xEC02;<\/p>/ig, (match, content) => {
return formatCodeBlock(content)
html = html.replace(/<p>&#xEC03;(.*?)&#xEC02;(.*?)<\/p>/ig, (match, content, tailingPara) => {
return `${formatCodeBlock(content)}<p>${tailingPara}</p>`
})

// Replace double backticks with <code>, for supporting backticks in inline code blocks
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/supportedFormats.nativeCode.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css"> @import url(https://themes.googleusercontent.com/fonts/css?kit=XGMkxXUZTA64h2imyzu79g);</style></head><body class="doc-content" style="background-color:#ffffff;padding:72pt 72pt 72pt 72pt;max-width:468pt"><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">Intro sentence.</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal"></span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span>&#60419;</span><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal">// This is a code block</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal"></span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal">// Here&#39;s another line</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">&#60418;</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">Outro sentence.</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal"></span></p></body></html>
<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css"> @import url(https://themes.googleusercontent.com/fonts/css?kit=XGMkxXUZTA64h2imyzu79g);</style></head><body class="doc-content" style="background-color:#ffffff;padding:72pt 72pt 72pt 72pt;max-width:468pt"><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">Intro sentence.</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal"></span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span>&#60419;</span><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal">// This is a code block</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal"></span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal">// Here&#39;s another line</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">&#60418;</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">Middle sentence.</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal"></span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span>&#60419;</span><span style="color:#b80672;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:9pt;font-family:&quot;Roboto Mono&quot;;font-style:normal"># A second code block</span></p><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:&quot;Arial&quot;;line-height:1.15;orphans:2;widows:2;text-align:left"><span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:&quot;Arial&quot;;font-style:normal">&#60418;Outro sentence.</span></p></body></html>
3 changes: 2 additions & 1 deletion test/unit/htmlProcessing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ describe('HTML processing', () => {
})

describe('native code block handling', () => {
it('formats the code block', () => {
it('formats the code blocks', () => {
const codeBlock = testGlobal.native.output('pre > code')
assert.exists(codeBlock.html())
assert.equal(codeBlock.length, 2)
})

it('removes code block marker unicode characters', () => {
Expand Down

0 comments on commit 9c32405

Please sign in to comment.