generateFromMarkdown static method

Uint8List generateFromMarkdown({
  1. required String content,
  2. String title = 'Documento',
})

Convert markdown content to DOCX bytes.

The markdown is parsed and converted to OOXML paragraph elements. Supports: # headings, bold, - bullets, plain paragraphs.

Implementation

static Uint8List generateFromMarkdown({
  required String content,
  String title = 'Documento',
}) {
  final archive = Archive();

  // Add static XML files
  _addFile(archive, '[Content_Types].xml', _contentTypesXml);
  _addFile(archive, '_rels/.rels', _relsXml);
  _addFile(archive, 'word/_rels/document.xml.rels', _documentRelsXml);
  _addFile(archive, 'word/styles.xml', _stylesXml);
  _addFile(archive, 'word/numbering.xml', _numberingXml);

  // Generate dynamic document.xml from markdown
  final documentXml = _buildDocumentXml(content, title);
  _addFile(archive, 'word/document.xml', documentXml);

  final encoded = ZipEncoder().encode(archive);
  return Uint8List.fromList(encoded ?? []);
}