rehype-ignore
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,7 +7,19 @@ import { visit } from 'unist-util-visit'; | ||
if (node.type === 'element' || node.type === 'root') { | ||
const start = node.children.findIndex((item) => item.type === 'comment' && item.value === openDelimiter); | ||
const end = node.children.findIndex((item) => item.type === 'comment' && item.value === closeDelimiter); | ||
if (start > -1 && end > -1) { | ||
node.children = node.children.filter((_, idx) => idx < start || idx > end); | ||
} | ||
// const start = node.children.findIndex((item) => item.type === 'comment' && item.value === openDelimiter); | ||
// const end = node.children.findIndex((item) => item.type === 'comment' && item.value === closeDelimiter); | ||
// if (start > -1 && end > -1) { | ||
// node.children = node.children.filter((_, idx) => idx < start || idx > end); | ||
// } | ||
let start = false; | ||
node.children = node.children.filter((item) => { | ||
if (item.type === 'comment' && item.value.trim() === openDelimiter) { | ||
start = true; | ||
return false; | ||
} | ||
if (item.type === 'comment' && item.value.trim() === closeDelimiter) { | ||
start = false; | ||
return false; | ||
} | ||
return !start; | ||
}); | ||
} | ||
@@ -14,0 +26,0 @@ }); |
{ | ||
"name": "rehype-ignore", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Ignore content display via HTML comments, Shown in GitHub readme, excluded in HTML.", | ||
@@ -10,3 +10,3 @@ "homepage": "https://jaywcjlove.github.io/rehype-ignore", | ||
"type": "module", | ||
"main": "lib/index.js", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
@@ -13,0 +13,0 @@ "prepack": "npm run build", |
@@ -123,2 +123,3 @@ rehype-ignore | ||
- [`rehype-rewrite`](https://github.com/jaywcjlove/rehype-rewrite) Rewrite element with rehype. | ||
- [`rehype-video`](https://github.com/jaywcjlove/rehype-video) Add improved video syntax: links to `.mp4` and `.mov` turn into videos. | ||
@@ -125,0 +126,0 @@ - [`rehype-attr`](https://github.com/jaywcjlove/rehype-attr) New syntax to add attributes to Markdown. |
@@ -28,3 +28,3 @@ import { unified } from 'unified'; | ||
.toString() | ||
expect(htmlStr).toEqual(html); | ||
expect(htmlStr).toEqual(''); | ||
}); | ||
@@ -40,3 +40,3 @@ | ||
.toString() | ||
expect(htmlStr).toEqual(html); | ||
expect(htmlStr).toEqual('<h1>header</h1>'); | ||
}); | ||
@@ -52,5 +52,27 @@ | ||
.toString() | ||
expect(htmlStr).toEqual(`<!--rehype:ignore:end-->`); | ||
expect(htmlStr).toEqual(''); | ||
}); | ||
it('rehypeIgnore Markdown test case', async () => { | ||
const html = `# Hello World | ||
<!--rehype:ignore:start-->Hello World<!--rehype:ignore:end--> | ||
Good!`; | ||
const expected = `<h1>Hello World</h1> | ||
<p>Good!</p>`; | ||
const htmlStr = unified() | ||
.use(remarkParse) | ||
.use(remark2rehype, { allowDangerousHtml: true }) | ||
.use(rehypeRaw) | ||
.use(rehypeIgnore, { }) | ||
.use(stringify) | ||
.processSync(html) | ||
.toString() | ||
expect(htmlStr).toEqual(expected); | ||
}); | ||
it('rehypeIgnore test case', async () => { | ||
@@ -63,2 +85,7 @@ const html = `<!--rehype:ignore:start--> | ||
</p> | ||
<!--rehype:ignore:start--> | ||
<h2>header</h2> | ||
<!--rehype:ignore:end--> | ||
<p>Hi</p> | ||
`; | ||
@@ -69,2 +96,5 @@ const expected = ` | ||
</p> | ||
<p>Hi</p> | ||
`; | ||
@@ -79,22 +109,1 @@ const htmlStr = rehype() | ||
}); | ||
it('rehypeIgnore Markdown test case', async () => { | ||
const html = `# Hello World | ||
<!--rehype:ignore:start-->Hello World<!--rehype:ignore:end--> | ||
Good!`; | ||
const expected = `<h1>Hello World</h1> | ||
<p>Good!</p>`; | ||
const htmlStr = unified() | ||
.use(remarkParse) | ||
.use(remark2rehype, { allowDangerousHtml: true }) | ||
.use(rehypeRaw) | ||
.use(rehypeIgnore, { }) | ||
.use(stringify) | ||
.processSync(html) | ||
.toString() | ||
expect(htmlStr).toEqual(expected); | ||
}); |
@@ -21,7 +21,20 @@ import { Plugin } from 'unified'; | ||
if (node.type === 'element' || node.type === 'root') { | ||
const start = node.children.findIndex((item) => item.type === 'comment' && item.value === openDelimiter); | ||
const end = node.children.findIndex((item) => item.type === 'comment' && item.value === closeDelimiter); | ||
if (start > -1 && end > -1) { | ||
node.children = node.children.filter((_, idx) => idx < start || idx > end); | ||
} | ||
// const start = node.children.findIndex((item) => item.type === 'comment' && item.value === openDelimiter); | ||
// const end = node.children.findIndex((item) => item.type === 'comment' && item.value === closeDelimiter); | ||
// if (start > -1 && end > -1) { | ||
// node.children = node.children.filter((_, idx) => idx < start || idx > end); | ||
// } | ||
let start = false; | ||
node.children = node.children.filter((item) => { | ||
if (item.type === 'comment' && item.value.trim() === openDelimiter) { | ||
start = true; | ||
return false | ||
} | ||
if (item.type === 'comment' && item.value.trim() === closeDelimiter) { | ||
start = false; | ||
return false | ||
} | ||
return !start; | ||
}) | ||
} | ||
@@ -28,0 +41,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13396
171
145