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( ['

Hello World!

', '', '
'].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( [ '

Hello World!

', @@ -56,9 +60,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should highlight (`detect`, no class)', 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!

', @@ -80,9 +85,10 @@ test('rehypeHighlight', async function (t) { await t.test( 'should highlight (detect, no class, subset)', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: true, subset: ['arduino']}) + .use(rehypeStringify) .process( [ '

Hello World!

', @@ -105,9 +111,10 @@ test('rehypeHighlight', async function (t) { await t.test( 'should not highlight (`detect: false`, no class)', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: false}) + .use(rehypeStringify) .process( [ '

Hello World!

', @@ -128,9 +135,10 @@ test('rehypeHighlight', async function (t) { ) await t.test('should highlight (prefix without dash)', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: true, prefix: 'foo'}) + .use(rehypeStringify) .process( [ '

Hello World!

', @@ -150,9 +158,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should highlight (prefix with dash)', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: true, prefix: 'foo-'}) + .use(rehypeStringify) .process( [ '

Hello World!

', @@ -172,9 +181,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should highlight (lang class)', 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!

', @@ -196,9 +206,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should highlight (language class)', 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!

', @@ -220,9 +231,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should highlight (long name)', 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!

', @@ -244,9 +256,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should not highlight (`no-highlight`)', 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!

', @@ -270,9 +283,10 @@ test('rehypeHighlight', async function (t) { await t.test( 'should prefer `no-highlight` over a `language-*` class', 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!

\n
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( [ '

Hello World!

', @@ -309,9 +324,10 @@ test('rehypeHighlight', async function (t) { }) await t.test('should warn on missing languages', 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!

', @@ -329,9 +345,10 @@ test('rehypeHighlight', async function (t) { await t.test( 'should not highlight plainText-ed languages', async function () { - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {plainText: ['js']}) + .use(rehypeStringify) .process( [ '

Hello World!

', @@ -355,9 +372,10 @@ test('rehypeHighlight', async function (t) { await t.test('should not remove contents', async function () { // For some reason this isn’t detected as c++. - const file = await rehype() - .data('settings', {fragment: true}) + const file = await unified() + .use(rehypeParse, {fragment: true}) .use(rehypeHighlight, {detect: true, subset: ['cpp']}) + .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(`
   const a = 1;
   printf("x")
 
`) @@ -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( [ '

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( '
console.log(1)
' ) @@ -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( [ '

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!

',