Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-eggs-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-jats': minor
---

Wrap parenthetical citations in <sup> tag to group citations
24 changes: 7 additions & 17 deletions packages/myst-to-jats/src/transforms/citations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { selectAll } from 'unist-util-select';
import type { GenericNode, GenericParent } from 'myst-common';

/**
* Add parentheses and separator text to citeGroup nodes as children
* Add <sup> tag and separator text to citeGroup with nodes as children
*
* This allows us to simply render children and get all the correct formatting.
*/
Expand All @@ -21,31 +21,21 @@ export function citeGroupTransform(mdast: GenericParent) {
node.children.forEach((child) => {
child.kind = kind;
});
const newChildren: GenericNode[] = [];
if (kind === 'parenthetical') {
newChildren.push({
type: 'text',
value: '(',
});
}
newChildren.push(node.children[0]);
const wrapper: GenericNode = { type: 'superscript', children: [] };
wrapper.children = [];

wrapper.children.push(node.children[0]);
const sep = kind === 'parenthetical' ? ';' : ',';
node.children.slice(1).forEach((child) => {
newChildren.push(
wrapper.children!.push(
{
type: 'text',
value: `${sep} `,
},
child,
);
});
if (kind === 'parenthetical') {
newChildren.push({
type: 'text',
value: ')',
});
}
node.children = newChildren as any[];
node.children = kind == 'parenthetical' ? ([wrapper] as any[]) : wrapper.children;
});
}

Expand Down
Loading