0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +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

21
package-lock.json generated
View File

@@ -32,7 +32,6 @@
"marked": "5.0.4",
"marked-extended-tables": "^1.0.6",
"marked-gfm-heading-id": "^3.0.3",
"marked-smartypants": "^1.0.2",
"markedLegacy": "npm:marked@^0.3.19",
"moment": "^2.29.4",
"mongoose": "^7.2.2",
@@ -9684,17 +9683,6 @@
"marked": "^4 || ^5"
}
},
"node_modules/marked-smartypants": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/marked-smartypants/-/marked-smartypants-1.0.2.tgz",
"integrity": "sha512-hpbM9waiBSIHpqdoU5AAeuYozeObBwUet3xkCFrFBA+1329byRVxLDwYmelMCS3ss+sEVJhDgrunIy+ubiqFwQ==",
"dependencies": {
"smartypants": "^0.1.6"
},
"peerDependencies": {
"marked": "^4 || ^5"
}
},
"node_modules/markedLegacy": {
"name": "marked",
"version": "0.3.19",
@@ -15333,15 +15321,6 @@
"npm": ">= 3.0.0"
}
},
"node_modules/smartypants": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/smartypants/-/smartypants-0.1.6.tgz",
"integrity": "sha512-zGXh+Q6Y3OPTLM5x2HxAIkEAj4ZcePftmIOdIYozv2T+m03Sp5R4YppczKuo6IdnSMc99U+Wgvy8Mil0eeep7g==",
"bin": {
"smartypants": "bin/smartypants.js",
"smartypantsu": "bin/smartypantsu.js"
}
},
"node_modules/snapdragon": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",

View File

@@ -100,7 +100,6 @@
"marked": "5.0.4",
"marked-extended-tables": "^1.0.6",
"marked-gfm-heading-id": "^3.0.3",
"marked-smartypants": "^1.0.2",
"markedLegacy": "npm:marked@^0.3.19",
"moment": "^2.29.4",
"mongoose": "^7.2.2",

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) {