JSON, Markdown, HTML, DOCX, and PDF
Every format goes through one canonical Document. Codecs decode into it and encode from it; PDF and print draw the pages the editor already laid out. Each codec returns its report or diagnostics beside the result.
JSON
Document.fromJson or DocumentSource.jsonString loads; toJson() or toJsonString() saves. Store referenced fonts and images separately.
DOCX
DocxCodec (vyuh_document_codec_docx) opens and saves Word files. decodeWithReport returns fidelity issues and receipts; encodeWithReport returns a support report. Keep both with your workflow. Browse compatibility.
Markdown
MarkdownCodec (vyuh_document_md_codec) converts CommonMark and GFM in pure Dart. Decode once to get a Document, edit it in the ordinary editor, and encode when you need Markdown again. Keep the diagnostics with the result.
dart
import 'package:vyuh_document_md_codec/vyuh_document_md_codec.dart';
import 'package:vyuh_document/types.dart';
MarkdownDecodeResult importMarkdown(String source) {
return const MarkdownCodec().decode(source, dialect: MarkdownDialect.gfm);
}
MarkdownEncodeResult exportMarkdown(Document document) {
return const MarkdownCodec().encode(document, dialect: MarkdownDialect.gfm);
}
// Edit the imported result.document with the ordinary document editor.
// Save exportMarkdown(controller.document).source when Markdown is needed.
// Keep diagnostics from both conversions alongside the host's file workflow.Mermaid and math syntax register through MarkdownExtensionRegistry; their renderers and editors stay separate from the codec.
HTML
HtmlCodec.encode(document, extensions:, resolveAsset:) returns a body fragment and fidelity diagnostics. Use fullDocument: true for a complete web page. HtmlExtensionRegistry.fromExtensions(installedExtensions) drives the same quotation, code, divider, figure and field contributions used by HTML import and clipboard hosts. Map opaque image ids to public or relative resource URLs with resolveAsset; the codec performs no IO.
The demo offers File → Download → Web page (.html) without waiting for page layout. HTML preserves semantic content and supported styles while the reader reflows it. Missing handlers, unresolved assets and unsupported presentation produce diagnostics. Page regions, notes and review metadata are not part of the body export; canonical JSON remains the lossless storage format.
PDF and print
vyuh_document_codec_pdf paints the complete layout of the current revision, with fonts and assets prepared. Call waitForCurrentExportLayout(...) to wait until every page is ready. Your app saves, downloads or sends the bytes.
Connect controls to effects
DocumentExportMenu and the workspace transfer actions only draw the controls. DocumentEditorTransferActions groups your import and export callbacks; a null callback hides that target.
See import and export integration.