mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-16 12:32:39 +00:00
lint
This commit is contained in:
@@ -152,7 +152,7 @@ const BrewRenderer = (props)=>{
|
|||||||
renderedPages.length = 0;
|
renderedPages.length = 0;
|
||||||
|
|
||||||
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
||||||
renderedPages[props.currentEditorPage] = renderPage(rawPages[props.currentEditorPage], props.currentEditorPage)
|
renderedPages[props.currentEditorPage] = renderPage(rawPages[props.currentEditorPage], props.currentEditorPage);
|
||||||
|
|
||||||
_.forEach(rawPages, (page, index)=>{
|
_.forEach(rawPages, (page, index)=>{
|
||||||
if((isInView(index) || !renderedPages[index]) && typeof window !== 'undefined'){
|
if((isInView(index) || !renderedPages[index]) && typeof window !== 'undefined'){
|
||||||
|
|||||||
@@ -336,9 +336,9 @@ const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
|||||||
const label = match[2];
|
const label = match[2];
|
||||||
|
|
||||||
//v=====--------------------< HANDLE MATH >-------------------=====v//
|
//v=====--------------------< HANDLE MATH >-------------------=====v//
|
||||||
let mathRegex = /[a-z]+\(|[+\-*/^()]/g;
|
const mathRegex = /[a-z]+\(|[+\-*/^()]/g;
|
||||||
let matches = label.split(mathRegex)
|
const matches = label.split(mathRegex);
|
||||||
let mathVars = matches.filter(match => isNaN(match))?.map((s)=>s.trim()); // Capture any variable names
|
const mathVars = matches.filter((match)=>isNaN(match))?.map((s)=>s.trim()); // Capture any variable names
|
||||||
|
|
||||||
let replacedLabel = label;
|
let replacedLabel = label;
|
||||||
|
|
||||||
@@ -366,8 +366,8 @@ const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
|||||||
const linkRegex = /^([^<\s][^\s]*|<.*?>)(?: ("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\((?:\\\(|\\\)|[^()])*\)))?$/m;
|
const linkRegex = /^([^<\s][^\s]*|<.*?>)(?: ("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\((?:\\\(|\\\)|[^()])*\)))?$/m;
|
||||||
const linkMatch = linkRegex.exec(foundVar.content);
|
const linkMatch = linkRegex.exec(foundVar.content);
|
||||||
|
|
||||||
let href = linkMatch ? linkMatch[1] : null; //TODO: TRIM OFF < > IF PRESENT
|
const href = linkMatch ? linkMatch[1] : null; //TODO: TRIM OFF < > IF PRESENT
|
||||||
let title = linkMatch ? linkMatch[2]?.slice(1, -1) : null;
|
const title = linkMatch ? linkMatch[2]?.slice(1, -1) : null;
|
||||||
|
|
||||||
if(!prefix[0] && href) // Link
|
if(!prefix[0] && href) // Link
|
||||||
return `[${label}](${href}${title ? ` "${title}"` : ''})`;
|
return `[${label}](${href}${title ? ` "${title}"` : ''})`;
|
||||||
@@ -446,14 +446,14 @@ const processVariableQueue = function() {
|
|||||||
item.type = 'text';
|
item.type = 'text';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
varsQueue = varsQueue.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;
|
||||||
}
|
}
|
||||||
varsQueue = varsQueue.filter(item => item.type !== 'varDefBlock');
|
varsQueue = varsQueue.filter((item)=>item.type !== 'varDefBlock');
|
||||||
};
|
};
|
||||||
|
|
||||||
function MarkedVariables() {
|
function MarkedVariables() {
|
||||||
@@ -467,7 +467,7 @@ function MarkedVariables() {
|
|||||||
const inlineCallRegex = /[!$]?\[((?!\s*\])(?:\\.|[^\[\]\\])+)\](?!\()/; //Matches 12, [13]
|
const inlineCallRegex = /[!$]?\[((?!\s*\])(?:\\.|[^\[\]\\])+)\](?!\()/; //Matches 12, [13]
|
||||||
|
|
||||||
// Combine regexes and wrap in parens like so: (regex1)|(regex2)|(regex3)|(regex4)
|
// Combine regexes and wrap in parens like so: (regex1)|(regex2)|(regex3)|(regex4)
|
||||||
let combinedRegex = new RegExp([codeBlockSkip, blockDefRegex, blockCallRegex, inlineDefRegex, inlineCallRegex].map(s => `(${s.source})`).join('|'), 'gm');
|
const combinedRegex = new RegExp([codeBlockSkip, blockDefRegex, blockCallRegex, inlineDefRegex, inlineCallRegex].map((s)=>`(${s.source})`).join('|'), 'gm');
|
||||||
|
|
||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let match;
|
let match;
|
||||||
@@ -562,7 +562,7 @@ function MarkedVariables() {
|
|||||||
|
|
||||||
processVariableQueue();
|
processVariableQueue();
|
||||||
|
|
||||||
const output = varsQueue.map(item => item.content).join('');
|
const output = varsQueue.map((item)=>item.content).join('');
|
||||||
varsQueue = []; // Must clear varsQueue 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;
|
||||||
}
|
}
|
||||||
@@ -571,7 +571,7 @@ function MarkedVariables() {
|
|||||||
};
|
};
|
||||||
//^=====--------------------< Variable Handling >-------------------=====^//
|
//^=====--------------------< Variable Handling >-------------------=====^//
|
||||||
|
|
||||||
Marked.use(MarkedVariables())
|
Marked.use(MarkedVariables());
|
||||||
Marked.use({ extensions: [mustacheSpans, mustacheDivs, mustacheInjectInline, definitionLists, superSubScripts] });
|
Marked.use({ extensions: [mustacheSpans, mustacheDivs, mustacheInjectInline, definitionLists, superSubScripts] });
|
||||||
Marked.use(mustacheInjectBlock);
|
Marked.use(mustacheInjectBlock);
|
||||||
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ describe('Block-level variables', ()=>{
|
|||||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<p>two</p><p>one</p><p>two</p>'.trimReturns());
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<p>two</p><p>one</p><p>two</p>'.trimReturns());
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Ignores undefined variables that can't be hoisted", function() {
|
it('Ignores undefined variables that can\'t be hoisted', function() {
|
||||||
const source = dedent`
|
const source = dedent`
|
||||||
$[var](My name is $[first] $[last])
|
$[var](My name is $[first] $[last])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user