mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-15 22:55:56 +00:00
Experimenting with validation more
This commit is contained in:
@@ -75,6 +75,20 @@ var BrewRenderer = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
renderPage : function(pageText, index){
|
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} />
|
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');
|
var pages = this.props.text.split('\\page');
|
||||||
this.totalPages = pages.length;
|
this.totalPages = pages.length;
|
||||||
|
|
||||||
|
|
||||||
|
//TESTING VALIDATION
|
||||||
try{
|
try{
|
||||||
var temp = Markdown.validate(this.props.text);
|
var temp = Markdown.validate(this.props.text);
|
||||||
|
|
||||||
|
|||||||
@@ -20,59 +20,43 @@ module.exports = {
|
|||||||
validate : (rawText)=>{
|
validate : (rawText)=>{
|
||||||
var currentLine = 0;
|
var currentLine = 0;
|
||||||
var errors = [];
|
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'){
|
if(token.type === 'paragraph' || token.type === 'html'){
|
||||||
|
|
||||||
var hasOpen = token.text.indexOf('<div') !== -1;
|
var hasOpen = token.text.indexOf('<div') !== -1;
|
||||||
var hasClose = token.text.indexOf('</div>') !== -1;
|
var hasClose = token.text.indexOf('</div>') !== -1;
|
||||||
|
|
||||||
if(hasClose && token.text.length > 6){
|
|
||||||
errors.push({
|
if(hasOpen && !hasClose){
|
||||||
err : ' Closing tags must be on their own line',
|
return {
|
||||||
|
err : 'No closing tag',
|
||||||
token : token,
|
token : token,
|
||||||
line : currentLine
|
line : currentLine
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
else if(hasOpen && !hasClose){
|
if(hasClose && !hasOpen){
|
||||||
errors.push({
|
if(token.text.length > 6){
|
||||||
err : ' No closing tag',
|
return {
|
||||||
|
err : 'Closing tags must be on their own line',
|
||||||
|
token : token,
|
||||||
|
line : currentLine
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
err : 'No opening tag',
|
||||||
token : token,
|
token : token,
|
||||||
line : currentLine
|
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);
|
//console.log(token);
|
||||||
});
|
|
||||||
|
//currentLine += token.text.split('\n').length + 1;
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user