Skip to content

Commit

Permalink
🐛 Show citations with an error (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Feb 22, 2023
1 parent 270dc61 commit 35226db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/citations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Plugin } from 'unified';
import type { Root } from 'myst-spec';
import type { GenericNode } from 'myst-common';
import { selectAll } from 'unist-util-select';

/**
* Add fake children to the citations
*/
export async function addCiteChildrenTransform(tree: Root): Promise<void> {
const links = selectAll('cite', tree) as GenericNode[];
links.forEach(async cite => {
if (cite.children && cite.children.length > 0) return;
cite.error = true;
cite.children = [{ type: 'text', value: cite.label }];
});
}

export const addCiteChildrenPlugin: Plugin<[], Root, Root> = () => tree => {
addCiteChildrenTransform(tree);
};
2 changes: 2 additions & 0 deletions src/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { StaticNotebook } from '@jupyterlab/notebook';
import { getCellList } from './utils';
import { imageUrlSourceTransform } from './images';
import { internalLinksPlugin } from './links';
import { addCiteChildrenPlugin } from './citations';

const evalRole: RoleSpec = {
name: 'eval',
Expand Down Expand Up @@ -125,6 +126,7 @@ export function parseContent(
.use(footnotesPlugin, { references })
.use(resolveReferencesPlugin, { state })
.use(internalLinksPlugin, { notebook })
.use(addCiteChildrenPlugin)
.use(keysPlugin)
.runSync(mdast as any, file);

Expand Down

0 comments on commit 35226db

Please sign in to comment.