From 9c3240567283c463f15f6dd1ccf6139d5b494a40 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 13 Aug 2024 09:58:14 +1000 Subject: [PATCH] Correctly render tightly interleaved text/code blocks --- server/formatter.js | 4 ++-- test/fixtures/supportedFormats.nativeCode.html | 2 +- test/unit/htmlProcessing.test.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/formatter.js b/server/formatter.js index 6601da9e..175d2a6d 100644 --- a/server/formatter.js +++ b/server/formatter.js @@ -110,8 +110,8 @@ function formatCode(html) { }) // Expand native code blocks - html = html.replace(/

(.*?)<\/p>/ig, (match, content) => { - return formatCodeBlock(content) + html = html.replace(/

(.*?)(.*?)<\/p>/ig, (match, content, tailingPara) => { + return `${formatCodeBlock(content)}

${tailingPara}

` }) // Replace double backticks with , for supporting backticks in inline code blocks diff --git a/test/fixtures/supportedFormats.nativeCode.html b/test/fixtures/supportedFormats.nativeCode.html index 4691086e..6933e7d6 100644 --- a/test/fixtures/supportedFormats.nativeCode.html +++ b/test/fixtures/supportedFormats.nativeCode.html @@ -1 +1 @@ -

Intro sentence.

// This is a code block

// Here's another line

Outro sentence.

+

Intro sentence.

// This is a code block

// Here's another line

Middle sentence.

# A second code block

Outro sentence.

\ No newline at end of file diff --git a/test/unit/htmlProcessing.test.js b/test/unit/htmlProcessing.test.js index 587f7f93..f0688f98 100644 --- a/test/unit/htmlProcessing.test.js +++ b/test/unit/htmlProcessing.test.js @@ -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', () => {