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 with front matter enabledmd=MarkdownConverter.to_markdown("business-plan.docx",convert_options=options)# Step 3: Print the result -- YAML front matter appears at the topprint(md)# 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.
---
format: Docx
pages: 18
---
| HOME BASED | | |
| --- | --- | --- |
| | | |
| PROFESSIONAL SERVICES | | |
...
---
format: Docx
pages: 18
---
| :"""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.
---
author: "Brianna Thielen"
format: Docx
pages: 1
---
[queryEmployees]
Employee Information for Employee [EmployeeID]: [FirstName] [LastName]
...