Skip to content
QuireKit MSFE
Developer docs
v0.0.0 · Experimental

Export custom nodes to Word, PDF and OFD

Share native content conversion and image rendering, with templates, resource failures, cancellation and Word metadata recovery.

Export adapters read a Markdown snapshot independently of your Vue/React node views. Screen appearance does not enter a file automatically: provide an explicit printable representation. Word, PDF and OFD can share the same extensions. See MD Editor for template selection.

Quire Render and multi-format export

Quire Render is QuireKit's unified rendering engine. Word, PDF and OFD first share semantic node conversion and templates. Word compiles editable DOCX, while PDF/OFD uses Classic pagination and passes each page's content to the corresponding Quire Render backend.

NameResponsibility
qkViewCompose declarative components and resolve their local layout
Quire Display ListRepresent text, paths, images and clipping with QuireDisplayList
Render BackendOutput drawing commands to Canvas, SVG, PDF or OFD

A dedicated layout engine owns document pagination; qkView is one way to produce drawing commands. Markdown export still uses the native-content or image conversions below. Vue/DOM views and qkView interactive controls do not automatically become Word or fixed-layout content. Font, resource and loss handling remain specific to each backend.

Choose a representation

RequirementConverter outputWordPDF / OFD
Callouts, business cards and readable fieldsNative paragraphs, lists, tables, shading and bordersEditable textSelectable text with Classic pagination
Charts or complex graphicsHost-rendered PNG/JPEGImage, optionally with recovery metadataImage, proportionally fitted to available width and height
Recover business data on importVersioned Custom XML metadata with visible contentRestored after validationThis recovery data is not saved
Custom PDF/OFD vector drawing or paginationNo dedicated public API yet—Requires a separate extension to shared layout

PDF/OFD consumes visible LitAST understood by the existing Classic assembly. It does not execute DOCX package passes or install arbitrary third-party Classic schemas. Private XML or an unknown LitAST node type alone cannot make a custom node appear in PDF/OFD.

Conversion lifecycle

  1. parse(source, next) extends parsing only when new Markdown syntax is needed. Existing code fences need no new parser.
  2. prepare(root, context) validates data, acquires resources and creates temporary nodes. Complete asynchronous work here.
  3. addDocx() returns the same docx.codec.node() contributions used by Classic. convertChildren reuses standard conversion; resolveService(markdownExportTemplateService) reads the current resolved template.
  4. Shared presentation constrains tables, images and margins. Word compiles a DOCX; PDF/OFD imports a temporary Classic document for pagination and encoding.

Each modelType has one conversion owner. Avoid claiming every code node and dropping unfamiliar languages. This recipe first converts validated approval-card fences into exampleApprovalCard; ordinary code keeps its standard converter.

A native business card

This is an independent export recipe. It does not install a new editor view or insertion menu. Business data is stored in an ordinary fence:

markdown

The complete implementation uses public package exports. TypeScript consumers need @types/mdast and declare their temporary node with declare module 'mdast'. The card uses containers.note from the selected template. Cell margins use native twips and border width uses eighth-points; the shared export pipeline owns paragraph styles, fonts and pagination.

export-nodes/native.tsts

title and paragraphs contain plain text. Fields, lengths and counts are bounded; invalid input stays as code with a diagnostic. Long cards may split across pages without fixed row heights. For rich content, define a clear child-node contract and use convertChildren; do not interpolate user HTML into XML.

ts

This minimal call uses Latin text. For Chinese or custom fonts, supply embeddable bytes and load matching measurement faces as described in PDF and OFD export. word.data / pdf.data contain download bytes and diagnostics contains the report. The code does not download files or mutate an editor itself.

Reuse the converter for OFD

The /ofd entry of the commercial @quirekit/md-editor-export package shares temporary document preparation and Classic pagination with PDF, then encodes OFD directly. Reuse the markdown, extensions and template above with explicit host fonts:

ts

OFD has no PDF standard fonts: even Latin text requires complete TTF/OTF bytes. The fonts' family, aliases or acceptedSubstitutions should cover the template, and the host must load the same physical faces into the browser before measurement. Unicode subset embedding is the default; fontEmbedding: 'full' embeds complete faces. Non-browser hosts supply textMeasurer and, for equations, rasterizeFormula. OFD returns data, pageCount and diagnostics, with signal and lossPolicy.

Native cards retain text; image nodes and equations remain images. DOCX Custom XML recovery data is not included in OFD. Resource preparation, template width limits, failures and cancellation follow the PDF contract below. See PDF and OFD export for font and reader boundaries.

Image nodes

This recipe renders a progress-chart fence containing a JSON array, such as [25,50,75], into a bounded PNG. It creates an offscreen canvas using an explicit Document, without reading live node views or requesting external resources. The renderer owns image colors and text. To follow an export template, pass its resolved colors and fonts to your own renderer.

export-nodes/image.tsts

Create an AbortController for each export. Pass its signal to resource callbacks and PDF options. Add createProgressChartExtension(document, controller.signal) to the shared extensions, then call exportMarkdownPdf(markdown, { extensions, ownerDocument: document, signal: controller.signal }), and abort when the dialog closes or document changes. A third-party renderer without cancellation support may keep computing; check the signal after it completes and discard stale results. Word hosts should also check the signal before publishing a result.

render returns a valid PNG/JPEG data URI. A null result, invalid data or thrown error retains the original code with code-image-unavailable. Chart text is not individually selectable in PDF. metadata: false disables Word source recovery and reports the loss. PDF only retains the visible image even when the same converter has metadata enabled.

Compose with Mermaid

Multiple createMarkdownDocxCodeImageExtension instances claim the same temporary node type and cannot be registered separately. MD Editor replaces its builtin image converter with a same-name host extension, so registering only progress-chart also replaces its default Mermaid configuration. For both languages, use one languages: ['mermaid', 'progress-chart'] configuration and a dispatching renderer. The host provides both implementations. Renaming an extension does not bypass node ownership.

Install in MD Editor

vue

Export plugins receive options that already contain the selected template and builtin/custom converters, so custom nodes use one converter for Word, PDF and OFD. docx.extensions does not install commercial PDF or OFD capability; formats that are not installed do not appear in the menu. Framework-neutral hosts call the format-specific export functions with the same template and converters explicitly.

Recovery, diagnostics and acceptance

Word import verifies the visible-content fingerprint before the extension validates its payload version and fields. When users edit Word text, images or relevant styles, retain their current content instead of restoring old business data. Missing extensions, invalid metadata and unknown versions also use visible fallback. Recovery restores validated business data; this recipe normalizes JSON formatting and does not promise byte-for-byte fence recovery.

best-effort returns bytes and diagnostics. strict rejects any warning, including rounded-corner approximation, image projection or missing fonts. PDF does not promise source recovery; a Word metadata diagnostic must not be interpreted as evidence that the PDF is reversible.

Before shipping a converter, verify ordinary nodes remain unchanged; failed resources retain content; real DOCX/PDF/OFD files contain visible text or images; long content paginates and nested images fit; templates apply; cancellation cannot download an old result; and Word edits invalidate stale source. The public recipes are exercised directly by their tests rather than copied into a second implementation.

MSFE · QuireKitYour Markdown source stays yours.