diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 804d6b2cf..2cc5e3ad0 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -357,7 +357,7 @@ const superSubScripts = { }; const forcedParagraphBreaks = { - name : 'colonParagraphs', + name : 'hardBreaks', level : 'inline', start(src) { return src.match(/^:+$/m)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { @@ -365,7 +365,7 @@ const forcedParagraphBreaks = { const match = regex.exec(src); if(match?.length) { return { - type : 'colonParagraphs', // Should match "name" above + type : 'hardBreaks', // Should match "name" above raw : match[0], // Text to consume from the source length : match[1].length, text : '' @@ -373,7 +373,7 @@ const forcedParagraphBreaks = { } }, renderer(token) { - return `
`.repeat(token.length); + return `
`.repeat(token.length).concat('\n'); } }; @@ -395,8 +395,7 @@ const definitionListsSingleLine = { .map((emoji)=>firstLine = firstLine.replace(emoji.raw, 'x'.repeat(emoji.raw.length))); const newMatch = /^([^\n]*?)::([^\n]*)(?:\n|$)/ym.exec(firstLine); - if((newMatch) && newMatch[1].length > 0) { - // Test the lengths to handle two : paragraph breaks exception + if(newMatch) { definitions.push({ dt : this.lexer.inlineTokens(originalLine.slice(0, newMatch[1].length).trim()), dd : this.lexer.inlineTokens(originalLine.slice(newMatch[1].length + 2).trim()) @@ -857,7 +856,8 @@ module.exports = { varsQueue = []; //Could move into MarkedVariables() globalPageNumber = pageNumber; - rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n
\n`); + rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n
\n`) + .replace(/^(:+)$/gm, (match)=>`${`:\n\n`.repeat(match.length)}\n`); const opts = Marked.defaults; rawBrewText = opts.hooks.preprocess(rawBrewText); diff --git a/tests/markdown/hardbreaks.test.js b/tests/markdown/hardbreaks.test.js new file mode 100644 index 000000000..b27c6859c --- /dev/null +++ b/tests/markdown/hardbreaks.test.js @@ -0,0 +1,23 @@ +/* eslint-disable max-lines */ + +const Markdown = require('naturalcrit/markdown.js'); + +describe('Hard Breaks', ()=>{ + test('Single Break', function() { + const source = ':\n\n'; + const rendered = Markdown.render(source).trim(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
'); + }); + + test('Double Break', function() { + const source = '::\n\n'; + const rendered = Markdown.render(source).trim(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
\n
'); + }); + + test('Triple Break', function() { + const source = ':::\n\n'; + const rendered = Markdown.render(source).trim(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
\n
\n
'); + }); +});