UNPKG

myst-cli

Version:
40 lines (39 loc) 1.55 kB
import { mystParse } from 'myst-parser'; import { buttonRole } from 'myst-ext-button'; import { cardDirective } from 'myst-ext-card'; import { gridDirectives } from 'myst-ext-grid'; import { proofDirective } from 'myst-ext-proof'; import { exerciseDirectives } from 'myst-ext-exercise'; import { tabDirectives } from 'myst-ext-tabs'; import { VFile } from 'vfile'; import { logMessagesFromVFile } from '../utils/logging.js'; /** * Parse MyST content using the full suite of built-in directives, roles, and plugins * * @param session session with logging * @param content Markdown content to parse * @param file path to file containing content */ export function parseMyst(session, content, file, opts) { var _a, _b, _c, _d; const vfile = new VFile(); vfile.path = file; const parsed = mystParse(content, { markdownit: { linkify: true }, directives: [ cardDirective, ...gridDirectives, proofDirective, ...exerciseDirectives, ...tabDirectives, ...((_b = (_a = session.plugins) === null || _a === void 0 ? void 0 : _a.directives) !== null && _b !== void 0 ? _b : []), ], extensions: { frontmatter: !(opts === null || opts === void 0 ? void 0 : opts.ignoreFrontmatter), }, roles: [buttonRole, ...((_d = (_c = session.plugins) === null || _c === void 0 ? void 0 : _c.roles) !== null && _d !== void 0 ? _d : [])], vfile, }); logMessagesFromVFile(session, vfile); return parsed; }