mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-13 12:45:56 +00:00
Experimenting with validation more
This commit is contained in:
@@ -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 <div className='phb' id={`p${index + 1}`} dangerouslySetInnerHTML={{__html:Markdown.render(pageText)}} key={index} />
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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('<div') !== -1;
|
||||
var hasClose = token.text.indexOf('</div>') !== -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, '<div')){
|
||||
errors.push({
|
||||
err : ' No closing tag',
|
||||
token : token,
|
||||
line : currentLine
|
||||
});
|
||||
}else if(_.startsWith(token.text, '</div>')){
|
||||
//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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user