From 796cf98eddd075f53c3e6f3366045a1db64b5d8c Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 26 Aug 2026 23:06:22 +0800 Subject: [PATCH 1/2] Update centertext plugin to use negative sentinel markers --- .../plugins/markdown-it-center-text.ts | 17 +++++++++++------ .../plugins/markdown-it-center-text.test.ts | 12 ++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts b/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts index 23e5d6ba14..754ef01c61 100644 --- a/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts +++ b/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts @@ -28,6 +28,11 @@ import MarkdownIt from 'markdown-it'; import StateInline from 'markdown-it/lib/rules_inline/state_inline'; +// Delimiter markers are non-negative character codes, so negative sentinels +// used not to collide with markers used by other inline rules +const CENTERTEXT_OPEN_MARKER = -1; +const CENTERTEXT_CLOSE_MARKER = -2; + /** * A markdown-it plugin to center text using the syntax ->text<- */ @@ -48,7 +53,7 @@ export function centertext_plugin(md: MarkdownIt): void { token = state.push('text', '', 0); token.content = '->'; state.delimiters.push({ - marker: 45, // CHANGED: Use character code 45 instead of string '->' + marker: CENTERTEXT_OPEN_MARKER, jump: 0, token: state.tokens.length - 1, length: 2, @@ -64,7 +69,7 @@ export function centertext_plugin(md: MarkdownIt): void { token = state.push('text', '', 0); token.content = '<-'; state.delimiters.push({ - marker: 60, // CHANGED: Use character code 60 instead of string '<-' + marker: CENTERTEXT_CLOSE_MARKER, jump: 0, token: state.tokens.length - 1, length: 2, @@ -94,9 +99,9 @@ export function centertext_plugin(md: MarkdownIt): void { for (i = 0; i < max; i++) { delim = delimiters[i]; - if (delim.marker === 45/* - */) { + if (delim.marker === CENTERTEXT_OPEN_MARKER) { foundStart = true; - } else if (delim.marker === 60/* < */) { + } else if (delim.marker === CENTERTEXT_CLOSE_MARKER) { foundEnd = true; } } @@ -104,7 +109,7 @@ export function centertext_plugin(md: MarkdownIt): void { for (i = 0; i < max; i++) { delim = delimiters[i]; - if (delim.marker === 45/* - */) { + if (delim.marker === CENTERTEXT_OPEN_MARKER) { foundStart = true; token = state.tokens[delim.token]; token.type = 'centertext_open'; @@ -113,7 +118,7 @@ export function centertext_plugin(md: MarkdownIt): void { token.markup = '->'; token.content = ''; token.attrs = [['class', 'text-center']]; - } else if (delim.marker === 60/* < */) { + } else if (delim.marker === CENTERTEXT_CLOSE_MARKER) { if (foundStart) { token = state.tokens[delim.token]; token.type = 'centertext_close'; diff --git a/packages/core/test/unit/lib/markdown-it/plugins/markdown-it-center-text.test.ts b/packages/core/test/unit/lib/markdown-it/plugins/markdown-it-center-text.test.ts index cb1373c453..b5e2cc2290 100644 --- a/packages/core/test/unit/lib/markdown-it/plugins/markdown-it-center-text.test.ts +++ b/packages/core/test/unit/lib/markdown-it/plugins/markdown-it-center-text.test.ts @@ -1,6 +1,9 @@ import markdownIt from 'markdown-it'; import { centertext_plugin } from '../../../../../src/lib/markdown-it/plugins/markdown-it-center-text.js'; +import { + createDoubleDelimiterInlineRule, +} from '../../../../../src/lib/markdown-it/plugins/markdown-it-double-delimiter.js'; describe('markdown-it-center-text plugin', () => { let md: markdownIt; @@ -72,4 +75,13 @@ describe('markdown-it-center-text plugin', () => { // which is possibly not schematicallly correct expect(result).toContain('reversed'); }); + + test('should not collide with the "--" small-text rule sharing the same "-" character', () => { + const mdWithSmall = markdownIt(); + mdWithSmall.use(createDoubleDelimiterInlineRule('--', 'small', 'emphasis')); + mdWithSmall.use(centertext_plugin); + + expect(mdWithSmall.renderInline('--Small--, ->Center-align<-')) + .toBe('Small,
Center-align
'); + }); }); From 8b6f0793a4094bb98fde0f53792bfbef2c6b92be Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 27 Aug 2026 08:19:32 +0800 Subject: [PATCH 2/2] Updtate docs --- .../core/src/lib/markdown-it/plugins/markdown-it-center-text.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts b/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts index 754ef01c61..3df8a619f1 100644 --- a/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts +++ b/packages/core/src/lib/markdown-it/plugins/markdown-it-center-text.ts @@ -29,7 +29,7 @@ import MarkdownIt from 'markdown-it'; import StateInline from 'markdown-it/lib/rules_inline/state_inline'; // Delimiter markers are non-negative character codes, so negative sentinels -// used not to collide with markers used by other inline rules +// used not to collide with markers used by other inline rules. const CENTERTEXT_OPEN_MARKER = -1; const CENTERTEXT_CLOSE_MARKER = -2;