Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 Update for footnotes and JATS #44

Merged
merged 1 commit into from
Mar 28, 2023
Merged
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
9 changes: 9 additions & 0 deletions .changeset/rude-bikes-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'myst-to-react': patch
'myst-demo': patch
'@myst-theme/providers': patch
'@myst-theme/jupyter': patch
'@myst-theme/site': patch
---

Update packages to latest versions. Add JATS support.
5 changes: 5 additions & 0 deletions .changeset/tame-mugs-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/jupyter': patch
---

Remove console.log
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@myst-theme/frontmatter": "*",
"myst-frontmatter": "^0.0.9",
"myst-frontmatter": "*",
"myst-to-react": "*"
}
}
3,612 changes: 2,050 additions & 1,562 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/jupyter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"ansi-to-react": "^6.1.6",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"myst-common": "^0.0.14",
"myst-config": "^0.0.10",
"myst-common": "^0.0.15",
"myst-config": "^0.0.11",
"myst-spec": "^0.0.4",
"nanoid": "^4.0.0",
"nbtx": "^0.2.3",
Expand Down
2 changes: 0 additions & 2 deletions packages/jupyter/src/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export function Output(node: GenericNode) {
);
}

console.log('Output', allSafe, outputs);

return (
<figure
key={node.key}
Expand Down
25 changes: 13 additions & 12 deletions packages/myst-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
"@heroicons/react": "^2.0.13",
"classnames": "^2.3.2",
"js-yaml": "^4.1.0",
"myst-common": "^0.0.14",
"myst-config": "^0.0.10",
"myst-ext-card": "^0.0.4",
"myst-ext-grid": "^0.0.4",
"myst-ext-tabs": "^0.0.4",
"myst-frontmatter": "^0.0.9",
"myst-parser": "^0.0.23",
"myst-common": "^0.0.15",
"myst-config": "^0.0.11",
"myst-directives": "^0.0.24",
"myst-ext-card": "^0.0.5",
"myst-ext-grid": "^0.0.5",
"myst-ext-tabs": "^0.0.5",
"myst-frontmatter": "^0.0.10",
"myst-parser": "^0.0.24",
"myst-spec": "^0.0.4",
"myst-to-docx": "^0.0.18",
"myst-to-html": "^0.0.23",
"myst-to-jats": "^0.0.20",
"myst-to-docx": "^0.0.19",
"myst-to-html": "^0.0.24",
"myst-to-jats": "^0.0.21",
"myst-to-react": "^0.1.33",
"myst-to-tex": "^0.0.21",
"myst-transforms": "^0.0.23",
"myst-to-tex": "^0.0.22",
"myst-transforms": "^0.0.24",
"unified": "^10.1.2",
"unist-util-visit": "^4.1.1",
"vfile": "^5.3.6",
Expand Down
22 changes: 14 additions & 8 deletions packages/myst-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ function downloadBlob(filename: string, blob: Blob) {
a.click();
}

async function saveDocxFile(filename: string, mdast: any, footnotes?: any) {
async function saveDocxFile(filename: string, mdast: any) {
const { unified } = await import('unified');
const { mystToDocx, fetchImagesAsBuffers } = await import('myst-to-docx');
// Clone the tree
const tree = JSON.parse(JSON.stringify(mdast));
// Put the footnotes back in
if (footnotes) tree.children.push(...Object.values(footnotes));
const opts = await fetchImagesAsBuffers(tree);
const docxBlob = await (unified()
.use(mystToDocx, opts)
Expand All @@ -44,7 +42,11 @@ async function saveDocxFile(filename: string, mdast: any, footnotes?: any) {
async function parse(
text: string,
defaultFrontmatter?: PageFrontmatter,
options?: { renderers?: Record<string, NodeRenderer>; removeHeading?: boolean },
options?: {
renderers?: Record<string, NodeRenderer>;
removeHeading?: boolean;
jats?: { fullArticle?: boolean };
},
) {
// Ensure that any imports from myst are async and scoped to this function
const { visit } = await import('unist-util-visit');
Expand Down Expand Up @@ -112,7 +114,7 @@ async function parse(
.use(mathPlugin, { macros: frontmatter?.math ?? {} }) // This must happen before enumeration, as it can add labels
.use(enumerateTargetsPlugin, { state })
.use(linksPlugin, { transformers: linkTransforms })
.use(footnotesPlugin, { references })
.use(footnotesPlugin)
.use(resolveReferencesPlugin, { state })
.use(keysPlugin)
.runSync(mdast as any, file);
Expand All @@ -122,7 +124,7 @@ async function parse(
.stringify(mdast as any, texFile).result as LatexResult;
const jatsFile = new VFile();
const jats = unified()
.use(mystToJats, { spaces: 2 })
.use(mystToJats, { spaces: 2, fullArticle: options?.jats?.fullArticle, frontmatter })
.stringify(mdast as any, jatsFile).result as JatsResult;
const content = useParse(mdast as any, options?.renderers);
return {
Expand Down Expand Up @@ -173,7 +175,11 @@ export function MySTRenderer({

useEffect(() => {
const ref = { current: true };
parse(text, { numbering }, { renderers, removeHeading: !!TitleBlock }).then((result) => {
parse(
text,
{ numbering },
{ renderers, removeHeading: !!TitleBlock, jats: { fullArticle: true } },
).then((result) => {
if (!ref.current) return;
setFrontmatter(result.frontmatter);
setYaml(result.yaml);
Expand Down Expand Up @@ -305,7 +311,7 @@ export function MySTRenderer({
<div>
<button
className="rounded border p-3"
onClick={() => saveDocxFile('demo.docx', references.article, references.footnotes)}
onClick={() => saveDocxFile('demo.docx', references.article)}
title={`Download Micorsoft Word`}
aria-label={`Download Micorsoft Word`}
>
Expand Down
6 changes: 3 additions & 3 deletions packages/myst-to-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"@popperjs/core": "^2.11.6",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"myst-common": "^0.0.14",
"myst-config": "^0.0.10",
"myst-common": "^0.0.15",
"myst-config": "^0.0.11",
"myst-spec": "^0.0.4",
"nanoid": "^4.0.0",
"react-popper": "^2.3.0",
"react-syntax-highlighter": "^15.5.0",
"swr": "^1.3.0",
"unist-util-select": "^4.0.1"
"unist-util-select": "^4.0.3"
},
"peerDependencies": {
"@types/react": "^16.8 || ^17.0 || ^18.0",
Expand Down
7 changes: 6 additions & 1 deletion packages/myst-to-react/src/footnotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import type { NodeRenderer } from '@myst-theme/providers';
import { useReferences } from '@myst-theme/providers';
import { useParse } from '.';
import { ClickPopover } from './components/ClickPopover';
import { select } from 'unist-util-select';

export function FootnoteDefinition({ identifier }: { identifier: string }) {
const references = useReferences();
const node = references?.footnotes?.[identifier];
const node =
(references as any)?.footnotes?.[identifier] ??
select(`footnoteDefinition[identifier=${identifier}]`, references?.article);
const children = useParse(node as GenericParent);
return <>{children}</>;
}
Expand All @@ -25,6 +28,8 @@ export const FootnoteReference: NodeRenderer = (node) => {

const FOOTNOTE_RENDERERS = {
footnoteReference: FootnoteReference,
// Do not render the definitions, they get pulled in by a handler
footnoteDefinition: () => null,
};

export default FOOTNOTE_RENDERERS;
6 changes: 3 additions & 3 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"build": "npm-run-all -l clean -p build:cjs build:types"
},
"dependencies": {
"myst-common": "^0.0.14",
"myst-config": "^0.0.10",
"myst-frontmatter": "^0.0.9"
"myst-common": "^0.0.15",
"myst-config": "^0.0.11",
"myst-frontmatter": "^0.0.10"
},
"peerDependencies": {
"@types/react": "^16.8 || ^17.0 || ^18.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@myst-theme/providers": "^0.1.33",
"classnames": "^2.3.2",
"lodash.throttle": "^4.1.1",
"myst-common": "^0.0.14",
"myst-config": "^0.0.10",
"myst-common": "^0.0.15",
"myst-config": "^0.0.11",
"myst-demo": "^0.1.33",
"myst-to-react": "^0.1.33",
"nbtx": "^0.2.3",
Expand Down