Skip to content

Commit

Permalink
Add superscript and subscript to known HTML
Browse files Browse the repository at this point in the history
See #418
  • Loading branch information
rowanc1 committed Oct 16, 2023
1 parent 93cf5ae commit f6b10b3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
83 changes: 83 additions & 0 deletions packages/myst-transforms/src/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,87 @@ describe('Test reconstructHtmlTransform', () => {
],
});
});
test('no paragraph when in a paragraph', async () => {
const mdast = {
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'See ',
},
{
type: 'html',
value: '<sup>',
},
{
type: 'text',
value: '[1]',
},
{
type: 'html',
value: '</sup>',
},
{
type: 'text',
value: '.',
},
],
},
],
};
reconstructHtmlTransform(mdast);
expect(mdast).toEqual({
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'See ',
},
{
type: 'html',
value: '<sup>[1]</sup>',
},
{
type: 'text',
value: '.',
},
],
},
],
});
htmlTransform(mdast);
expect(mdast).toEqual({
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'See ',
},
{
type: 'superscript',
children: [
{
type: 'text',
value: '[1]',
},
],
},
{
type: 'text',
value: '.',
},
],
},
],
});
});
});
8 changes: 7 additions & 1 deletion packages/myst-transforms/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ const defaultHtmlToMdastOptions: Record<keyof HtmlTransformOptions, any> = {
figcaption(h: H, node: any) {
return h(node, 'caption', all(h, node));
},
comment(h: any, node: any) {
comment(h: H, node: any) {
// Prevents HTML comments from showing up as text in web
const result = h(node, 'comment');
(result as any).value = node.value;
return result;
},
sup(h: H, node: any) {
return h(node, 'superscript', all(h, node));
},
sub(h: H, node: any) {
return h(node, 'subscript', all(h, node));
},
},
};

Expand Down

0 comments on commit f6b10b3

Please sign in to comment.