0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Revert Marked Update

Too many edge cases still broken. Bah.
This commit is contained in:
Trevor Buckner
2020-05-10 21:11:03 -04:00
parent e94148b2f0
commit 7c813be13a
5 changed files with 1395 additions and 1503 deletions

View File

@@ -4,7 +4,7 @@ const createClass = require('create-react-class');
const _ = require('lodash');
const cx = require('classnames'); //Unused variable
const DISMISS_KEY = 'dismiss_notification5-8-2020';
const DISMISS_KEY = 'dismiss_notification7-24-19';
const NotificationPopup = createClass({
getInitialState : function() {
@@ -21,24 +21,19 @@ const NotificationPopup = createClass({
},
notifications : {
psa : function(){
return <li key='markdown'>
<em>Markdown library update </em> <br />
We have updated the library that converts your brews from markdown to
HTML for security reasons. We have made every effort to make sure your
homebrews appear just as they did before, but there's always a chance we
missed something. If your homebrew has started rendering incorrectly
since your last visit,&nbsp;
<a target='_blank' href={`https://www.reddit.com/r/homebrewery/submit?selftext=true&title=${encodeURIComponent('[Issue] Describe Your Issue Here')}`}>
please let us know
</a>
&nbsp;and we will try to fix your issue as soon as possible.
return <li key='psa'>
<em>Known bug: Grey Shadow Boxes </em> <br />
The shadows around certain brew elements such as notes and statblocks might appear as a solid grey box when generating a PDF. &nbsp;
<a target='_blank' href='https://old.reddit.com/r/homebrewery/comments/ch3v0d/psa_grey_boxesshadows_around_notes_stat_blocks_etc/'>
See this Reddit post
</a> for updates and possible workarounds.
</li>;
},
faq : function(){
return <li key='faq'>
<em>Protect your work! </em> <br />
At the moment we do not save a history of your projects, so please make frequent backups of your brews! &nbsp;
<a target='_blank' href='https://www.reddit.com/r/homebrewery/comments/fwhl3n/faq_psas_announcements/'>
<a target='_blank' href='https://www.reddit.com/r/homebrewery/comments/adh6lh/faqs_psas_announcements/'>
See the FAQ
</a> to learn how to avoid losing your work!
</li>;

View File

@@ -177,12 +177,6 @@ body {
}
}
//*****************************
// * SPLIT TABLE
// *****************************/
div table+pre {
display: none;
}
//*****************************
// * NOTE
// *****************************/
blockquote{
@@ -336,8 +330,9 @@ body {
//Column Break
pre, code{
visibility : hidden;
break-after : column;
min-height : 1px;
-webkit-column-break-after : always;
break-after : always;
-moz-column-break-after : always;
}
//Avoid breaking up
p,blockquote,table{

2740
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -46,7 +46,7 @@
"express": "^4.17.1",
"jwt-simple": "^0.5.6",
"lodash": "^4.17.15",
"marked": "^1.0.0",
"marked": "^0.3.19",
"moment": "^2.25.3",
"mongoose": "^5.9.12",
"nconf": "^0.10.0",

View File

@@ -1,119 +1,18 @@
const _ = require('lodash');
const Markdown = require('marked');
const renderer = new Markdown.Renderer();
// Copied directly from Marked helpers.js source with permission
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('');
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
const openTag = html.substring(0, html.indexOf('>')+1);
html = html.substring(html.indexOf('>')+1);
html = html.substring(0, html.lastIndexOf('</div>'));
return `${openTag} ${Markdown(html)} </div>`;
}
for (; i < cells.length; i++) {
// leading or trailing whitespace is ignored per the gfm spec
cells[i] = cells[i].trim().replace(/\\\|/g, '|');
}
return cells;
return html;
};
const renderer = {
// Adjust the way html is handled
html(html) {
html = _.trim(html);
// Process the markdown within Divs
if(_.startsWith(html, '<div') && html.includes('>')) {
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, '<style') || _.startsWith(html, '<pre') || _.startsWith(html, '<img')) {
if(html.includes('>')) {
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)}`;
}
return html;
}
};
const tokenizer = {
//Adjust tables to work even if columns are uneven
table(src) {
const cap = this.rules.block.table.exec(src);
if(cap) {
const item = {
type : 'table',
header : splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
align : cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells : cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
};
item.raw = cap[0];
let l = item.align.length;
let i;
for (i = 0; i < l; i++) {
if(/^ *-+: *$/.test(item.align[i])) {
item.align[i] = 'right';
} else if(/^ *:-+: *$/.test(item.align[i])) {
item.align[i] = 'center';
} else if(/^ *:-+ *$/.test(item.align[i])) {
item.align[i] = 'left';
} else {
item.align[i] = null;
}
}
l = item.cells.length;
for (i = 0; i < l; i++) {
item.cells[i] = splitCells(
item.cells[i].replace(/^ *\| *| *\| *$/g, ''),
item.header.length);
}
return item;
}
}
};
/*renderer.code = function (code, infostring, escaped) {
if(code == ''){
return '<pre><code>\n</code></pre>';
}
return code;
}*/
Markdown.use({ renderer, tokenizer });
const sanatizeScriptTags = (content)=>{
return content
.replace(/<script/ig, '&lt;script')
@@ -131,7 +30,9 @@ module.exports = {
marked : Markdown,
render : (rawBrewText)=>{
return Markdown(
sanatizeScriptTags(rawBrewText));
sanatizeScriptTags(rawBrewText),
{ renderer: renderer }
);
},
validate : (rawBrewText)=>{
@@ -186,3 +87,4 @@ module.exports = {
return errors;
},
};