From 99fb7283d4b064d9dfd610c33b38927f302ce462 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 28 Aug 2025 14:02:18 +0800 Subject: [PATCH] feat: add the ability to only parse specific markdown rules --- src/parseExpensiMark.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/parseExpensiMark.ts b/src/parseExpensiMark.ts index 6e14e25b..4419daaa 100644 --- a/src/parseExpensiMark.ts +++ b/src/parseExpensiMark.ts @@ -28,10 +28,11 @@ const MAX_PARSABLE_LENGTH = 4000; type Token = ['TEXT' | 'HTML', string]; type StackItem = {tag: string; children: Array}; -function parseMarkdownToHTML(markdown: string): string { +function parseMarkdownToHTML(markdown: string, filterRules: string[] | undefined): string { const parser = new ExpensiMark(); const html = parser.replace(markdown, { shouldKeepRawInput: true, + filterRules, }); return html as string; } @@ -240,11 +241,11 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, MarkdownRange[]] { const isNative = Platform.OS === 'android' || Platform.OS === 'ios'; -function parseExpensiMark(markdown: string): MarkdownRange[] { +function parseExpensiMark(markdown: string, filterRules?: string[]): MarkdownRange[] { if (markdown.length > MAX_PARSABLE_LENGTH) { return []; } - const html = parseMarkdownToHTML(markdown); + const html = parseMarkdownToHTML(markdown, filterRules); const tokens = parseHTMLToTokens(html); const tree = parseTokensToTree(tokens); const [text, ranges] = parseTreeToTextAndRanges(tree);