diff --git a/package-lock.json b/package-lock.json index 71d2693a9..4633936df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "less": "^3.13.1", "lodash": "^4.17.21", "marked": "15.0.8", + "marked-alignment-paragraphs": "^1.0.0", "marked-emoji": "^2.0.0", "marked-extended-tables": "^2.0.1", "marked-gfm-heading-id": "^4.0.1", @@ -9979,6 +9980,15 @@ "node": ">= 18" } }, + "node_modules/marked-alignment-paragraphs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/marked-alignment-paragraphs/-/marked-alignment-paragraphs-1.0.0.tgz", + "integrity": "sha512-e+X+vUt9oteG4I0+29ZvTjrNEvB2/uo/Dhczu+Nq0shITA3oqYmTercT25mq+2mfJQQn7xiJGXPmDmBSFgotIA==", + "license": "MIT", + "peerDependencies": { + "marked": ">=3 <16" + } + }, "node_modules/marked-emoji": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/marked-emoji/-/marked-emoji-2.0.0.tgz", diff --git a/package.json b/package.json index a98cf59ff..4eb617d7c 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "marked-emoji": "^2.0.0", "marked-extended-tables": "^2.0.1", "marked-gfm-heading-id": "^4.0.1", + "marked-alignment-paragraphs": "^1.0.0", "marked-nonbreaking-spaces": "^1.0.1", "marked-smartypants-lite": "^1.0.3", "marked-subsuper-text": "^1.0.3", diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 6f5fa6fc6..a9740652b 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -7,6 +7,7 @@ import MarkedExtendedTables from 'marked-extended-tables'; import { markedSmartypantsLite as MarkedSmartypantsLite } from 'marked-smartypants-lite'; import { gfmHeadingId as MarkedGFMHeadingId, resetHeadings as MarkedGFMResetHeadingIDs } from 'marked-gfm-heading-id'; import { markedEmoji as MarkedEmojis } from 'marked-emoji'; +import MarkedAlignedParagraphs from 'marked-alignment-paragraphs'; import MarkedNonbreakingSpaces from 'marked-nonbreaking-spaces'; import MarkedSubSuperText from 'marked-subsuper-text'; import { romanize } from 'romans'; @@ -388,42 +389,6 @@ const mustacheInjectBlock = { } }; -const justifiedParagraphClasses = []; -justifiedParagraphClasses[2] = 'Left'; -justifiedParagraphClasses[4] = 'Right'; -justifiedParagraphClasses[6] = 'Center'; - -const justifiedParagraphs = { - name : 'justifiedParagraphs', - level : 'block', - start(src) { - return src.match(/\n(?:-:|:-|-:) {1}/m)?.index; - }, // Hint to Marked.js to stop and check for a match - tokenizer(src, tokens) { - const regex = /^(((:-))|((-:))|((:-:))) .+(\n(([^\n].*\n)*(\n|$))|$)/ygm; - const match = regex.exec(src); - if(match?.length) { - let whichJustify; - if(match[2]?.length) whichJustify = 2; - if(match[4]?.length) whichJustify = 4; - if(match[6]?.length) whichJustify = 6; - return { - type : 'justifiedParagraphs', // Should match "name" above - raw : match[0], // Text to consume from the source - length : match[whichJustify].length, - text : match[0].slice(match[whichJustify].length), - class : justifiedParagraphClasses[whichJustify], - tokens : this.lexer.inlineTokens(match[0].slice(match[whichJustify].length + 1)) - }; - } - }, - renderer(token) { - return `
${this.parser.parseInline(token.tokens)}
`; - } - -}; - - const forcedParagraphBreaks = { name : 'hardBreaks', level : 'block', @@ -800,9 +765,10 @@ const tableTerminators = [ ]; Marked.use(MarkedVariables()); -Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, +Marked.use({ extensions : [definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, mustacheSpans, mustacheDivs, mustacheInjectInline] }); Marked.use(mustacheInjectBlock); +Marked.use(MarkedAlignedParagraphs()); Marked.use(MarkedSubSuperText()); Marked.use(MarkedNonbreakingSpaces()); Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });