GroupDocs.Markdown provides a quick and easy way to convert documents into clean, structured Markdown. The library offers two approaches: static methods for one-line conversions and an instance API for more control.
Static methods (simplest)
Call MarkdownConverter.to_markdown() to get a Markdown string, or MarkdownConverter.to_file() to write directly to disk:
fromgroupdocs.markdownimportMarkdownConverterdefconvert_static():"""Convert a document to Markdown using the static one-liner API."""MarkdownConverter.to_file("business-plan.docx","convert-static-methods.md")if__name__=="__main__":convert_static()
business-plan.docx is sample file used in this example. Click here to download it.
Create a MarkdownConverter instance for advanced scenarios such as inspecting metadata before converting or reusing a loaded document:
fromgroupdocs.markdownimportMarkdownConverter,ConvertOptionsdefconvert_instance():"""Convert a document using the instance API with conversion options."""withMarkdownConverter("business-plan.docx")asconverter:options=ConvertOptions()options.heading_level_offset=1converter.convert("convert-instance-api.md",convert_options=options)if__name__=="__main__":convert_instance()
business-plan.docx is sample file used in this example. Click here to download it.
Use ConvertOptions to customize the output – select specific pages, control image handling, choose a Markdown flavor, add YAML front matter, and more. For loading customization, use LoadOptions to specify file format or provide a password.
These documentation articles explain how to convert files from the most popular formats: