diff --git a/package.json b/package.json index ade184b..9a7f9ba 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,13 @@ "@types/node": "^22.0.0", "c8": "^10.0.0", "prettier": "^3.0.0", - "rehype": "^13.0.0", + "rehype-parse": "^9.0.0", + "rehype-stringify": "^10.0.0", "remark-cli": "^12.0.0", "remark-preset-wooorm": "^11.0.0", "type-coverage": "^2.0.0", "typescript": "^5.0.0", + "unified": "^11.0.0", "xo": "^0.60.0" }, "exports": "./index.js", diff --git a/test.js b/test.js index 674fabe..bab417b 100644 --- a/test.js +++ b/test.js @@ -5,8 +5,10 @@ import assert from 'node:assert/strict' import test from 'node:test' import {common} from 'lowlight' -import {rehype} from 'rehype' import rehypeHighlight from 'rehype-highlight' +import rehypeParse from 'rehype-parse' +import rehypeStringify from 'rehype-stringify' +import {unified} from 'unified' test('rehypeHighlight', async function (t) { await t.test('should expose the public api', async function () { @@ -16,9 +18,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should work on empty code', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: true}) + .use(rehypeStringify) .process( ['
'].join('\n')
)
@@ -34,9 +37,10 @@ test('rehypeHighlight', async function (t) {
})
await t.test('should not highlight (no class)', async function () {
- const file = await rehype()
- .data('settings', {fragment: true})
+ const file = await unified()
+ .use(rehypeParse, {fragment: true})
.use(rehypeHighlight)
+ .use(rehypeStringify)
.process(
[
'alert(1)
'
)
@@ -285,9 +299,10 @@ test('rehypeHighlight', async function (t) {
)
await t.test('should not highlight (`nohighlight`)', async function () {
- const file = await rehype()
- .data('settings', {fragment: true})
+ const file = await unified()
+ .use(rehypeParse, {fragment: true})
.use(rehypeHighlight)
+ .use(rehypeStringify)
.process(
[
'def add(a, b):\n return a + b
`)
assert.equal(
@@ -367,9 +385,10 @@ test('rehypeHighlight', async function (t) {
})
await t.test('should support multiple `code`s in a `pre`', async function () {
- const file = await rehype()
- .data('settings', {fragment: true})
- .use(rehypeHighlight).process(`+ const file = await unified() + .use(rehypeParse, {fragment: true}) + .use(rehypeHighlight) + .use(rehypeStringify).process(``) @@ -381,9 +400,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should reprocess exact', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight) + .use(rehypeStringify) .process( [ 'const a = 1;
printf("x")
Hello World!
', @@ -405,11 +425,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should parse custom language', async function () { - const file = await rehype() - .data('settings', {fragment: true}) - .use(rehypeHighlight, { - aliases: {javascript: ['funkyscript']} - }) + const file = await unified() + .use(rehypeParse, {fragment: true}) + .use(rehypeHighlight, {aliases: {javascript: ['funkyscript']}}) + .use(rehypeStringify) .process( '' ) @@ -421,9 +440,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should reprocess exact', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight) + .use(rehypeStringify) .process( [ 'console.log(1)
Hello World!
', @@ -445,9 +465,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should ignore comments', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: true}) + .use(rehypeStringify) .process( [ 'Hello World!
', @@ -467,9 +488,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should support `
` elements', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight) + .use(rehypeStringify) .process( [ 'Hello World!
', @@ -490,9 +512,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should register languages', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {languages: {...common, test: testLang}}) + .use(rehypeStringify) .process( [ 'Hello World!
',