mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-31 13:02:38 +00:00
Fix multiline IMG tags breaking
This commit is contained in:
@@ -9,6 +9,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
env : {
|
env : {
|
||||||
browser : true,
|
browser : true,
|
||||||
|
node: true
|
||||||
},
|
},
|
||||||
plugins : ['react'],
|
plugins : ['react'],
|
||||||
rules : {
|
rules : {
|
||||||
@@ -66,7 +67,7 @@ module.exports = {
|
|||||||
multiLine : { beforeColon: true, afterColon: true, align: 'colon' },
|
multiLine : { beforeColon: true, afterColon: true, align: 'colon' },
|
||||||
singleLine : { beforeColon: false, afterColon: true }
|
singleLine : { beforeColon: false, afterColon: true }
|
||||||
}],
|
}],
|
||||||
'linebreak-style' : ['warn', 'unix'],
|
'linebreak-style' : 'off',
|
||||||
'no-trailing-spaces' : 'warn',
|
'no-trailing-spaces' : 'warn',
|
||||||
'no-whitespace-before-property' : 'warn',
|
'no-whitespace-before-property' : 'warn',
|
||||||
'object-curly-spacing' : ['warn', 'always'],
|
'object-curly-spacing' : ['warn', 'always'],
|
||||||
|
|||||||
@@ -2,74 +2,79 @@ const _ = require('lodash');
|
|||||||
const Markdown = require('marked');
|
const Markdown = require('marked');
|
||||||
|
|
||||||
// Copied directly from Marked helpers.js source with permission
|
// Copied directly from Marked helpers.js source with permission
|
||||||
function splitCells(tableRow, count) {
|
const splitCells = function(tableRow, count) {
|
||||||
// ensure that every cell-delimiting pipe has a space
|
// ensure that every cell-delimiting pipe has a space
|
||||||
// before it to distinguish it from an escaped pipe
|
// before it to distinguish it from an escaped pipe
|
||||||
const row = tableRow.replace(/\|/g, (match, offset, str) => {
|
const row = tableRow.replace(/\|/g, (match, offset, str)=>{
|
||||||
let escaped = false,
|
let escaped = false,
|
||||||
curr = offset;
|
curr = offset;
|
||||||
while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
|
while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
|
||||||
if (escaped) {
|
if(escaped) {
|
||||||
// odd number of slashes means | is escaped
|
// odd number of slashes means | is escaped
|
||||||
// so we leave it alone
|
// so we leave it alone
|
||||||
return '|';
|
return '|';
|
||||||
} else {
|
} else {
|
||||||
// add space before unescaped |
|
// add space before unescaped |
|
||||||
return ' |';
|
return ' |';
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
cells = row.split(/ \|/);
|
cells = row.split(/ \|/);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
if (cells.length > count) {
|
if(cells.length > count) {
|
||||||
cells.splice(count);
|
cells.splice(count);
|
||||||
} else {
|
} else {
|
||||||
while (cells.length < count) cells.push('');
|
while (cells.length < count) cells.push('');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; i < cells.length; i++) {
|
for (; i < cells.length; i++) {
|
||||||
// leading or trailing whitespace is ignored per the gfm spec
|
// leading or trailing whitespace is ignored per the gfm spec
|
||||||
cells[i] = cells[i].trim().replace(/\\\|/g, '|');
|
cells[i] = cells[i].trim().replace(/\\\|/g, '|');
|
||||||
}
|
}
|
||||||
return cells;
|
return cells;
|
||||||
}
|
};
|
||||||
|
|
||||||
const renderer = {
|
const renderer = {
|
||||||
// Adjust the way html is handled
|
// Adjust the way html is handled
|
||||||
html(html) {
|
html(html) {
|
||||||
html = _.trim(html)
|
html = _.trim(html);
|
||||||
|
|
||||||
// Process the markdown within Divs
|
// Process the markdown within Divs
|
||||||
if(_.startsWith(html, '<div') && html.includes('>')) {
|
if(_.startsWith(html, '<div') && html.includes('>')) {
|
||||||
let openTag = html.substring(0, html.indexOf('>')+1);
|
const openTag = html.substring(0, html.indexOf('>')+1);
|
||||||
html = html.substring(html.indexOf('>')+1);
|
html = html.substring(html.indexOf('>')+1);
|
||||||
return `${openTag} ${Markdown(html)}`;
|
return `${openTag} ${Markdown(html)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't require a blank line after HTML to parse Markdown
|
// Don't require a blank line after HTML to parse Markdown
|
||||||
if(html.includes('\n')) {
|
if(html.includes('\n')) {
|
||||||
if(_.startsWith(html, '<style') || _.startsWith(html, '<pre')) {
|
if(_.startsWith(html, '<style') || _.startsWith(html, '<pre') || _.startsWith(html, '<img')) {
|
||||||
return html; // Style and Pre tags should not parse Markdown
|
if(html.includes('>')) {
|
||||||
}
|
const openTag = html.substring(0, html.lastIndexOf('>')+1);
|
||||||
let openTag = html.substring(0, html.indexOf('\n')+1);
|
html = html.substring(html.lastIndexOf('>')+1);
|
||||||
html = html.substring(html.indexOf('\n')+1);
|
return `${openTag} ${Markdown(html)}`;
|
||||||
return `${openTag} ${Markdown(html)}`;
|
}
|
||||||
}
|
return html; // Style, Pre, and Img tags should not parse Markdown
|
||||||
|
}
|
||||||
|
const openTag = html.substring(0, html.indexOf('\n')+1);
|
||||||
|
html = html.substring(html.indexOf('\n')+1);
|
||||||
|
return `${openTag} ${Markdown(html)}`;
|
||||||
|
}
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const tokenizer = {
|
const tokenizer = {
|
||||||
//Adjust tables to work even if columns are uneven
|
//Adjust tables to work even if columns are uneven
|
||||||
table(src) {
|
table(src) {
|
||||||
const cap = this.rules.block.table.exec(src);
|
const cap = this.rules.block.table.exec(src);
|
||||||
if (cap) {
|
if(cap) {
|
||||||
const item = {
|
const item = {
|
||||||
type: 'table',
|
type : 'table',
|
||||||
header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
|
header : splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
|
||||||
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
align : cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
||||||
cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
cells : cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
||||||
};
|
};
|
||||||
|
|
||||||
item.raw = cap[0];
|
item.raw = cap[0];
|
||||||
@@ -77,11 +82,11 @@ const tokenizer = {
|
|||||||
let l = item.align.length;
|
let l = item.align.length;
|
||||||
let i;
|
let i;
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
if (/^ *-+: *$/.test(item.align[i])) {
|
if(/^ *-+: *$/.test(item.align[i])) {
|
||||||
item.align[i] = 'right';
|
item.align[i] = 'right';
|
||||||
} else if (/^ *:-+: *$/.test(item.align[i])) {
|
} else if(/^ *:-+: *$/.test(item.align[i])) {
|
||||||
item.align[i] = 'center';
|
item.align[i] = 'center';
|
||||||
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
} else if(/^ *:-+ *$/.test(item.align[i])) {
|
||||||
item.align[i] = 'left';
|
item.align[i] = 'left';
|
||||||
} else {
|
} else {
|
||||||
item.align[i] = null;
|
item.align[i] = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user