Skip to content

Commit

Permalink
✨ feat: Add new function "remarkGfmHighlight" for modifying "blockquo…
Browse files Browse the repository at this point in the history
…te" nodes

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.
  • Loading branch information
canisminor1990 committed Nov 16, 2023
1 parent f4ff36f commit e0cd845
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/remarklint/remarkGfmHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
});
Expand Down

0 comments on commit e0cd845

Please sign in to comment.