Skip to content

Commit

Permalink
🔧 Update myst dependencies (#335)
Browse files Browse the repository at this point in the history
Co-authored-by: Franklin Koch <[email protected]>
Co-authored-by: Rowan Cockett <[email protected]>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent bd6bacc commit da31e48
Show file tree
Hide file tree
Showing 11 changed files with 494 additions and 552 deletions.
8 changes: 8 additions & 0 deletions .changeset/itchy-numbers-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@myst-theme/frontmatter': patch
'myst-demo': patch
'@myst-theme/article': patch
'@myst-theme/book': patch
---

Update for latest myst versions
899 changes: 399 additions & 500 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"build": "npm-run-all -l clean -p build:esm"
},
"dependencies": {
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-spec-ext": "^1.1.18",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"myst-spec-ext": "^1.1.31",
"nbtx": "^0.2.3",
"unist-util-select": "^4.0.3"
}
Expand Down
10 changes: 5 additions & 5 deletions packages/jupyter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"jupyterlab-plotly": "^5.18.0",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-frontmatter": "^1.1.18",
"myst-spec": "^0.0.4",
"myst-spec-ext": "^1.1.18",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"myst-frontmatter": "^1.1.31",
"myst-spec": "^0.0.5",
"myst-spec-ext": "^1.1.31",
"myst-to-react": "^0.7.0",
"nanoid": "^4.0.2",
"nbtx": "^0.2.3",
Expand Down
35 changes: 18 additions & 17 deletions packages/myst-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@
"@heroicons/react": "^2.0.18",
"classnames": "^2.3.2",
"js-yaml": "^4.1.0",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-directives": "^1.0.18",
"myst-ext-card": "^1.0.4",
"myst-ext-exercise": "^1.0.4",
"myst-ext-grid": "^1.0.4",
"myst-ext-proof": "^1.0.6",
"myst-ext-tabs": "^1.0.4",
"myst-frontmatter": "^1.1.18",
"myst-parser": "^1.0.18",
"myst-spec": "^0.0.4",
"myst-to-docx": "^1.0.7",
"myst-to-html": "^1.0.18",
"myst-to-jats": "^1.0.19",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"myst-directives": "^1.2.0",
"myst-ext-card": "^1.0.5",
"myst-ext-exercise": "^1.0.5",
"myst-ext-grid": "^1.0.5",
"myst-ext-proof": "^1.0.8",
"myst-ext-tabs": "^1.0.5",
"myst-frontmatter": "^1.1.31",
"myst-parser": "^1.2.0",
"myst-spec": "^0.0.5",
"myst-to-docx": "^1.0.9",
"myst-to-html": "^1.2.0",
"myst-to-jats": "^1.0.24",
"myst-to-react": "^0.7.0",
"myst-to-tex": "^1.0.14",
"myst-to-typst": "^0.0.6",
"myst-transforms": "^1.1.16",
"myst-to-tex": "^1.0.23",
"myst-to-typst": "^0.0.12",
"myst-transforms": "^1.3.1",
"unified": "^10.1.2",
"unist-util-remove": "^4.0.0",
"unist-util-visit": "^4.1.2",
"vfile": "^5.3.7",
"vfile-message": "^3.1.4"
Expand Down
62 changes: 48 additions & 14 deletions packages/myst-demo/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { VFile } from 'vfile';
import type { LatexResult } from 'myst-to-tex'; // Only import the type!!
import type { TypstResult } from 'myst-to-typst'; // Only import the type!!
import { remove } from 'unist-util-remove';
import type { VFileMessage } from 'vfile-message';
import yaml from 'js-yaml';
import type { GenericNode, References } from 'myst-common';
import {
fileError,
RuleId,
type GenericNode,
type GenericParent,
type References,
} from 'myst-common';
import type { Code } from 'myst-spec';
import { SourceFileKind } from 'myst-spec-ext';
import type { DocxResult } from 'myst-to-docx';
import { validatePageFrontmatter } from 'myst-frontmatter';
import type { PageFrontmatter } from 'myst-frontmatter';
import type { NodeRenderer } from '@myst-theme/providers';
import { ReferencesProvider } from '@myst-theme/providers';
import { CopyIcon, CodeBlock, MyST } from 'myst-to-react';
import React, { useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import classnames from 'classnames';
import {
ExclamationTriangleIcon,
Expand Down Expand Up @@ -40,6 +48,36 @@ async function saveDocxFile(filename: string, mdast: any) {
downloadBlob(filename, docxBlob as Blob);
}

/**
* Simpler function than getFrontmatter from myst-transforms
*
* This only strips frontmatter yaml; it does nothing with headings
*/
function getFrontmatter(vfile: VFile, tree: GenericParent) {
const firstParent = tree.children[0]?.type === 'block' ? tree.children[0] : tree;
const firstNode = firstParent.children?.[0] as Code;
let frontmatter: Record<string, any> = {};
const firstIsYaml = firstNode?.type === 'code' && firstNode?.lang === 'yaml';
if (firstIsYaml) {
try {
frontmatter = (yaml.load(firstNode.value) as Record<string, any>) || {};
(firstNode as any).type = '__delete__';
} catch (err) {
fileError(vfile, 'Invalid YAML frontmatter', {
note: (err as Error).message,
ruleId: RuleId.frontmatterIsYaml,
});
}
}
// Handles deleting the block if it is the only element in the block
const possibleNull = remove(tree, '__delete__');
if (possibleNull === null) {
// null is returned if tree itself didn’t pass the test or is cascaded away
remove(tree, { cascade: false }, '__delete__');
}
return frontmatter;
}

async function parse(
text: string,
defaultFrontmatter?: PageFrontmatter,
Expand All @@ -66,7 +104,6 @@ async function parse(
RRIDTransformer,
linksPlugin,
ReferenceState,
getFrontmatter,
abbreviationPlugin,
glossaryPlugin,
joinGatesPlugin,
Expand All @@ -80,7 +117,7 @@ async function parse(
const { tabDirectives } = await import('myst-ext-tabs');
const { proofDirective } = await import('myst-ext-proof');
const { exerciseDirectives } = await import('myst-ext-exercise');
const file = new VFile();
const vfile = new VFile();
const parseMyst = (content: string) =>
mystParse(content, {
markdownit: { linkify: true },
Expand All @@ -92,7 +129,7 @@ async function parse(
...exerciseDirectives,
],
// roles: [reactiveRole],
vfile: file,
vfile,
});
const mdast = parseMyst(text);
const linkTransforms = [
Expand All @@ -110,17 +147,14 @@ async function parse(
cite: { order: [], data: {} },
footnotes: {},
};
const { frontmatter: frontmatterRaw } = getFrontmatter(file, mdast, {
removeYaml: true,
removeHeading: options?.removeHeading ?? false,
});
const frontmatterRaw = getFrontmatter(vfile, mdast);
const frontmatter = validatePageFrontmatter(frontmatterRaw, {
property: 'frontmatter',
messages: {},
});
const state = new ReferenceState({
const state = new ReferenceState('', {
numbering: frontmatter.numbering ?? defaultFrontmatter?.numbering,
file,
vfile,
});
visit(mdast, (n) => {
// Before we put in the citation render, we can mark them as errors
Expand All @@ -131,15 +165,15 @@ async function parse(
unified()
.use(basicTransformationsPlugin, { parser: parseMyst })
.use(mathPlugin, { macros: frontmatter?.math ?? {} }) // This must happen before enumeration, as it can add labels
.use(glossaryPlugin, { state }) // This should be before the enumerate plugins
.use(glossaryPlugin) // This should be before the enumerate plugins
.use(abbreviationPlugin, { abbreviations: frontmatter.abbreviations })
.use(enumerateTargetsPlugin, { state })
.use(linksPlugin, { transformers: linkTransforms })
.use(footnotesPlugin)
.use(joinGatesPlugin)
.use(resolveReferencesPlugin, { state })
.use(keysPlugin)
.runSync(mdast as any, file);
.runSync(mdast as any, vfile);

const mdastPost = JSON.parse(JSON.stringify(mdast));
visit(mdastPost, (n) => {
Expand Down Expand Up @@ -186,7 +220,7 @@ async function parse(
typstWarnings: typstFile.messages,
jats: jats,
jatsWarnings: jatsFile.messages,
warnings: file.messages,
warnings: vfile.messages,
};
}

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 @@ -25,9 +25,9 @@
"@radix-ui/react-hover-card": "^1.0.6",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-spec": "^0.0.4",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"myst-spec": "^0.0.5",
"nanoid": "^4.0.2",
"react-syntax-highlighter": "^15.5.0",
"swr": "^2.1.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"peerDependencies": {
"@types/react": "^16.8 || ^17.0 || ^18.0",
"@types/react-dom": "^16.8 || ^17.0 || ^18.0",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-frontmatter": "^1.1.18",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"myst-frontmatter": "^1.1.31",
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"@radix-ui/react-collapsible": "^1.0.3",
"classnames": "^2.3.2",
"lodash.throttle": "^4.1.1",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"myst-demo": "^0.7.0",
"myst-spec-ext": "^1.1.18",
"myst-spec-ext": "^1.1.31",
"myst-to-react": "^0.7.0",
"nbtx": "^0.2.3",
"node-cache": "^5.1.2",
Expand Down
4 changes: 2 additions & 2 deletions themes/article/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@remix-run/node": "~1.17.0",
"@remix-run/react": "~1.17.0",
"@remix-run/vercel": "~1.17.0",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"node-fetch": "^2.6.11",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
4 changes: 2 additions & 2 deletions themes/book/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@remix-run/node": "~1.17.0",
"@remix-run/react": "~1.17.0",
"@remix-run/vercel": "~1.17.0",
"myst-common": "^1.1.18",
"myst-config": "^1.1.18",
"myst-common": "^1.1.31",
"myst-config": "^1.1.31",
"node-fetch": "^2.6.11",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down

0 comments on commit da31e48

Please sign in to comment.