;
65 | };
66 |
--------------------------------------------------------------------------------
/test/fixtures/multiple-html/input.html:
--------------------------------------------------------------------------------
1 | ::: code-group labels=[npm, pnpm]
2 |
3 | npm install rehype-code-group
4 |
5 |
6 | pnpm add rehype-code-group
7 |
8 | :::
9 |
10 |
Another code group
11 |
::: code-group labels=[npm, pnpm, yarn]
12 |
13 | npm install rehype-code-group
14 |
15 |
16 | pnpm add rehype-code-group
17 |
18 |
19 | yarn add rehype-code-group
20 |
21 |
:::
22 |
23 |
--------------------------------------------------------------------------------
/test/fixtures/multiple-html/output.html:
--------------------------------------------------------------------------------
1 | npm install rehype-code-group
64 |
pnpm add rehype-code-group
65 |
Another code group
npm install rehype-code-group
66 |
pnpm add rehype-code-group
67 |
yarn add rehype-code-group
68 |
--------------------------------------------------------------------------------
/test/fixtures/multiple-md/input.md:
--------------------------------------------------------------------------------
1 | ::: code-group labels=[npm, pnpm]
2 |
3 | ```bash
4 | npm install rehype-code-group
5 | ```
6 |
7 | ```bash
8 | pnpm add rehype-code-group
9 | ```
10 |
11 | :::
12 |
13 | ::: code-group labels=[npm, pnpm, yarn]
14 |
15 | ```bash
16 | npm install rehype-code-group
17 | ```
18 |
19 | ```bash
20 | pnpm add rehype-code-group
21 | ```
22 |
23 | ```bash
24 | yarn add rehype-code-group
25 | ```
26 |
27 | :::
--------------------------------------------------------------------------------
/test/fixtures/multiple-md/output.html:
--------------------------------------------------------------------------------
1 | npm install rehype-code-group
64 |
pnpm add rehype-code-group
65 |
npm install rehype-code-group
66 |
pnpm add rehype-code-group
67 |
yarn add rehype-code-group
68 |
--------------------------------------------------------------------------------
/test/fixtures/single-html/input.html:
--------------------------------------------------------------------------------
1 | ::: code-group labels=[npm, pnpm]
2 |
3 | npm install rehype-code-group
4 |
5 |
6 | pnpm add rehype-code-group
7 |
8 | :::
9 |
--------------------------------------------------------------------------------
/test/fixtures/single-html/output.html:
--------------------------------------------------------------------------------
1 | npm install rehype-code-group
64 |
pnpm add rehype-code-group
65 |
--------------------------------------------------------------------------------
/test/fixtures/single-md/input.md:
--------------------------------------------------------------------------------
1 | ::: code-group labels=[npm, pnpm, yarn]
2 |
3 | ```bash
4 | npm install rehype-code-group
5 | ```
6 |
7 | ```bash
8 | pnpm add rehype-code-group
9 | ```
10 |
11 | ```bash
12 | yarn add rehype-code-group
13 | ```
14 |
15 | :::
--------------------------------------------------------------------------------
/test/fixtures/single-md/output.html:
--------------------------------------------------------------------------------
1 | npm install rehype-code-group
64 |
pnpm add rehype-code-group
65 |
yarn add rehype-code-group
66 |
--------------------------------------------------------------------------------
/test/index.test.ts:
--------------------------------------------------------------------------------
1 | import fs from "node:fs";
2 | import path from "node:path";
3 | import { describe, expect, it } from "vitest";
4 | import { processHtml } from "../scripts/processHtml";
5 | import { processMarkdown } from "../scripts/processMarkdown";
6 |
7 | const fixturesDir = path.join(__dirname, "fixtures");
8 |
9 | const readFixture = async (
10 | testCase: string,
11 | fileName: string,
12 | ): string | null => {
13 | try {
14 | const filePath = path.join(fixturesDir, testCase, fileName);
15 | return fs.readFileSync(filePath, "utf8");
16 | } catch (err) {
17 | return null;
18 | }
19 | };
20 |
21 | describe("rehypeCodeGroup", async () => {
22 | const testCases = await fs.readdirSync(fixturesDir, { withFileTypes: true });
23 | const directories = testCases
24 | .filter((dirent) => dirent.isDirectory())
25 | .map((dirent) => dirent.name);
26 |
27 | for (const testCase of directories) {
28 | it(`should process ${testCase} correctly`, async () => {
29 | const isHtml = testCase.split("-")[1] === "html";
30 |
31 | const expectedOutput = await readFixture(testCase, "output.html");
32 |
33 | if (expectedOutput === null) {
34 | throw new Error(`No output found for ${testCase}`);
35 | }
36 |
37 | let output: string;
38 | if (isHtml) {
39 | const inputHtml = await readFixture(testCase, "input.html");
40 | output = await processHtml(inputHtml, {});
41 | } else {
42 | const inputMd = await readFixture(testCase, "input.md");
43 | output = await processMarkdown(inputMd, {});
44 | }
45 |
46 | expect(output).toBe(expectedOutput);
47 | });
48 | }
49 | });
50 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | // Enable latest features
4 | "lib": ["ESNext", "DOM"],
5 | "target": "ESNext",
6 | "module": "NodeNext",
7 | "moduleDetection": "force",
8 | "verbatimModuleSyntax": true,
9 | // Best practices
10 | "strict": true,
11 | "skipLibCheck": true,
12 | "noFallthroughCasesInSwitch": true,
13 | "esModuleInterop": true,
14 | // Some stricter flags (disabled by default)
15 | "noUnusedLocals": true,
16 | "noUnusedParameters": true,
17 | "noPropertyAccessFromIndexSignature": true,
18 |
19 | "rootDir": "./src",
20 | "outDir": "./dist",
21 | "forceConsistentCasingInFileNames": true,
22 |
23 | "declaration": true,
24 | "declarationMap": true,
25 | "types": ["vitest/globals"]
26 | },
27 | "include": ["src"],
28 | "exclude": ["node_modules", "dist"]
29 | }
30 |
--------------------------------------------------------------------------------
/vitest.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vitest/config";
2 |
3 | export default defineConfig({
4 | test: {
5 | include: ["test/**/*.test.ts"],
6 | coverage: {
7 | provider: "v8",
8 | include: ["src/**/*.ts"],
9 | exclude: ["src/options.ts"],
10 | reporter: ["text", "json"],
11 | },
12 | },
13 | });
14 |
--------------------------------------------------------------------------------