Importable runtime-bootstrap primitive — registers
@awacloud/mdon an@awacloud/fwModuleRuntimeand returns lazy accessors, in one call.
Module bootstrapMd | Source packages/front/office/md/src/bootstrap.js | Deps none (a function, not a descriptor — bootstrapMd is a plain export, not something a ModuleRuntime resolves by name) | Worker-safe yes
Import
import { bootstrapMd } from '@awacloud/md/bootstrap.js';
The .js form is the only one published — see the package's exports map.
API
| Member | Type | Description |
|---|---|---|
runtime |
ModuleRuntime |
The runtime bootstrapMd registered on — the one supplied via opts.runtime, or a freshly created one |
resolve |
(name: string) => any |
runtime.resolve(name) |
md |
object (getter) |
Resolved 'md' facade — carries .createMd, see md |
mdFull |
object (getter) |
Resolved 'mdFullBundle' (core + 10 extras), see md-full |
htmlDocument |
object (getter) |
Resolved 'mdHtmlDocument' ({ renderFragment, build }), see document/html-document |
md, mdFull and htmlDocument are lazy getters: nothing is instantiated until accessed — ModuleRuntime#resolve itself resolves lazily, and bootstrapMd never calls it.
Options
| Option | Type | Default | Description |
|---|---|---|---|
runtime |
ModuleRuntime |
a fresh new ModuleRuntime() |
A host runtime to register on. Registration is idempotent — ModuleRuntime.register replaces a same-name/same-version entry, so calling bootstrapMd twice on the same runtime does not throw. |
Passing a runtime that is not a ModuleRuntime (missing .register/.resolve) throws a plain TypeError — not an md/-prefixed error code (see errors).
Examples
Fresh runtime
import { bootstrapMd } from '@awacloud/md/bootstrap.js';
const { md, mdFull } = bootstrapMd();
md.renderHtml('# Hi\n'); // '<h1>Hi</h1>\n'
mdFull.renderHtml('==m==\n'); // contains '<mark>'
Host runtime
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
import { bootstrapMd } from '@awacloud/md/bootstrap.js';
const runtime = new ModuleRuntime();
const { resolve } = bootstrapMd({ runtime });
resolve('mdToc').slugify('A b'); // 'a-b'
Notes
- Registration is idempotent: calling
bootstrapMd({ runtime })twice on the same runtime replaces the same-name/same-version entries rather than throwing. md,mdFullandhtmlDocumentare lazy getters — accessing them is what triggersruntime.resolve, not thebootstrapMd(opts)call itself.mdandmdFullare the same instance:mdFullBundleinstalls the extras on themdinstance the runtime already holds, so readingmdFullalso installs them onmd(readmdalone and it has no extension,md.extensions.lengthis0; after readingmdFullit is10). For an instance that stays core-only, takemd.createMd()before touchingmdFull.src/main.jsstays a manifest (the fourfw_require/modules/extras/bundlearrays, nothing else) —bootstrap.jsis the ONLY member ofsrc/that instantiates anything.
See also
md— the resolved'md'facademd-full— the resolved'mdFullBundle'- Getting started