const _ = require('lodash');
const Markdown = require('marked');
const renderer = new Markdown.Renderer();
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
if(_.startsWith(_.trim(html), '
')+1);
let closeTag = '';
html = html.substring(html.indexOf('>')+1);
if(_.endsWith(_.trim(html), '
')){
closeTag = '';
html = html.substring(0,html.lastIndexOf('')+1);
if(!_.endsWith(_.trim(html), '>')){ // If there is no closing tag, parse markdown directly after
let remainder = html.substring(html.indexOf('>')+1);
return `${openTag} ${Markdown(remainder)}`;
}
}
/*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)}`;
}
}*/
return html;
};
/*renderer.code = function (code, infostring, escaped) {
if(code == ''){
return '\n
';
}
return code;
}*/
const sanatizeScriptTags = (content)=>{
return content
.replace(/