mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 20:42:44 +00:00
Update code to use helper function to ensure unifrom normalization of Variable labels.
This commit is contained in:
@@ -59,6 +59,12 @@ mathParser.functions.signed = function (a) {
|
|||||||
return `${a}`;
|
return `${a}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Make sure we normalize variable names consistantly.
|
||||||
|
const normalizeVarNames = (label)=>{
|
||||||
|
return label.trim()
|
||||||
|
.replace(/\s+/g, ' ');
|
||||||
|
};
|
||||||
|
|
||||||
//Processes the markdown within an HTML block if it's just a class-wrapper
|
//Processes the markdown within an HTML block if it's just a class-wrapper
|
||||||
renderer.html = function (html) {
|
renderer.html = function (html) {
|
||||||
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
|
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
|
||||||
@@ -533,7 +539,7 @@ const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
|||||||
const match = regex.exec(input);
|
const match = regex.exec(input);
|
||||||
|
|
||||||
const prefix = match[1];
|
const prefix = match[1];
|
||||||
const label = match[2];
|
const label = normalizeVarNames(match[2]); // Ensure the label name is normalized as it should be in the var stack.
|
||||||
|
|
||||||
//v=====--------------------< HANDLE MATH >-------------------=====v//
|
//v=====--------------------< HANDLE MATH >-------------------=====v//
|
||||||
const mathRegex = /[a-z]+\(|[+\-*/^(),]/g;
|
const mathRegex = /[a-z]+\(|[+\-*/^(),]/g;
|
||||||
@@ -688,7 +694,7 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[3]) { // Block Definition
|
if(match[3]) { // Block Definition
|
||||||
const label = match[4] ? match[4].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[4] ? normalizeVarNames(match[4]) : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
const content = match[5] ? match[5].trim().replace(/[ \t]+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const content = match[5] ? match[5].trim().replace(/[ \t]+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
@@ -698,7 +704,7 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[6]) { // Block Call
|
if(match[6]) { // Block Call
|
||||||
const label = match[7] ? match[7].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[7] ? normalizeVarNames(match[7]) : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallBlock',
|
{ type : 'varCallBlock',
|
||||||
@@ -707,7 +713,7 @@ function MarkedVariables() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[8]) { // Inline Definition
|
if(match[8]) { // Inline Definition
|
||||||
const label = match[10] ? match[10].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[10] ? normalizeVarNames(match[10]) : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
let content = match[11] || null;
|
let content = match[11] || null;
|
||||||
|
|
||||||
// In case of nested (), find the correct matching end )
|
// In case of nested (), find the correct matching end )
|
||||||
@@ -735,11 +741,11 @@ function MarkedVariables() {
|
|||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallInline',
|
{ type : 'varCallInline',
|
||||||
varName : label,
|
varName : label,
|
||||||
content : match[9].replace(/\s+/g, ' ').replace(/\[\s+/, '[').replace(/\s+\]/, ']')
|
content : match[9]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[12]) { // Inline Call
|
if(match[12]) { // Inline Call
|
||||||
const label = match[13] ? match[13].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
const label = match[13] ? normalizeVarNames(match[13]) : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
|
||||||
varsQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallInline',
|
{ type : 'varCallInline',
|
||||||
|
|||||||
Reference in New Issue
Block a user