Skip to content

Commit

Permalink
✨ feat: Add function to highlight specific blockquote nodes in Markdown
Browse files Browse the repository at this point in the history
This commit introduces a new function called "remarkGfmHighlight" that utilizes the "unist-util-visit" library to visit and manipulate a Markdown tree. The function searches for "blockquote" nodes and within those nodes, it checks for the first "strong" node. If the starting column of the "strong" node is 3, it checks the text content and assigns a corresponding value from the "gfmHighlight" array to the "value" variable.

Changes Made:
- Added "remarkGfmHighlight" function to highlight specific blockquote nodes in Markdown.
  • Loading branch information
canisminor1990 committed Nov 16, 2023
1 parent 6ebe26a commit a17a894
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/remarklint/remarkGfmHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export function remarkGfmHighlight() {
return async (tree: any) => {
const { visit } = await import('unist-util-visit');
visit(tree, 'blockquote', (node: any) => {
visit(node, 'strong', (subnode: any) => {
let value = '';

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 (item.from === textnode.value) value = item.to;
}
}
if (value) {
Expand Down

0 comments on commit a17a894

Please sign in to comment.