Skip to content

Commit

Permalink
📦 Updates to myst
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Nov 23, 2023
1 parent 335c7d5 commit 53cdb69
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 201 deletions.
315 changes: 168 additions & 147 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.14",
"myst-config": "^1.1.14",
"myst-spec-ext": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"myst-spec-ext": "^1.1.15",
"nbtx": "^0.2.3",
"unist-util-select": "^4.0.3"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/jupyter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"@scienceicons/react": "^0.0.6",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"myst-common": "^1.1.14",
"myst-config": "^1.1.14",
"myst-frontmatter": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"myst-frontmatter": "^1.1.15",
"myst-spec": "^0.0.4",
"myst-spec-ext": "^1.1.14",
"myst-spec-ext": "^1.1.15",
"myst-to-react": "^0.5.14",
"nanoid": "^4.0.2",
"nbtx": "^0.2.3",
Expand Down
18 changes: 9 additions & 9 deletions packages/myst-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
"@heroicons/react": "^2.0.18",
"classnames": "^2.3.2",
"js-yaml": "^4.1.0",
"myst-common": "^1.1.14",
"myst-config": "^1.1.14",
"myst-directives": "^1.0.15",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"myst-directives": "^1.0.16",
"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.14",
"myst-parser": "^1.0.15",
"myst-frontmatter": "^1.1.15",
"myst-parser": "^1.0.16",
"myst-spec": "^0.0.4",
"myst-to-docx": "^1.0.7",
"myst-to-html": "^1.0.15",
"myst-to-jats": "^1.0.17",
"myst-to-html": "^1.0.16",
"myst-to-jats": "^1.0.18",
"myst-to-react": "^0.5.14",
"myst-to-tex": "^1.0.13",
"myst-to-tex": "^1.0.14",
"myst-to-typst": "^0.0.6",
"myst-transforms": "^1.1.12",
"myst-transforms": "^1.1.13",
"unified": "^10.1.2",
"unist-util-visit": "^4.1.2",
"vfile": "^5.3.7",
Expand Down
120 changes: 94 additions & 26 deletions packages/myst-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ async function parse(
// For the mdast that we show, duplicate, strip positions and dump to yaml
// Also run some of the transforms, like the links
const mdastPre = JSON.parse(JSON.stringify(mdast));
unified().use(linksPlugin, { transformers: linkTransforms }).runSync(mdastPre);
visit(mdastPre, (n) => delete n.position);
const mdastString = yaml.dump(mdastPre);
const htmlString = mystToHtml(mdastPre);
unified().use(linksPlugin, { transformers: linkTransforms }).runSync(mdast);
const htmlString = mystToHtml(mdast);
const references = {
cite: { order: [], data: {} },
footnotes: {},
Expand All @@ -124,6 +123,12 @@ async function parse(
numbering: frontmatter.numbering ?? defaultFrontmatter?.numbering,
file,
});
visit(mdast, (n) => {
// Before we put in the citation render, we can mark them as errors
if (n.type === 'cite') {
n.error = true;
}
});
unified()
.use(basicTransformationsPlugin, { parser: parseMyst })
.use(mathPlugin, { macros: frontmatter?.math ?? {} }) // This must happen before enumeration, as it can add labels
Expand All @@ -136,6 +141,11 @@ async function parse(
.use(resolveReferencesPlugin, { state })
.use(keysPlugin)
.runSync(mdast as any, file);
const mdastPost = JSON.parse(JSON.stringify(mdast));
visit(mdastPost, (n) => {
delete n.position;
delete n.key;
});
const texFile = new VFile();
const tex = unified()
.use(mystToTex, { references })
Expand Down Expand Up @@ -166,7 +176,8 @@ async function parse(

return {
frontmatter,
yaml: mdastString,
mdastPre,
mdastPost,
references: { ...references, article: mdast } as References,
html: htmlString,
tex: tex.value,
Expand Down Expand Up @@ -200,7 +211,8 @@ export function MySTRenderer({
const [text, setText] = useState<string>(value.trim());
const [references, setReferences] = useState<References>({});
const [frontmatter, setFrontmatter] = useState<PageFrontmatter>({});
const [mdastYaml, setYaml] = useState<string>('Loading...');
const [mdastPre, setMdastPre] = useState<any>('Loading...');
const [mdastPost, setMdastPost] = useState<any>('Loading...');
const [html, setHtml] = useState<string>('Loading...');
const [tex, setTex] = useState<string>('Loading...');
const [texWarnings, setTexWarnings] = useState<VFileMessage[]>([]);
Expand All @@ -210,6 +222,8 @@ export function MySTRenderer({
const [jatsWarnings, setJatsWarnings] = useState<VFileMessage[]>([]);
const [warnings, setWarnings] = useState<VFileMessage[]>([]);
const [previewType, setPreviewType] = useState('DEMO');
const [astLang, setAstLang] = useState('yaml');
const [astStage, setAstStage] = useState('pre');

useEffect(() => {
const ref = { current: true };
Expand All @@ -220,7 +234,8 @@ export function MySTRenderer({
).then((result) => {
if (!ref.current) return;
setFrontmatter(result.frontmatter);
setYaml(result.yaml);
setMdastPre(result.mdastPre);
setMdastPost(result.mdastPost);
setReferences(result.references);
setHtml(result.html);
setTex(result.tex);
Expand Down Expand Up @@ -274,26 +289,64 @@ export function MySTRenderer({
break;
}
const demoMenu = (
<div className="self-center text-sm border cursor-pointer dark:border-slate-600">
{['DEMO', 'AST', 'HTML', 'LaTeX', 'Typst', 'JATS', 'DOCX'].map((show) => (
<button
key={show}
className={classnames('px-2 py-1', {
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700':
previewType !== show,
'bg-blue-800 text-white': previewType === show,
})}
title={`Show the ${show}`}
aria-label={`Show the ${show}`}
aria-pressed={previewType === show ? 'true' : 'false'}
onClick={() => setPreviewType(show)}
>
{show}
</button>
))}
</div>
<>
<div className="self-center text-sm border cursor-pointer dark:border-slate-600">
{['DEMO', 'AST', 'HTML', 'LaTeX', 'Typst', 'JATS', 'DOCX'].map((show) => (
<button
key={show}
className={classnames('px-2 py-1', {
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700':
previewType !== show,
'bg-blue-800 text-white': previewType === show,
})}
title={`Show the ${show}`}
aria-label={`Show the ${show}`}
aria-pressed={previewType === show ? 'true' : 'false'}
onClick={() => setPreviewType(show)}
>
{show}
</button>
))}
</div>
{previewType === 'AST' && (
<div className="self-center text-sm border cursor-pointer w-fit dark:border-slate-600">
{['yaml', 'json'].map((show) => (
<button
key={show}
className={classnames('px-2 py-1', {
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700':
astLang !== show,
'bg-blue-800 text-white': astLang === show,
})}
title={`Show the AST as ${show.toUpperCase()}`}
aria-pressed={astLang === show ? 'true' : 'false'}
onClick={() => setAstLang(show)}
>
{show.toUpperCase()}
</button>
))}
{['pre', 'post'].map((show) => (
<button
key={show}
className={classnames('px-2 py-1', {
'bg-white hover:bg-slate-200 dark:bg-slate-500 dark:hover:bg-slate-700':
astStage !== show,
'bg-blue-800 text-white': astStage === show,
})}
title={`Show the AST Stage ${show.toUpperCase()}`}
aria-pressed={astStage === show ? 'true' : 'false'}
onClick={() => setAstStage(show)}
>
{show.toUpperCase()}
</button>
))}
</div>
)}
</>
);

const mdastStage = astStage === 'pre' ? mdastPre : mdastPost;

return (
<figure
className={classnames(
Expand Down Expand Up @@ -335,7 +388,13 @@ export function MySTRenderer({
})}
>
{!column && <div className="absolute top-0 left-0">{demoMenu}</div>}
<div className={classnames('px-6 pb-6', { 'pt-[40px]': !column, 'pt-4': column })}>
<div
className={classnames('px-6 pb-6', {
'pt-[40px]': !column && previewType !== 'AST',
'pt-[80px]': !column && previewType === 'AST',
'pt-4': column,
})}
>
{previewType === 'DEMO' && (
<>
<ReferencesProvider references={references} frontmatter={frontmatter}>
Expand All @@ -344,7 +403,16 @@ export function MySTRenderer({
</ReferencesProvider>
</>
)}
{previewType === 'AST' && <CodeBlock lang="yaml" value={mdastYaml} showCopy={false} />}
{previewType === 'AST' && (
<>
<CodeBlock
lang={astLang}
value={
astLang === 'yaml' ? yaml.dump(mdastStage) : JSON.stringify(mdastStage, null, 2)
}
/>
</>
)}
{previewType === 'HTML' && <CodeBlock lang="xml" value={html} showCopy={false} />}
{previewType === 'LaTeX' && <CodeBlock lang="latex" value={tex} showCopy={false} />}
{previewType === 'Typst' && <CodeBlock lang="typst" value={typst} showCopy={false} />}
Expand Down
4 changes: 2 additions & 2 deletions packages/myst-to-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@radix-ui/react-hover-card": "^1.0.6",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"myst-common": "^1.1.14",
"myst-config": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"myst-spec": "^0.0.4",
"nanoid": "^4.0.2",
"react-syntax-highlighter": "^15.5.0",
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.14",
"myst-config": "^1.1.14",
"myst-frontmatter": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"myst-frontmatter": "^1.1.15",
"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.14",
"myst-config": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"myst-demo": "^0.5.14",
"myst-spec-ext": "^1.1.14",
"myst-spec-ext": "^1.1.15",
"myst-to-react": "^0.5.14",
"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.14",
"myst-config": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"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.14",
"myst-config": "^1.1.14",
"myst-common": "^1.1.15",
"myst-config": "^1.1.15",
"node-fetch": "^2.6.11",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down

0 comments on commit 53cdb69

Please sign in to comment.