Packages
Annotated source
A site installs mdsvex. Its entries are mdsvex, the Vite plugin, and mdsvex/compile, mdsvex/highlight, mdsvex/math, mdsvex/host and the mdsvex/globals types.
The packages below sit under it and install on their own. The entries in these tables are the surface to build on. Anything else they export, a name with a leading underscore or one marked internal, is there for mdsvex and its tools and changes without notice.
Parser and renderer
| package and entry | export | what for |
|---|---|---|
@mdsvex/parse | parse_markdown_svelte(source, options) | a batch parse, into a NodeBuffer |
@mdsvex/parse | PFMParser | an incremental parse, init, feed and finish, or parse for a whole string. It calls an Emitter with what it finds |
@mdsvex/parse | ParseStallError | a parse that stops moving |
@mdsvex/parse/tree-builder | TreeBuilder | the Emitter that builds a NodeBuffer |
@mdsvex/parse/cursor | Cursor | walks a NodeBuffer |
@mdsvex/render | CursorHTMLRenderer | the HTML string renderer compile uses |
@mdsvex/render and @mdsvex/render/Node.svelte | ComponentRenderer and the Node component | renders a buffer live in Svelte, as it grows |
@mdsvex/render/stream | PluginStream, PLUGIN_DATA | runs plugins over a stream, and gives components the plugin data as it changes |
@mdsvex/render/sourcemap | mappings_to_v3 | a v3 source map from the mappings of a compile with sourcemap: true |
- Node kinds are types only.
NodeKind,WireOpandStateKindfrom@mdsvex/parse, andNodeKindandNodeFieldfrom@mdsvex/parse/utils, areconst enums, which have no value at runtime. A named import of one fails in JavaScript, and TypeScript withisolatedModulesreports TS2748. At runtime,string_to_kind('heading')andkind_to_string(kind)from@mdsvex/parse/utilsturn a kind into its number and back. - Parse plugins are written against the types
mdsvexexports, see parse plugins.PLUGINS.mdin@mdsvex/parsehas the whole API. - Source offsets are string indices, in UTF-16 code units, into the source with its line endings made
\n. - The wire format,
WireEmitterandWireTreeBuilder, sends a parse to another process as opcodes. It is not a stable surface yet.WIRE_FORMAT.mddescribes it as it is now.
Editor tools
| package | how it is used | what for |
|---|---|---|
@mdsvex/language-server | the pfm-language-server command, with --stdio | the language server for any editor that speaks LSP. The VS Code and Zed extensions run it |
@mdsvex/typescript-plugin | "plugins": [{ "name": "@mdsvex/typescript-plugin" }] in compilerOptions | lets the TypeScript server read .svx imports in .ts and .svelte files |
@mdsvex/prettier-plugin | a Prettier plugin | formats documents, see Prettier |
@mdsvex/language-core and @mdsvex/source-map are the pieces the language server and the TypeScript plugin are built from, and have no surface of their own to build on. ARCHITECTURE.md explains how they fit together.