diff --git a/server/formatter.js b/server/formatter.js index 175d2a6d..3f046c5a 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, tailingPara) => { - return `${formatCodeBlock(content)}

${tailingPara}

` + html = html.replace(/

(.*?)<\/p>(<[^>]*>)/ig, (match, content, followingTag) => { + return `${formatCodeBlock(content)}${followingTag}` }) // 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 6933e7d6..7f4e8d80 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

Middle sentence.

# A second code block

Outro sentence.

\ No newline at end of file +

Intro sentence.

// This is a code block

// Here's another line

Middle sentence.

# A second code block

Outro sentence.

/* Another code block */

Heading following a code block

diff --git a/test/unit/htmlProcessing.test.js b/test/unit/htmlProcessing.test.js index f0688f98..eb42c730 100644 --- a/test/unit/htmlProcessing.test.js +++ b/test/unit/htmlProcessing.test.js @@ -147,7 +147,12 @@ describe('HTML processing', () => { it('formats the code blocks', () => { const codeBlock = testGlobal.native.output('pre > code') assert.exists(codeBlock.html()) - assert.equal(codeBlock.length, 2) + assert.equal(codeBlock.length, 3) + }) + + it('leaves the trailing heading intact', () => { + const heading = testGlobal.native.output('h2') + assert.equal(heading.html(), 'Heading following a code block') }) it('removes code block marker unicode characters', () => {