YAML front matter

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

from groupdocs.markdown import MarkdownConverter, ConvertOptions

def front_matter_example():
    """Convert a document to Markdown with YAML front matter extracted from metadata."""

    # Step 1: Enable front matter generation in conversion options
    options = ConvertOptions()
    options.include_front_matter = True

    # Step 2: Convert the document with front matter enabled
    md = MarkdownConverter.to_markdown("business-plan.docx", convert_options=options)

    # Step 3: Print the result -- YAML front matter appears at the top
    print(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 |  |  |

...

Download full output

---

format: Docx

pages: 18

---





| ![Woman with laptop and business documents](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA3ADcAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCAHyAqYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdI
[TRUNCATED]

Download full output

Combined with heading offset

from groupdocs.markdown import MarkdownConverter, ConvertOptions

def front_matter_combined():
    """Convert a document with both YAML front matter and heading level offset."""

    # Step 1: Configure options with front matter and heading offset
    options = ConvertOptions()
    options.include_front_matter = True       # add YAML metadata block
    options.heading_level_offset = 1          # shift headings down one level

    # Step 2: Convert and save to a file using keyword argument for options
    MarkdownConverter.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]

...

Download full output

---
author: "Brianna Thielen"
format: Docx
pages: 1
---

[queryEmployees]

Employee Information for Employee [EmployeeID]: [FirstName] [LastName]

[TRUNCATED]

Download full output

Front matter fields

Only non-empty fields are included:

FieldSourceExample
titleBuiltInDocumentProperties.Title"Q3 Report"
authorBuiltInDocumentProperties.Author"Jane Doe"
formatDetected file formatDocx
pagesPage or worksheet count12