From e0cd84506dad76cc1197ad1d287830c62c51bd29 Mon Sep 17 00:00:00 2001 From: CanisMinor Date: Thu, 16 Nov 2023 15:03:24 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20new=20function=20"rem?= =?UTF-8?q?arkGfmHighlight"=20for=20modifying=20"blockquote"=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces a new function called "remarkGfmHighlight" in a TypeScript file. The function utilizes the "visit" function to traverse a syntax tree and make modifications to specific nodes. In this case, it targets "blockquote" nodes and checks for "strong" nodes within them. If the starting column position of the "strong" node is 3, it further processes the node. It then compares the text value of the "strong" node with a predefined set of values ('Note', 'Tip', 'Important', 'Warning', 'Caution'). If there is a match, the "strong" node is replaced with a "text" node, and the value of the "text" node is set to a corresponding value from the "gfmHighlight" array. The changes are made to enhance the functionality of the code by adding support for modifying "blockquote" nodes based on specific conditions. --- src/remarklint/remarkGfmHighlight.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/remarklint/remarkGfmHighlight.ts b/src/remarklint/remarkGfmHighlight.ts index 8f89b22..ff620b4 100644 --- a/src/remarklint/remarkGfmHighlight.ts +++ b/src/remarklint/remarkGfmHighlight.ts @@ -12,16 +12,13 @@ export function remarkGfmHighlight() { visit(tree, 'blockquote', (node: any) => { visit(node.children[0], 'strong', (subnode: any) => { if (subnode.position.start.column !== 3) return; - let value: string; visit(subnode, 'text', (textnode: any) => { - if (['Note', 'Tip', 'Important', 'Warning', 'Caution'].includes(textnode.value)) { - for (const item of gfmHighlight) { - if (item.from === textnode.value) value = item.to; - } - } - if (value) { + if (!['Note', 'Tip', 'Important', 'Warning', 'Caution'].includes(textnode.value)) return; + for (const item of gfmHighlight) { + if (item.from !== textnode.value) continue; subnode.type = 'text'; - subnode.value = value; + subnode.value = item.to; + return; } }); });