Skip to content

Commit

Permalink
wip: add tests to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Nov 26, 2024
1 parent cd12e31 commit 03c0e07
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/myst-to-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
"rehype-stringify": "^9.0.3",
"unified": "^10.1.2",
"unist-builder": "^3.0.0",
"unist-util-find-after": "^4.0.0",
"unist-util-remove": "^3.1.0",
"unist-util-select": "^4.0.3",
"unist-util-visit": "^4.1.0",
"unist-util-find-after": "^4.0.0"
"unist-util-visit": "^4.1.0"
},
"devDependencies": {
"hastscript": "^7.0.0"
}
}
2 changes: 2 additions & 0 deletions packages/myst-to-html/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const mdast: Handler = (h, node) => h(node, 'div', { id: node.id });
const mermaid: Handler = (h, node) => h(node, 'div', { class: 'margin' });
const myst: Handler = (h, node) => h(node, 'div', { class: 'margin' });
const output: Handler = (h, node) => h(node, 'div', { class: 'output' });
const keyboard: Handler = (h, node) => h(node, 'kbd', all(h, node));

export const mystToHast: Plugin<[Options?], string, GenericParent> =
(opts) => (tree: GenericParent) => {
Expand Down Expand Up @@ -202,6 +203,7 @@ export const mystToHast: Plugin<[Options?], string, GenericParent> =
mermaid,
myst,
output,
keyboard,
...opts?.handlers,
},
});
Expand Down
16 changes: 16 additions & 0 deletions packages/myst-to-html/tests/schema.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { mystToHast } from '../src/schema';
import { u } from 'unist-builder';
import { h } from 'hastscript';

// @ts-expect-error this
const toHast: (node: any) => any = mystToHast();

describe('mystToHast', () => {
it('Converts a keyboard node to kbd', () => {
const hast = toHast(
u('root', [u('paragraph', [u('keyboard', [u('text', { value: 'Ctrl' })])])]),
);
expect(hast).toStrictEqual(h(null, [h('p', [h('kbd', 'Ctrl')])]));
});
});

0 comments on commit 03c0e07

Please sign in to comment.