Skip to content

Commit

Permalink
Merge pull request #12 from bchainhub/update/fixes-09
Browse files Browse the repository at this point in the history
mdast
  • Loading branch information
rastislavcore authored Apr 27, 2024
2 parents d6ebe4c + d9146ea commit bb441ad
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export default function remarkCorebc(options = {}) {
visit(tree, 'text', (node, index, parent) => {
if (!isTextNode(node) || !parent || typeof index !== 'number')
return;
const parentNode = parent;
let newNodes = [];
let lastIndex = 0;
const matches = extractMatches(node.value, finalOptions);
Expand All @@ -203,7 +202,7 @@ export default function remarkCorebc(options = {}) {
if (lastIndex < node.value.length) {
newNodes.push(makeTextNode(node.value.slice(lastIndex)));
}
parentNode.children.splice(index, 1, ...newNodes);
parent.children.splice(index, 1, ...newNodes);
});
};
return transformer;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-corebc",
"version": "0.2.0",
"version": "0.2.1",
"description": "A Remark plugin to transform Core Blockchain notations into markdown links.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type Node } from 'unist';
import { Parent, Root, RootContent, Text, Link, LinkReference } from 'mdast';
import { Link, LinkReference, Node, Parent, Root, RootContent, Text } from 'mdast';
import { visit } from 'unist-util-visit';
import Ican from '@blockchainhub/ican';

Expand Down Expand Up @@ -270,9 +269,8 @@ export default function remarkCorebc(options: CorebcOptions = {}): (ast: Root) =
};

const transformer = (tree: Root): void => {
visit(tree, 'text', (node: Text, index: number | undefined, parent: Node | undefined) => {
visit(tree, 'text', (node: Text, index: number | undefined, parent: Parent | undefined) => {
if (!isTextNode(node) || !parent || typeof index !== 'number') return;
const parentNode: Parent = parent as Parent;
let newNodes: RootContent[] = [];
let lastIndex = 0;

Expand Down Expand Up @@ -301,7 +299,7 @@ export default function remarkCorebc(options: CorebcOptions = {}): (ast: Root) =
}

// Replace the original node with the new nodes
parentNode.children.splice(index, 1, ...newNodes);
parent.children.splice(index, 1, ...newNodes);
});
};

Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Node } from 'unist';
import { Root } from 'mdast';

declare module 'remark-corebc' {
interface CorebcOptions {
Expand All @@ -16,5 +16,5 @@ declare module 'remark-corebc' {
debug?: boolean;
}

export default function remarkCorebc(options?: CorebcOptions): (ast: Node) => void;
export default function remarkCorebc(options?: CorebcOptions): (ast: Root) => void;
}

0 comments on commit bb441ad

Please sign in to comment.