mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 00:42:47 +00:00
Fix spaces not working in mustache divs / spans
This commit is contained in:
@@ -37,24 +37,28 @@ const mustacheSpans = {
|
|||||||
//Find closing delimiter
|
//Find closing delimiter
|
||||||
let blockCount = 0;
|
let blockCount = 0;
|
||||||
let tags = '';
|
let tags = '';
|
||||||
let endIndex = 0;
|
let endTags = 0;
|
||||||
|
let endToken = 0;
|
||||||
let delim;
|
let delim;
|
||||||
while (delim = inlineRegex.exec(match[0])) {
|
while (delim = inlineRegex.exec(match[0])) {
|
||||||
|
if(!tags) {
|
||||||
|
tags = ` ${processStyleTags(delim[0].substring(2))}`;
|
||||||
|
endTags = delim[0].length;
|
||||||
|
}
|
||||||
if(delim[0].startsWith('{{')) {
|
if(delim[0].startsWith('{{')) {
|
||||||
tags = tags || ` ${processStyleTags(delim[0].substring(2))}`;
|
|
||||||
blockCount++;
|
blockCount++;
|
||||||
} else if(delim[0] == '}}' && blockCount !== 0) {
|
} else if(delim[0] == '}}' && blockCount !== 0) {
|
||||||
blockCount--;
|
blockCount--;
|
||||||
if(blockCount == 0) {
|
if(blockCount == 0) {
|
||||||
endIndex = inlineRegex.lastIndex;
|
endToken = inlineRegex.lastIndex;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(endIndex) {
|
if(endToken) {
|
||||||
const raw = src.slice(0, endIndex);
|
const raw = src.slice(0, endToken);
|
||||||
const text = raw.slice((raw.indexOf(' ')+1) || -2, -2);
|
const text = raw.slice(endTags || -2, -2);
|
||||||
|
|
||||||
return { // Token to generate
|
return { // Token to generate
|
||||||
type : 'mustacheSpans', // Should match "name" above
|
type : 'mustacheSpans', // Should match "name" above
|
||||||
@@ -76,31 +80,35 @@ const mustacheDivs = {
|
|||||||
level : 'block',
|
level : 'block',
|
||||||
start(src) { return src.match(/\n *{{[^{]/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
start(src) { return src.match(/\n *{{[^{]/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
||||||
tokenizer(src, tokens) {
|
tokenizer(src, tokens) {
|
||||||
const completeBlock = /^ *{{[^\s}]* *\n.*\n *}}/s; // Regex for the complete token
|
const completeBlock = /^ *{{[^\n}]* *\n.*\n *}}/s; // Regex for the complete token
|
||||||
const blockRegex = /^ *{{(?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])* *$|^ *}}$/gm;
|
const blockRegex = /^ *{{(?::(?:"[\w,\-()#%. ]*"|[\w\,\-()#%.]*)|[^"'{}\s])* *$|^ *}}$/gm;
|
||||||
const match = completeBlock.exec(src);
|
const match = completeBlock.exec(src);
|
||||||
if(match) {
|
if(match) {
|
||||||
//Find closing delimiter
|
//Find closing delimiter
|
||||||
let blockCount = 0;
|
let blockCount = 0;
|
||||||
let tags = '';
|
let tags = '';
|
||||||
let endIndex = 0;
|
let endTags = 0;
|
||||||
|
let endToken = 0;
|
||||||
let delim;
|
let delim;
|
||||||
while (delim = blockRegex.exec(match[0])?.[0].trim()) {
|
while (delim = blockRegex.exec(match[0])?.[0].trim()) {
|
||||||
|
if(!tags) {
|
||||||
|
tags = ` ${processStyleTags(delim.substring(2))}`;
|
||||||
|
endTags = delim.length;
|
||||||
|
}
|
||||||
if(delim.startsWith('{{')) {
|
if(delim.startsWith('{{')) {
|
||||||
tags = tags || ` ${processStyleTags(delim.substring(2))}`;
|
|
||||||
blockCount++;
|
blockCount++;
|
||||||
} else if(delim == '}}' && blockCount !== 0) {
|
} else if(delim == '}}' && blockCount !== 0) {
|
||||||
blockCount--;
|
blockCount--;
|
||||||
if(blockCount == 0) {
|
if(blockCount == 0) {
|
||||||
endIndex = blockRegex.lastIndex;
|
endToken = blockRegex.lastIndex;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(endIndex) {
|
if(endToken) {
|
||||||
const raw = src.slice(0, endIndex);
|
const raw = src.slice(0, endToken);
|
||||||
const text = raw.slice((raw.indexOf('\n')+1) || -2, -2);
|
const text = raw.slice(endTags || -2, -2);
|
||||||
return { // Token to generate
|
return { // Token to generate
|
||||||
type : 'mustacheDivs', // Should match "name" above
|
type : 'mustacheDivs', // Should match "name" above
|
||||||
raw : raw, // Text to consume from the source
|
raw : raw, // Text to consume from the source
|
||||||
|
|||||||
Reference in New Issue
Block a user