From cd2337ff2cb62a702b8b82f88de03238d81005f6 Mon Sep 17 00:00:00 2001 From: Scott Tolksdorf Date: Mon, 12 Sep 2016 09:58:32 -0400 Subject: [PATCH] Experimenting with validation more --- client/homebrew/brewRenderer/brewRenderer.jsx | 16 +++++ shared/naturalcrit/markdown.js | 60 +++++++------------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/client/homebrew/brewRenderer/brewRenderer.jsx b/client/homebrew/brewRenderer/brewRenderer.jsx index 61e264f..ecb748e 100644 --- a/client/homebrew/brewRenderer/brewRenderer.jsx +++ b/client/homebrew/brewRenderer/brewRenderer.jsx @@ -75,6 +75,20 @@ var BrewRenderer = React.createClass({ }, renderPage : function(pageText, index){ + + var html = Markdown.render(pageText) + + var checkHTML = function(html) { + var doc = document.createElement('div'); + doc.innerHTML = html; + console.log(doc.innerHTML); + return ( doc.innerHTML === html ); + } + + console.log('page', index, checkHTML(html)); + + + return
}, @@ -82,6 +96,8 @@ var BrewRenderer = React.createClass({ var pages = this.props.text.split('\\page'); this.totalPages = pages.length; + + //TESTING VALIDATION try{ var temp = Markdown.validate(this.props.text); diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 6263e68..dc2d63d 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -20,59 +20,43 @@ module.exports = { validate : (rawText)=>{ var currentLine = 0; var errors = []; - var tokens = Markdown.lexer(rawText); + var tokens = Markdown.lexer(rawText, {renderer : renderer}); - _.each(tokens, (token)=>{ + return _.filter(_.map(tokens, (token)=>{ if(token.type === 'paragraph' || token.type === 'html'){ var hasOpen = token.text.indexOf('') !== -1; - if(hasClose && token.text.length > 6){ - errors.push({ - err : ' Closing tags must be on their own line', + + if(hasOpen && !hasClose){ + return { + err : 'No closing tag', token : token, line : currentLine - }); + }; } - else if(hasOpen && !hasClose){ - errors.push({ - err : ' No closing tag', + if(hasClose && !hasOpen){ + if(token.text.length > 6){ + return { + err : 'Closing tags must be on their own line', + token : token, + line : currentLine + }; + } + return { + err : 'No opening tag', token : token, line : currentLine - }); - } - else if(hasClose && !hasOpen){ - errors.push({ - err : ' No opening tag', - token : token, - line : currentLine - }); + }; } - - /* - - - if(_.startsWith(token.text, '')){ - //Do a check to make sure it's on it's own line - - errors.push({ - err : ' No opening tag', - token : token, - line : currentLine - }) - } - */ } //console.log(token); - }); + + //currentLine += token.text.split('\n').length + 1; + + })); return errors; },