From 38bd3b0fc52586de7d0aba7bbbfc3e5dc100f979 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Tue, 11 Feb 2025 14:34:01 -0600 Subject: [PATCH 1/4] Migrate the justified paragraphs extension to an NPM --- package-lock.json | 10 +++++ package.json | 1 + shared/naturalcrit/markdown.js | 40 ++----------------- .../markdown/paragraph-justification.test.js | 27 ------------- 4 files changed, 14 insertions(+), 64 deletions(-) delete mode 100644 tests/markdown/paragraph-justification.test.js diff --git a/package-lock.json b/package-lock.json index bd3f71491..a57084dc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "marked-emoji": "^1.4.3", "marked-extended-tables": "^1.1.0", "marked-gfm-heading-id": "^4.0.1", + "marked-justified-paragraphs": "^1.0.0", "marked-smartypants-lite": "^1.0.3", "markedLegacy": "npm:marked@^0.3.19", "moment": "^2.30.1", @@ -9874,6 +9875,15 @@ "marked": ">=13 <16" } }, + "node_modules/marked-justified-paragraphs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/marked-justified-paragraphs/-/marked-justified-paragraphs-1.0.0.tgz", + "integrity": "sha512-TgTKij4HbYy85zWAZ0Va7JCOU/yh8d12Jq2J/jaBHNMa6gJDAsbLT42MFLU9gwLYxsg8hCJHJ0n0zYY6zo8jiA==", + "license": "MIT", + "peerDependencies": { + "marked": ">=3 <16" + } + }, "node_modules/marked-smartypants-lite": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/marked-smartypants-lite/-/marked-smartypants-lite-1.0.3.tgz", diff --git a/package.json b/package.json index 342af4d6e..8c343833d 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,7 @@ "marked-emoji": "^1.4.3", "marked-extended-tables": "^1.1.0", "marked-gfm-heading-id": "^4.0.1", + "marked-justified-paragraphs": "^1.0.0", "marked-smartypants-lite": "^1.0.3", "markedLegacy": "npm:marked@^0.3.19", "moment": "^2.30.1", diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 99766b536..e9ea49d46 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 MarkedJustifiedParagraphs from 'marked-justified-paragraphs'; //Icon fonts included so they can appear in emoji autosuggest dropdown import diceFont from '../../themes/fonts/iconFonts/diceFont.js'; @@ -362,42 +363,6 @@ const superSubScripts = { }; -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', @@ -795,8 +760,9 @@ const tableTerminators = [ ]; Marked.use(MarkedVariables()); -Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, +Marked.use({ extensions : [definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, nonbreakingSpaces, superSubScripts, mustacheSpans, mustacheDivs, mustacheInjectInline] }); +Marked.use(MarkedJustifiedParagraphs()); Marked.use(mustacheInjectBlock); Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false }); Marked.use(MarkedExtendedTables(tableTerminators), MarkedGFMHeadingId({ globalSlugs: true }), diff --git a/tests/markdown/paragraph-justification.test.js b/tests/markdown/paragraph-justification.test.js deleted file mode 100644 index 48b311e85..000000000 --- a/tests/markdown/paragraph-justification.test.js +++ /dev/null @@ -1,27 +0,0 @@ -/* eslint-disable max-lines */ - -import Markdown from 'naturalcrit/markdown.js'; - -describe('Justification', ()=>{ - test('Left Justify', function() { - const source = ':- Hello'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

Hello

`); - }); - test('Right Justify', function() { - const source = '-: Hello'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

Hello

`); - }); - test('Center Justify', function() { - const source = ':-: Hello'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

Hello

`); - }); - - test('Ignored inside a code block', function() { - const source = '```\n\n:- Hello\n\n```\n'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`
\n:- Hello\n
\n`); - }); -}); From 80564dd8dbde43f34282f0795334e41beec0e751 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Tue, 11 Feb 2025 15:01:20 -0600 Subject: [PATCH 2/4] Remove relocated tests from executiomn --- .circleci/config.yml | 3 --- package.json | 1 - 2 files changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c195df81c..2025e8fe7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -73,9 +73,6 @@ jobs: - run: name: Test - Non-Breaking Spaces command: npm run test:non-breaking-spaces - - run: - name: Test - Paragraph Justification - command: npm run test:paragraph-justification - run: name: Test - Variables command: npm run test:variables diff --git a/package.json b/package.json index 8c343833d..b93fe21f2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "test:definition-lists": "jest tests/markdown/definition-lists.test.js --verbose --noStackTrace", "test:hard-breaks": "jest tests/markdown/hard-breaks.test.js --verbose --noStackTrace", "test:non-breaking-spaces": "jest tests/markdown/non-breaking-spaces.test.js --verbose --noStackTrace", - "test:paragraph-justification": "jest tests/markdown/paragraph-justification.test.js --verbose --noStackTrace", "test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace", "test:route": "jest tests/routes/static-pages.test.js --verbose", "test:safehtml": "jest tests/html/safeHTML.test.js --verbose", From f3315d654e394635a6a0dc073c3ed3a52452faa6 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 21 Feb 2025 14:37:33 -0500 Subject: [PATCH 3/4] tabs to spaces --- shared/naturalcrit/markdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index e9ea49d46..1d0730d4d 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -7,7 +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 MarkedJustifiedParagraphs from 'marked-justified-paragraphs'; +import MarkedJustifiedParagraphs from 'marked-justified-paragraphs'; //Icon fonts included so they can appear in emoji autosuggest dropdown import diceFont from '../../themes/fonts/iconFonts/diceFont.js'; From 519da0a5c033480dda34f96b5a5bd56e8d91faef Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 14 Apr 2025 16:44:25 -0400 Subject: [PATCH 4/4] Remove incorrect extension calls --- shared/naturalcrit/markdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index e00bca205..a9740652b 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -765,8 +765,8 @@ const tableTerminators = [ ]; Marked.use(MarkedVariables()); -Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, - nonbreakingSpaces, mustacheSpans, mustacheDivs, mustacheInjectInline] }); +Marked.use({ extensions : [definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, + mustacheSpans, mustacheDivs, mustacheInjectInline] }); Marked.use(mustacheInjectBlock); Marked.use(MarkedAlignedParagraphs()); Marked.use(MarkedSubSuperText());