diff --git a/.eslintrc.js b/.eslintrc.js index 713bd875a..6c0006f6c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,6 +9,7 @@ module.exports = { }, env : { browser : true, + node: true }, plugins : ['react'], rules : { @@ -66,7 +67,7 @@ module.exports = { multiLine : { beforeColon: true, afterColon: true, align: 'colon' }, singleLine : { beforeColon: false, afterColon: true } }], - 'linebreak-style' : ['warn', 'unix'], + 'linebreak-style' : 'off', 'no-trailing-spaces' : 'warn', 'no-whitespace-before-property' : 'warn', 'object-curly-spacing' : ['warn', 'always'], @@ -74,4 +75,4 @@ module.exports = { 'space-in-parens' : ['warn', 'never'], 'template-curly-spacing' : ['warn', 'never'], } -}; \ No newline at end of file +}; diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 35519aa32..f9d2fbffa 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -2,74 +2,79 @@ 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; +const splitCells = function(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(''); - } + 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; -} + 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) { - html = _.trim(html) + html = _.trim(html); - // Process the markdown within Divs - if(_.startsWith(html, '')) { - let openTag = html.substring(0, html.indexOf('>')+1); - html = html.substring(html.indexOf('>')+1); - return `${openTag} ${Markdown(html)}`; - } + // Process the markdown within Divs + if(_.startsWith(html, '')) { + const openTag = html.substring(0, html.indexOf('>')+1); + html = html.substring(html.indexOf('>')+1); + return `${openTag} ${Markdown(html)}`; + } + + // Don't require a blank line after HTML to parse Markdown + if(html.includes('\n')) { + if(_.startsWith(html, '')) { + const openTag = html.substring(0, html.lastIndexOf('>')+1); + html = html.substring(html.lastIndexOf('>')+1); + 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)}`; + } - // Don't require a blank line after HTML to parse Markdown - if(html.includes('\n')) { - if(_.startsWith(html, '