Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

mystmd-client

This package starts mystmd, the MyST build tool, with myst start --headless. Then it reads the built pages from the content server that command runs. It also parses MyST with mystmd’s own settings. It holds code that mystmd-lsp and myst-author both need, so they don’t each keep a copy in sync by hand. It is installed from GitHub rather than npm because it’s only needed until mystmd exports these helpers.

Use

npm install mystmd-client@github:myst-contrib/mystmd-client

npm builds it on install with the prepare script. To move a project that uses it to a newer commit, run the same command or npm update mystmd-client, then commit that project’s lock file.

import { parse, parseMyst, directives, roles } from 'mystmd-client/parse';
import { startMyst } from 'mystmd-client/start';
import { contentServer, mystmdMissing, type BuiltPage, type TocEntry } from 'mystmd-client/content-server';

const { tree, frontmatter, messages } = parseMyst(text, { keepTitle: true });

const myst = await startMyst(root, log, ['--execute']); // root holds myst.yml. log and args are optional.
// myst: { url, ready, exited, stop }

const server = contentServer(myst.url);
const pages: BuiltPage[] = await server.pages();
const toc: TocEntry[] = await server.toc();
const stopWatching = server.watch(onReload);

How it works

Use mystmd-client/parse to parse one page with mystmd’s settings and extensions when you can’t wait for a build. Use mystmd-client/start and mystmd-client/content-server when you need mystmd’s full build of a page, including plugins and cross-references. Run the myst CLI yourself when you need a full export or site build.

Develop

npm test runs without mystmd. npm run test:mystmd also starts the real mystmd devDependency and checks its content server. CI runs npm run test:mystmd and npm run typecheck. The docs site is this README. npm run docs:live previews it and npm run docs builds it.

mystmd-lsp and myst-author pin a commit of this package in their lock files. Their myst-common range should match ours, so all three packages use the same tree types.

Interface

parse

start

content-server

The rest is for myst-author alone:

What it needs upstream

This package can be deleted once mystmd exports its own single-page parse, myst start --headless launcher and content-server client. myst-author’s upstream list asks for those exports.