Enable include_front_matter to extract document metadata into a YAML block at the beginning of the Markdown output. This is commonly used by static site generators like Jekyll, Hugo, and Docusaurus.
Example
fromgroupdocs.markdownimportMarkdownConverter,ConvertOptionsdeffront_matter_example():"""Convert a document to Markdown with YAML front matter extracted from metadata."""# Step 1: Enable front matter generation in conversion optionsoptions=ConvertOptions()options.include_front_matter=True# Step 2: Convert the document and save it to a Markdown fileMarkdownConverter.to_file("business-plan.docx","front-matter-example.md",convert_options=options)# Output:# ---# title: "Q3 Report"# author: "Jane Doe"# format: Docx# pages: 12# ---## # Q3 Report# ...if__name__=="__main__":front_matter_example()
business-plan.docx is sample file used in this example. Click here to download it.
fromgroupdocs.markdownimportMarkdownConverter,ConvertOptionsdeffront_matter_combined():"""Convert a document with both YAML front matter and heading level offset."""# Step 1: Configure options with front matter and heading offsetoptions=ConvertOptions()options.include_front_matter=True# add YAML metadata blockoptions.heading_level_offset=1# shift headings down one level# Step 2: Convert and save to a file using keyword argument for optionsMarkdownConverter.to_file("annual-report.docx","front-matter-combined.md",convert_options=options)if__name__=="__main__":front_matter_combined()
annual-report.docx is sample file used in this example. Click here to download it.