mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 20:42:44 +00:00
Merge pull request #4044 from dbolack-ab/marked-justifiedParagraphs
Migrate the justified paragraphs extension to an NPM
This commit is contained in:
10
package-lock.json
generated
10
package-lock.json
generated
@@ -34,6 +34,7 @@
|
|||||||
"less": "^3.13.1",
|
"less": "^3.13.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"marked": "15.0.8",
|
"marked": "15.0.8",
|
||||||
|
"marked-alignment-paragraphs": "^1.0.0",
|
||||||
"marked-emoji": "^2.0.0",
|
"marked-emoji": "^2.0.0",
|
||||||
"marked-extended-tables": "^2.0.1",
|
"marked-extended-tables": "^2.0.1",
|
||||||
"marked-gfm-heading-id": "^4.0.1",
|
"marked-gfm-heading-id": "^4.0.1",
|
||||||
@@ -9979,6 +9980,15 @@
|
|||||||
"node": ">= 18"
|
"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": {
|
"node_modules/marked-emoji": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/marked-emoji/-/marked-emoji-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/marked-emoji/-/marked-emoji-2.0.0.tgz",
|
||||||
|
|||||||
@@ -111,6 +111,7 @@
|
|||||||
"marked-emoji": "^2.0.0",
|
"marked-emoji": "^2.0.0",
|
||||||
"marked-extended-tables": "^2.0.1",
|
"marked-extended-tables": "^2.0.1",
|
||||||
"marked-gfm-heading-id": "^4.0.1",
|
"marked-gfm-heading-id": "^4.0.1",
|
||||||
|
"marked-alignment-paragraphs": "^1.0.0",
|
||||||
"marked-nonbreaking-spaces": "^1.0.1",
|
"marked-nonbreaking-spaces": "^1.0.1",
|
||||||
"marked-smartypants-lite": "^1.0.3",
|
"marked-smartypants-lite": "^1.0.3",
|
||||||
"marked-subsuper-text": "^1.0.3",
|
"marked-subsuper-text": "^1.0.3",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import MarkedExtendedTables from 'marked-extended-tables';
|
|||||||
import { markedSmartypantsLite as MarkedSmartypantsLite } from 'marked-smartypants-lite';
|
import { markedSmartypantsLite as MarkedSmartypantsLite } from 'marked-smartypants-lite';
|
||||||
import { gfmHeadingId as MarkedGFMHeadingId, resetHeadings as MarkedGFMResetHeadingIDs } from 'marked-gfm-heading-id';
|
import { gfmHeadingId as MarkedGFMHeadingId, resetHeadings as MarkedGFMResetHeadingIDs } from 'marked-gfm-heading-id';
|
||||||
import { markedEmoji as MarkedEmojis } from 'marked-emoji';
|
import { markedEmoji as MarkedEmojis } from 'marked-emoji';
|
||||||
|
import MarkedAlignedParagraphs from 'marked-alignment-paragraphs';
|
||||||
import MarkedNonbreakingSpaces from 'marked-nonbreaking-spaces';
|
import MarkedNonbreakingSpaces from 'marked-nonbreaking-spaces';
|
||||||
import MarkedSubSuperText from 'marked-subsuper-text';
|
import MarkedSubSuperText from 'marked-subsuper-text';
|
||||||
import { romanize } from 'romans';
|
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 `<p align="${token.class}">${this.parser.parseInline(token.tokens)}</p>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const forcedParagraphBreaks = {
|
const forcedParagraphBreaks = {
|
||||||
name : 'hardBreaks',
|
name : 'hardBreaks',
|
||||||
level : 'block',
|
level : 'block',
|
||||||
@@ -800,9 +765,10 @@ const tableTerminators = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
Marked.use(MarkedVariables());
|
Marked.use(MarkedVariables());
|
||||||
Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks,
|
Marked.use({ extensions : [definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks,
|
||||||
mustacheSpans, mustacheDivs, mustacheInjectInline] });
|
mustacheSpans, mustacheDivs, mustacheInjectInline] });
|
||||||
Marked.use(mustacheInjectBlock);
|
Marked.use(mustacheInjectBlock);
|
||||||
|
Marked.use(MarkedAlignedParagraphs());
|
||||||
Marked.use(MarkedSubSuperText());
|
Marked.use(MarkedSubSuperText());
|
||||||
Marked.use(MarkedNonbreakingSpaces());
|
Marked.use(MarkedNonbreakingSpaces());
|
||||||
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
||||||
|
|||||||
Reference in New Issue
Block a user