mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 02:42:43 +00:00
Rename variables
This commit is contained in:
@@ -399,11 +399,9 @@ const lookupVar = function(label, index, hoist=false) {
|
|||||||
const processVariableQueue = function() {
|
const processVariableQueue = function() {
|
||||||
let resolvedOne = true;
|
let resolvedOne = true;
|
||||||
let finalLoop = false;
|
let finalLoop = false;
|
||||||
let loopcount = 0;
|
|
||||||
while (resolvedOne || finalLoop) { // Loop through queue until no more variable calls can be resolved
|
while (resolvedOne || finalLoop) { // Loop through queue until no more variable calls can be resolved
|
||||||
resolvedOne = false;
|
resolvedOne = false;
|
||||||
loopcount += 1;
|
for (const item of varsQueue) {
|
||||||
for (const item of linksQueue) {
|
|
||||||
if(item.type == 'text')
|
if(item.type == 'text')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -448,14 +446,14 @@ const processVariableQueue = function() {
|
|||||||
item.type = 'text';
|
item.type = 'text';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
linksQueue = linksQueue.filter(item => item.type !== 'resolved'); // Remove any fully-resolved variable definitions
|
varsQueue = varsQueue.filter(item => item.type !== 'resolved'); // Remove any fully-resolved variable definitions
|
||||||
|
|
||||||
if(finalLoop)
|
if(finalLoop)
|
||||||
break;
|
break;
|
||||||
if(!resolvedOne)
|
if(!resolvedOne)
|
||||||
finalLoop = true;
|
finalLoop = true;
|
||||||
}
|
}
|
||||||
linksQueue = linksQueue.filter(item => item.type !== 'varDefBlock');
|
varsQueue = varsQueue.filter(item => item.type !== 'varDefBlock');
|
||||||
};
|
};
|
||||||
|
|
||||||
function MarkedVariables() {
|
function MarkedVariables() {
|
||||||
@@ -476,14 +474,14 @@ function MarkedVariables() {
|
|||||||
while ((match = combinedRegex.exec(src)) !== null) {
|
while ((match = combinedRegex.exec(src)) !== null) {
|
||||||
// Form any matches into tokens and store
|
// Form any matches into tokens and store
|
||||||
if (match.index > lastIndex) { // Any non-variable stuff
|
if (match.index > lastIndex) { // Any non-variable stuff
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'text',
|
{ type : 'text',
|
||||||
varName : null,
|
varName : null,
|
||||||
content : src.slice(lastIndex, match.index)
|
content : src.slice(lastIndex, match.index)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(match[1]) {
|
if(match[1]) {
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'text',
|
{ type : 'text',
|
||||||
varName : null,
|
varName : null,
|
||||||
content : match[0]
|
content : match[0]
|
||||||
@@ -493,7 +491,7 @@ function MarkedVariables() {
|
|||||||
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] ? match[4].trim().replace(/\s+/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
|
const content = match[5] ? match[5].trim().replace(/[ \t]+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varDefBlock',
|
{ type : 'varDefBlock',
|
||||||
varName : label,
|
varName : label,
|
||||||
content : content
|
content : content
|
||||||
@@ -502,7 +500,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] ? match[7].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallBlock',
|
{ type : 'varCallBlock',
|
||||||
varName : label,
|
varName : label,
|
||||||
content : match[0]
|
content : match[0]
|
||||||
@@ -532,12 +530,12 @@ function MarkedVariables() {
|
|||||||
content = content.slice(0,i).trim().replace(/\s+/g, ' ');
|
content = content.slice(0,i).trim().replace(/\s+/g, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varDefBlock',
|
{ type : 'varDefBlock',
|
||||||
varName : label,
|
varName : label,
|
||||||
content : content
|
content : content
|
||||||
});
|
});
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallInline',
|
{ type : 'varCallInline',
|
||||||
varName : label,
|
varName : label,
|
||||||
content : match[9]
|
content : match[9]
|
||||||
@@ -546,7 +544,7 @@ function MarkedVariables() {
|
|||||||
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] ? match[13].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
|
||||||
|
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'varCallInline',
|
{ type : 'varCallInline',
|
||||||
varName : label,
|
varName : label,
|
||||||
content : match[0]
|
content : match[0]
|
||||||
@@ -556,7 +554,7 @@ function MarkedVariables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lastIndex < src.length) {
|
if (lastIndex < src.length) {
|
||||||
linksQueue.push(
|
varsQueue.push(
|
||||||
{ type : 'text',
|
{ type : 'text',
|
||||||
varName : null,
|
varName : null,
|
||||||
content : src.slice(lastIndex)
|
content : src.slice(lastIndex)
|
||||||
@@ -565,8 +563,8 @@ function MarkedVariables() {
|
|||||||
|
|
||||||
processVariableQueue();
|
processVariableQueue();
|
||||||
|
|
||||||
const output = linksQueue.map(item => item.content).join('');
|
const output = varsQueue.map(item => item.content).join('');
|
||||||
linksQueue = []; // Must clear linksQueue because custom HTML renderer uses Marked.parse which will preprocess again without clearing the array
|
varsQueue = []; // Must clear varsQueue because custom HTML renderer uses Marked.parse which will preprocess again without clearing the array
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -657,7 +655,7 @@ const processStyleTags = (string)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const globalVarsList = {};
|
const globalVarsList = {};
|
||||||
let linksQueue = [];
|
let varsQueue = [];
|
||||||
let globalPageNumber = 0;
|
let globalPageNumber = 0;
|
||||||
let parseVars = true;
|
let parseVars = true;
|
||||||
|
|
||||||
@@ -665,7 +663,7 @@ module.exports = {
|
|||||||
marked : Marked,
|
marked : Marked,
|
||||||
render : (rawBrewText, pageNumber=1)=>{
|
render : (rawBrewText, pageNumber=1)=>{
|
||||||
globalVarsList[pageNumber] = {}; //Reset global links for current page, to ensure values are parsed in order
|
globalVarsList[pageNumber] = {}; //Reset global links for current page, to ensure values are parsed in order
|
||||||
linksQueue = []; //Could move into MarkedVariables()
|
varsQueue = []; //Could move into MarkedVariables()
|
||||||
globalPageNumber = pageNumber;
|
globalPageNumber = pageNumber;
|
||||||
|
|
||||||
parseVars = true;
|
parseVars = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user