mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 09:12:39 +00:00
Fix Markdown rendering right after Divs
This commit is contained in:
@@ -37,33 +37,25 @@ function splitCells(tableRow, count) {
|
|||||||
const renderer = {
|
const renderer = {
|
||||||
// Adjust the way html is handled
|
// Adjust the way html is handled
|
||||||
html(html) {
|
html(html) {
|
||||||
// Processes the markdown within an HTML block if it's just a class-wrapper
|
html = _.trim(html)
|
||||||
if(_.startsWith(_.trim(html), '<div')){
|
|
||||||
let openTag = html.substring(0, html.indexOf('>')+1);
|
|
||||||
let closeTag = '';
|
|
||||||
html = html.substring(html.indexOf('>')+1);
|
|
||||||
if(_.endsWith(_.trim(html), '</div>')){
|
|
||||||
closeTag = '</div>';
|
|
||||||
html = html.substring(0,html.lastIndexOf('</div'));
|
|
||||||
}
|
|
||||||
return `${openTag} ${Markdown(html)} ${closeTag}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow raw HTML tags to end without a blank line if markdown is right after
|
// Process the markdown within Divs
|
||||||
if(html.includes('\n')){
|
if(_.startsWith(html, '<div') && html.includes('>')) {
|
||||||
let openTag = html.substring(0, html.indexOf('>')+1);
|
let openTag = html.substring(0, html.indexOf('>')+1);
|
||||||
if(!_.endsWith(_.trim(html), '>')){ // If there is no closing tag, parse markdown directly after
|
html = html.substring(html.indexOf('>')+1);
|
||||||
let remainder = html.substring(html.indexOf('>')+1);
|
return `${openTag} ${Markdown(html)}`;
|
||||||
return `${openTag} ${Markdown(remainder)}`;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Above may work better if we just force <script, <pre and <style
|
|
||||||
// tags to return directly instead of working around <divs>
|
|
||||||
/*if(_.startsWith(_.trim(html), '<script')){
|
|
||||||
return html;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
// Don't require a blank line after HTML to parse Markdown
|
||||||
|
if(html.includes('\n')) {
|
||||||
|
if(_.startsWith(html, '<style') || _.startsWith(html, '<pre')) {
|
||||||
|
return html; // Style and Pre tags should not parse Markdown
|
||||||
|
}
|
||||||
|
let openTag = html.substring(0, html.indexOf('\n')+1);
|
||||||
|
html = html.substring(html.indexOf('\n')+1);
|
||||||
|
return `${openTag} ${Markdown(html)}`;
|
||||||
|
}
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user