0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +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:
David Bolack
2024-08-20 11:46:43 -05:00
parent 3a81521e6f
commit 3985afade9
2 changed files with 29 additions and 6 deletions

View File

@@ -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 `<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)));
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<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;
rawBrewText = opts.hooks.preprocess(rawBrewText);