0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +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
startDB.bat
startMViewer.bat
*.xlsx

View File

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