mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 22:22:41 +00:00
Add one more test that was failing
This commit is contained in:
@@ -327,7 +327,7 @@ const definitionLists = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//v=====--------------------< Variable Handling >-------------------=====v// 245 lines
|
//v=====--------------------< Variable Handling >-------------------=====v// 236 lines
|
||||||
const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
||||||
const regex = /([!$]?)\[((?!\s*\])(?:\\.|[^\[\]\\])+)\]/g;
|
const regex = /([!$]?)\[((?!\s*\])(?:\\.|[^\[\]\\])+)\]/g;
|
||||||
const match = regex.exec(input);
|
const match = regex.exec(input);
|
||||||
@@ -369,18 +369,14 @@ const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
|||||||
let href = linkMatch ? linkMatch[1] : null; //TODO: TRIM OFF < > IF PRESENT
|
let href = linkMatch ? linkMatch[1] : null; //TODO: TRIM OFF < > IF PRESENT
|
||||||
let title = linkMatch ? linkMatch[2]?.slice(1, -1) : null;
|
let title = linkMatch ? linkMatch[2]?.slice(1, -1) : null;
|
||||||
|
|
||||||
let value;
|
|
||||||
|
|
||||||
if(!prefix[0] && href) // Link
|
if(!prefix[0] && href) // Link
|
||||||
value = `[${label}](${href}${title ? ` "${title}"` : ''})`;
|
return `[${label}](${href}${title ? ` "${title}"` : ''})`;
|
||||||
|
|
||||||
if(prefix[0] == '!' && href) // Image
|
if(prefix[0] == '!' && href) // Image
|
||||||
value = ``;
|
return ``;
|
||||||
|
|
||||||
if(prefix[0] == '$') // Variable
|
if(prefix[0] == '$') // Variable
|
||||||
value = foundVar.content;
|
return foundVar.content;
|
||||||
|
|
||||||
return value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const lookupVar = function(label, index, hoist=false) {
|
const lookupVar = function(label, index, hoist=false) {
|
||||||
@@ -413,11 +409,10 @@ const processVariableQueue = function() {
|
|||||||
while (match = regex.exec(item.content)) { // regex to find variable calls
|
while (match = regex.exec(item.content)) { // regex to find variable calls
|
||||||
const value = replaceVar(match[0], true);
|
const value = replaceVar(match[0], true);
|
||||||
|
|
||||||
if(value == undefined) {
|
if(value == undefined)
|
||||||
resolved = false;
|
resolved = false;
|
||||||
} else {
|
else
|
||||||
tempContent = tempContent.replaceAll(match[0], value);
|
tempContent = tempContent.replaceAll(match[0], value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resolved == true || item.content != tempContent) {
|
if(resolved == true || item.content != tempContent) {
|
||||||
@@ -430,9 +425,8 @@ const processVariableQueue = function() {
|
|||||||
resolved : resolved
|
resolved : resolved
|
||||||
};
|
};
|
||||||
|
|
||||||
if(resolved){
|
if(resolved)
|
||||||
item.type = 'resolved';
|
item.type = 'resolved';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item.type == 'varCallBlock' || item.type == 'varCallInline') {
|
if(item.type == 'varCallBlock' || item.type == 'varCallInline') {
|
||||||
@@ -472,7 +466,7 @@ function MarkedVariables() {
|
|||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let match;
|
let match;
|
||||||
while ((match = combinedRegex.exec(src)) !== null) {
|
while ((match = combinedRegex.exec(src)) !== null) {
|
||||||
// Form any matches into tokens and store
|
// Format any matches into tokens and store
|
||||||
if (match.index > lastIndex) { // Any non-variable stuff
|
if (match.index > lastIndex) { // Any non-variable stuff
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'text',
|
{ type : 'text',
|
||||||
@@ -520,9 +514,8 @@ function MarkedVariables() {
|
|||||||
level++;
|
level++;
|
||||||
} else if (content[i] === ')') {
|
} else if (content[i] === ')') {
|
||||||
level--;
|
level--;
|
||||||
if (level < 0) {
|
if (level < 0)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
|
|||||||
@@ -138,6 +138,23 @@ describe('Inline-level variables', ()=>{
|
|||||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p>My name is Bill Jones</p> <p>Bob</p>`.trimReturns());
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p>My name is Bill Jones</p> <p>Bob</p>`.trimReturns());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Only captures nested parens if balanced', function() {
|
||||||
|
const source = dedent`
|
||||||
|
$[var1](A variable (with nested parens) inside)
|
||||||
|
|
||||||
|
$[var1]
|
||||||
|
|
||||||
|
$[var2](A variable ) with unbalanced parens)
|
||||||
|
|
||||||
|
$[var2]`;
|
||||||
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(dedent`
|
||||||
|
<p>A variable (with nested parens) inside</p>
|
||||||
|
<p>A variable (with nested parens) inside</p>
|
||||||
|
<p>A variable with unbalanced parens)</p>
|
||||||
|
<p>A variable</p>
|
||||||
|
`.trimReturns());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Math', ()=>{
|
describe('Math', ()=>{
|
||||||
|
|||||||
Reference in New Issue
Block a user