0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-27 15:52:39 +00:00

Replace SmartyPants plugin with custom

This commit is contained in:
Trevor Buckner
2023-06-02 17:02:45 -04:00
parent 95873ac158
commit 942fdb8095
3 changed files with 42 additions and 26 deletions

View File

@@ -2,8 +2,7 @@
const _ = require('lodash');
const Marked = require('marked');
const MarkedExtendedTables = require('marked-extended-tables');
const {gfmHeadingId: MarkedGFMHeadingId} = require('marked-gfm-heading-id');
const {markedSmartypants: MarkedSmartyPants} = require('marked-smartypants');
const { gfmHeadingId: MarkedGFMHeadingId } = require('marked-gfm-heading-id');
const renderer = new Marked.Renderer();
//Processes the markdown within an HTML block if it's just a class-wrapper
@@ -238,10 +237,49 @@ const definitionLists = {
}
};
const MarkedSmartyPantsLite = ()=>{
return {
tokenizer : {
inlineText(src) {
// don't escape inlineText
const cap = this.rules.inline.text.exec(src);
/* istanbul ignore next */
if(!cap) {
// should never happen
return;
}
const text = cap[0]
// em-dashes
.replace(/---/g, '\u2014')
// en-dashes
.replace(/--/g, '\u2013')
// opening singles
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
// closing singles & apostrophes
.replace(/'/g, '\u2019')
// opening doubles
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
// closing doubles
.replace(/"/g, '\u201d')
// ellipses
.replace(/\.{3}/g, '\u2026');
return {
type : 'text',
raw : cap[0],
text : text
};
}
}
};
};
Marked.use({ extensions: [mustacheSpans, mustacheDivs, mustacheInjectInline, definitionLists] });
Marked.use(mustacheInjectBlock);
Marked.use({ renderer: renderer, smartypants: true, mangle: false, smartypants: false });
Marked.use(MarkedExtendedTables(), MarkedGFMHeadingId(), MarkedSmartyPants());
Marked.use({ renderer: renderer, mangle: false });
Marked.use(MarkedExtendedTables(), MarkedGFMHeadingId(), MarkedSmartyPantsLite());
//Fix local links in the Preview iFrame to link inside the frame
renderer.link = function (href, title, text) {