mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 03:52:40 +00:00
Remove need for Definition exceptios
Retool original `:` break to insert `\n\n`s between each `:` so that the definition lists never have a chance for a mismatch. Rename token to "hardbreak" Add tests for hardBreaks for `:`, `::`, and `:::` which should verify it works and does not collide with definitionlists.
This commit is contained in:
@@ -357,7 +357,7 @@ const superSubScripts = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const forcedParagraphBreaks = {
|
const forcedParagraphBreaks = {
|
||||||
name : 'colonParagraphs',
|
name : 'hardBreaks',
|
||||||
level : 'inline',
|
level : 'inline',
|
||||||
start(src) { return src.match(/^:+$/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
start(src) { return src.match(/^:+$/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||||
tokenizer(src, tokens) {
|
tokenizer(src, tokens) {
|
||||||
@@ -365,7 +365,7 @@ const forcedParagraphBreaks = {
|
|||||||
const match = regex.exec(src);
|
const match = regex.exec(src);
|
||||||
if(match?.length) {
|
if(match?.length) {
|
||||||
return {
|
return {
|
||||||
type : 'colonParagraphs', // Should match "name" above
|
type : 'hardBreaks', // Should match "name" above
|
||||||
raw : match[0], // Text to consume from the source
|
raw : match[0], // Text to consume from the source
|
||||||
length : match[1].length,
|
length : match[1].length,
|
||||||
text : ''
|
text : ''
|
||||||
@@ -373,7 +373,7 @@ const forcedParagraphBreaks = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
renderer(token) {
|
renderer(token) {
|
||||||
return `<div class='blank'></div>`.repeat(token.length);
|
return `<div class='blank'></div>`.repeat(token.length).concat('\n');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -395,8 +395,7 @@ const definitionListsSingleLine = {
|
|||||||
.map((emoji)=>firstLine = firstLine.replace(emoji.raw, 'x'.repeat(emoji.raw.length)));
|
.map((emoji)=>firstLine = firstLine.replace(emoji.raw, 'x'.repeat(emoji.raw.length)));
|
||||||
|
|
||||||
const newMatch = /^([^\n]*?)::([^\n]*)(?:\n|$)/ym.exec(firstLine);
|
const newMatch = /^([^\n]*?)::([^\n]*)(?:\n|$)/ym.exec(firstLine);
|
||||||
if((newMatch) && newMatch[1].length > 0) {
|
if(newMatch) {
|
||||||
// Test the lengths to handle two : paragraph breaks exception
|
|
||||||
definitions.push({
|
definitions.push({
|
||||||
dt : this.lexer.inlineTokens(originalLine.slice(0, newMatch[1].length).trim()),
|
dt : this.lexer.inlineTokens(originalLine.slice(0, newMatch[1].length).trim()),
|
||||||
dd : this.lexer.inlineTokens(originalLine.slice(newMatch[1].length + 2).trim())
|
dd : this.lexer.inlineTokens(originalLine.slice(newMatch[1].length + 2).trim())
|
||||||
@@ -857,7 +856,8 @@ module.exports = {
|
|||||||
varsQueue = []; //Could move into MarkedVariables()
|
varsQueue = []; //Could move into MarkedVariables()
|
||||||
globalPageNumber = pageNumber;
|
globalPageNumber = pageNumber;
|
||||||
|
|
||||||
rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n<div class='columnSplit'></div>\n`);
|
rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n<div class='columnSplit'></div>\n`)
|
||||||
|
.replace(/^(:+)$/gm, (match)=>`${`:\n\n`.repeat(match.length)}\n`);
|
||||||
const opts = Marked.defaults;
|
const opts = Marked.defaults;
|
||||||
|
|
||||||
rawBrewText = opts.hooks.preprocess(rawBrewText);
|
rawBrewText = opts.hooks.preprocess(rawBrewText);
|
||||||
|
|||||||
23
tests/markdown/hardbreaks.test.js
Normal file
23
tests/markdown/hardbreaks.test.js
Normal file
@@ -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('<div class=\'blank\'></div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Double Break', function() {
|
||||||
|
const source = '::\n\n';
|
||||||
|
const rendered = Markdown.render(source).trim();
|
||||||
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<div class=\'blank\'></div>\n<div class=\'blank\'></div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Triple Break', function() {
|
||||||
|
const source = ':::\n\n';
|
||||||
|
const rendered = Markdown.render(source).trim();
|
||||||
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<div class=\'blank\'></div>\n<div class=\'blank\'></div>\n<div class=\'blank\'></div>');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user