mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-23 05:51:29 +00:00
lint
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
var _ = require('lodash');
|
||||
var Markdown = require('marked');
|
||||
var renderer = new Markdown.Renderer();
|
||||
const _ = require('lodash');
|
||||
const Markdown = require('marked');
|
||||
const renderer = new Markdown.Renderer();
|
||||
|
||||
//Processes the markdown within an HTML block if it's just a class-wrapper
|
||||
renderer.html = function (html) {
|
||||
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
|
||||
var openTag = html.substring(0, html.indexOf('>')+1);
|
||||
const openTag = html.substring(0, html.indexOf('>')+1);
|
||||
html = html.substring(html.indexOf('>')+1);
|
||||
html = html.substring(0, html.lastIndexOf('</div>'));
|
||||
return `${openTag} ${Markdown(html)} </div>`;
|
||||
@@ -15,23 +15,23 @@ renderer.html = function (html) {
|
||||
|
||||
|
||||
const tagTypes = ['div', 'span', 'a'];
|
||||
const tagRegex = new RegExp('(' +
|
||||
const tagRegex = new RegExp(`(${
|
||||
_.map(tagTypes, (type)=>{
|
||||
return `\\<${type}|\\</${type}>`;
|
||||
}).join('|') + ')', 'g');
|
||||
}).join('|')})`, 'g');
|
||||
|
||||
|
||||
module.exports = {
|
||||
marked : Markdown,
|
||||
render : (rawBrewText)=>{
|
||||
return Markdown(rawBrewText, {renderer : renderer})
|
||||
return Markdown(rawBrewText, { renderer: renderer });
|
||||
},
|
||||
|
||||
validate : (rawBrewText) => {
|
||||
var errors = [];
|
||||
var leftovers = _.reduce(rawBrewText.split('\n'), (acc, line, _lineNumber) => {
|
||||
var lineNumber = _lineNumber + 1;
|
||||
var matches = line.match(tagRegex);
|
||||
validate : (rawBrewText)=>{
|
||||
const errors = [];
|
||||
const leftovers = _.reduce(rawBrewText.split('\n'), (acc, line, _lineNumber)=>{
|
||||
const lineNumber = _lineNumber + 1;
|
||||
const matches = line.match(tagRegex);
|
||||
if(!matches || !matches.length) return acc;
|
||||
|
||||
_.each(matches, (match)=>{
|
||||
@@ -48,16 +48,16 @@ module.exports = {
|
||||
line : lineNumber,
|
||||
type : type,
|
||||
text : 'Unmatched closing tag',
|
||||
id : 'CLOSE'
|
||||
id : 'CLOSE'
|
||||
});
|
||||
}else if(_.last(acc).type == type){
|
||||
} else if(_.last(acc).type == type){
|
||||
acc.pop();
|
||||
}else{
|
||||
} else {
|
||||
errors.push({
|
||||
line : _.last(acc).line + ' to ' + lineNumber,
|
||||
line : `${_.last(acc).line} to ${lineNumber}`,
|
||||
type : type,
|
||||
text : 'Type mismatch on closing tag',
|
||||
id : 'MISMATCH'
|
||||
id : 'MISMATCH'
|
||||
});
|
||||
acc.pop();
|
||||
}
|
||||
@@ -71,9 +71,9 @@ module.exports = {
|
||||
errors.push({
|
||||
line : unmatched.line,
|
||||
type : unmatched.type,
|
||||
text : "Unmatched opening tag",
|
||||
id : 'OPEN'
|
||||
})
|
||||
text : 'Unmatched opening tag',
|
||||
id : 'OPEN'
|
||||
});
|
||||
});
|
||||
|
||||
return errors;
|
||||
|
||||
Reference in New Issue
Block a user