Reference 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.

package and entryexportwhat for
@mdsvex/parseparse_markdown_svelte(source, options)a batch parse, into a NodeBuffer
@mdsvex/parsePFMParseran incremental parse, init, feed and finish, or parse for a whole string. It calls an Emitter with what it finds
@mdsvex/parseParseStallErrora parse that stops moving
@mdsvex/parse/tree-builderTreeBuilderthe Emitter that builds a NodeBuffer
@mdsvex/parse/cursorCursorwalks a NodeBuffer
@mdsvex/renderCursorHTMLRendererthe HTML string renderer compile uses
@mdsvex/render and @mdsvex/render/Node.svelteComponentRenderer and the Node componentrenders a buffer live in Svelte, as it grows
@mdsvex/render/streamPluginStream, PLUGIN_DATAruns plugins over a stream, and gives components the plugin data as it changes
@mdsvex/render/sourcemapmappings_to_v3a v3 source map from the mappings of a compile with sourcemap: true
  • Node kinds are types only. NodeKind, WireOp and StateKind from @mdsvex/parse, and NodeKind and NodeField from @mdsvex/parse/utils, are const enums, which have no value at runtime. A named import of one fails in JavaScript, and TypeScript with isolatedModules reports TS2748. At runtime, string_to_kind('heading') and kind_to_string(kind) from @mdsvex/parse/utils turn a kind into its number and back.
  • Parse plugins are written against the types mdsvex exports, see parse plugins. PLUGINS.md in @mdsvex/parse has 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, WireEmitter and WireTreeBuilder, sends a parse to another process as opcodes. It is not a stable surface yet. WIRE_FORMAT.md describes it as it is now.

packagehow it is usedwhat for
@mdsvex/language-serverthe pfm-language-server command, with --stdiothe 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 compilerOptionslets the TypeScript server read .svx imports in .ts and .svelte files
@mdsvex/prettier-plugina Prettier pluginformats 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.

mdsvex, markdown with Svelte in it. MIT licence.