Skip to content

Commit

Permalink
chore: rebuild code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 2, 2021
1 parent fc291b9 commit 69a5607
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"dependencies": {
"unified": "10.1.0"
"unified": "10.1.0",
"unist-util-visit": "4.1.0",
"unist-util-visit-parents": "5.1.0"
},
"devDependencies": {
"@types/jest": "27.0.2",
"jest": "27.2.0",
"rehype": "12.0.0",
"rehype-stringify": "9.0.2",
"rehype-raw": "6.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('rehype-rewrite test case', () => {
.data('settings', { fragment: true })
.use(rehypeRewrite, (node) => {
if(node.type == 'text' && node.value == 'header') {
console.log('node.value:', node.value)
node.value = ''
}
})
Expand Down Expand Up @@ -46,7 +47,7 @@ describe('rehype-rewrite test case', () => {
const expected = `<h1>hello<span> world</span></h1>`
const htmlStr = rehype()
.data('settings', { fragment: true })
.use(rehypeRewrite, (node: any) => {
.use(rehypeRewrite, (node) => {
if (node.type == 'element' && node.tagName == 'h1') {
node.children = [ ...node.children, {
type: 'element',
Expand All @@ -72,7 +73,7 @@ describe('rehype-rewrite test case', () => {
.use(remarkParse)
.use(remark2rehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeRewrite, (node: any) => {
.use(rehypeRewrite, (node) => {
if (node.type == 'element' && node.tagName == 'p') {
node.properties = { ...node.properties, style: 'color:red;' }
}
Expand Down
24 changes: 11 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Plugin, Transformer } from 'unified';
import { Parent, NodeData, Node } from 'unist';
import { visit } from './visit';
import { Plugin } from 'unified';
import { Root, Element } from 'hast';
import { Node, Data } from 'unist';
import { visit } from 'unist-util-visit';

export * from './visit';
export type RehypeRewriteOptions = (node: Node<Data>, index: number | null, parent: Root | Element | null) => void;

export type RehypeRewriteOptions = (node: NodeData<Parent>, index: number, parent: NodeData<Parent>) => void

const remarkRewrite: Plugin<[RehypeRewriteOptions?]> = (handle): Transformer => {
return transformer;
function transformer(tree: Node<NodeData<Parent>>): void {
visit(tree as any, (node: NodeData<Parent>, index: number, parent: NodeData<Parent>) => {
const remarkRewrite: Plugin<[RehypeRewriteOptions?], Root> = (handle) => {
return (tree) => {
visit(tree, (node, index, parent) => {
if (handle && typeof handle === 'function') {
handle(node, index, parent)
handle(node, index, parent);
}
})
});
}
}

export default remarkRewrite
export default remarkRewrite;
19 changes: 0 additions & 19 deletions src/visit.ts

This file was deleted.

0 comments on commit 69a5607

Please sign in to comment.