Skip to content

Commit

Permalink
type: Fix type errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 2, 2021
1 parent 69a5607 commit 88bee15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('rehype-rewrite test case', () => {
const html = `<h1>header</h1>`;
const expected = `<html><head></head><body style="color:red;"><h1>header</h1></body></html>`
const htmlStr = rehype()
.use(rehypeRewrite, (node: any) => {
.use(rehypeRewrite, (node) => {
if (node.type == 'element' && node.tagName == 'body') {
node.properties = { ...node.properties, style: 'color:red;'}
}
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Plugin } from 'unified';
import { Root, Element } from 'hast';
import { Node, Data } from 'unist';
import { Root, Element, ElementContent } from 'hast';
import { visit } from 'unist-util-visit';

export type RehypeRewriteOptions = (node: Node<Data>, index: number | null, parent: Root | Element | null) => void;
export type RehypeRewriteOptions = (node: ElementContent, index: number | null, parent: Root | Element | null) => void;

const remarkRewrite: Plugin<[RehypeRewriteOptions?], Root> = (handle) => {
return (tree) => {
return (tree: Root) => {
visit(tree, (node, index, parent) => {
if (handle && typeof handle === 'function') {
handle(node, index, parent);
handle(node as ElementContent, index, parent);
}
});
}
Expand Down

0 comments on commit 88bee15

Please sign in to comment.