const _ = require('lodash'); const Markdown = require('marked'); // Copied directly from Marked helpers.js source with permission function splitCells(tableRow, count) { // ensure that every cell-delimiting pipe has a space // before it to distinguish it from an escaped pipe const row = tableRow.replace(/\|/g, (match, offset, str) => { let escaped = false, curr = offset; while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; if (escaped) { // odd number of slashes means | is escaped // so we leave it alone return '|'; } else { // add space before unescaped | return ' |'; } }), cells = row.split(/ \|/); let i = 0; if (cells.length > count) { cells.splice(count); } else { while (cells.length < count) cells.push(''); } for (; i < cells.length; i++) { // leading or trailing whitespace is ignored per the gfm spec cells[i] = cells[i].trim().replace(/\\\|/g, '|'); } return cells; } const renderer = { // Adjust the way html is handled html(html) { // Processes the markdown within an HTML block if it's just a class-wrapper 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)}`; } } // Above may work better if we just force /*if(_.startsWith(_.trim(html), '\n'; } return code; }*/ Markdown.use({ renderer, tokenizer }); const sanatizeScriptTags = (content)=>{ return content .replace(/