0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 08:22:42 +00:00

Fix HTML right before markdown

Allow raw HTML tags to end without a blank line if markdown is right after
This commit is contained in:
Trevor Buckner
2020-04-14 10:26:42 -04:00
parent 5bc948ab0a
commit 5631ef7be7
2 changed files with 11 additions and 28 deletions

1
.gitignore vendored
View File

@@ -10,3 +10,4 @@ config/local.*
todo.md todo.md
startDB.bat startDB.bat
startMViewer.bat startMViewer.bat
*.xlsx

View File

@@ -1,6 +1,7 @@
const _ = require('lodash'); const _ = require('lodash');
const Markdown = require('marked'); const Markdown = require('marked');
const renderer = new Markdown.Renderer(); const renderer = new Markdown.Renderer();
const lexer = new Markdown.Lexer();
//Processes the markdown within an HTML block if it's just a class-wrapper //Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) { renderer.html = function (html) {
@@ -15,12 +16,6 @@ renderer.html = function (html) {
return `${openTag} ${Markdown(html)} ${closeTag}`; return `${openTag} ${Markdown(html)} ${closeTag}`;
} }
// Below may work better if we just explicitly allow <script, <pre and <style
// tags to return directly
/*if(_.startsWith(_.trim(html), '<script')){
return html;
}*/
// Allow raw HTML tags to end without a blank line if markdown is right after // Allow raw HTML tags to end without a blank line if markdown is right after
if(html.includes('\n')){ if(html.includes('\n')){
let openTag = html.substring(0, html.indexOf('>')+1); let openTag = html.substring(0, html.indexOf('>')+1);
@@ -30,31 +25,17 @@ renderer.html = function (html) {
} }
} }
/*if(html.includes('\n')){ // Above may work better if we just explicitly allow <script, <pre and <style
//let openTag = html.substring(0, html.indexOf('\n')); // tags to return directly
let openTag = html.substring(0, html.indexOf('>')+1); /*if(_.startsWith(_.trim(html), '<script')){
console.log("FULL HTML"); return html;
console.log(html); }*/
console.log("OPEN TAG");
console.log(openTag);
let closeTag = '';
if(_.endsWith(_.trim(html), '>')){
closeTag = html.substring(html.lastIndexOf('<'));
console.log("CLOSETAG");
console.log(closeTag);
}
else {
let remainder = html.substring(html.indexOf('>')+1);
console.log("REMAINDER");
console.log(remainder);
return `${openTag} ${Markdown(remainder)}`;
}
}*/
return html; return html;
}; };
console.log(lexer.rules);
/*renderer.code = function (code, infostring, escaped) { /*renderer.code = function (code, infostring, escaped) {
if(code == ''){ if(code == ''){
return '<pre><code>\n</code></pre>'; return '<pre><code>\n</code></pre>';
@@ -80,7 +61,8 @@ module.exports = {
render : (rawBrewText)=>{ render : (rawBrewText)=>{
return Markdown( return Markdown(
sanatizeScriptTags(rawBrewText), sanatizeScriptTags(rawBrewText),
{ renderer: renderer } { renderer: renderer,
lexer: lexer }
); );
}, },