Skip to content

Commit

Permalink
🍔 Consume myst-parser and role/directive extensions in myst-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch committed Feb 15, 2023
1 parent c844d87 commit a9fd512
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 976 deletions.
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/myst-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@
"myst-config": "^0.0.9",
"myst-ext-card": "^0.0.1",
"myst-ext-grid": "^0.0.1",
"myst-ext-reactive": "^0.0.1",
"myst-ext-tabs": "^0.0.1",
"myst-frontmatter": "^0.0.8",
"myst-parser": "^0.0.15",
"myst-spec": "^0.0.4",
"myst-templates": "^0.1.6",
"myst-to-docx": "^0.0.10",
"myst-to-tex": "^0.0.15",
"myst-transforms": "^0.0.15",
"mystjs": "^0.0.15",
"nanoid": "^4.0.0",
"nbtx": "^0.2.3",
"node-fetch": "^3.2.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-cli/src/process/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function loadFile(
const content = fs.readFileSync(file).toString();
const { sha256, useCache } = checkCache(cache, content, file);
if (useCache) break;
const mdast = parseMyst(content);
const mdast = parseMyst(session, content, file);
cache.$mdast[file] = {
sha256,
pre: { kind: KINDS.Article, file, mdast },
Expand Down
22 changes: 22 additions & 0 deletions packages/myst-cli/src/process/myst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Root } from 'mdast';
import { mystParse } from 'myst-parser';
import { cardDirective } from 'myst-ext-card';
import { gridDirective } from 'myst-ext-grid';
import { reactiveDirective, reactiveRole } from 'myst-ext-reactive';
import { tabDirectives } from 'myst-ext-tabs';
import { VFile } from 'vfile';
import type { ISession } from '../session';
import { logMessagesFromVFile } from '../utils';

export function parseMyst(session: ISession, content: string, file: string): Root {
const vfile = new VFile();
vfile.path = file;
const parsed = mystParse(content, {
markdownit: { linkify: true },
directives: [cardDirective, gridDirective, reactiveDirective, ...tabDirectives],
roles: [reactiveRole],
vfile,
});
logMessagesFromVFile(session, vfile);
return parsed;
}
Loading

0 comments on commit a9fd512

Please sign in to comment.