Use GroupDocs.Markdown to convert DOCX and other Word documents to clean Markdown.
Using static method
The simplest way to convert a Word file:
importosfromgroupdocs.markdownimportLicense,MarkdownConverterdefexport_word_to_markdown():"""Convert a Word document to Markdown using the static one-liner API."""# Step 1: Apply the license (optional for evaluation)ifos.path.exists("GroupDocs.Markdown.lic"):License.set_("GroupDocs.Markdown.lic")# Step 2: Convert DOCX to a Markdown string in one callmarkdown=MarkdownConverter.to_markdown("business-plan.docx")# Step 3: Or save the conversion result directly to a fileMarkdownConverter.to_file("business-plan.docx","export-word.md")if__name__=="__main__":export_word_to_markdown()
business-plan.docx is sample file used in this example. Click here to download it.
| :"""Convert a Word document to Markdown using the instance API with image export and heading offset."""# Step 1: Apply the license (optional for evaluation)ifos.path.exists("GroupDocs.Markdown.lic"):License.set_("GroupDocs.Markdown.lic")# Step 2: Open the DOCX document with a context managerwithMarkdownConverter("business-plan.docx")asconverter:# Step 3: Configure the image export strategy to save images to diskstrategy=ExportImagesToFileSystemStrategy("images")strategy.images_relative_path="images"# Step 4: Set conversion optionsoptions=ConvertOptions()options.image_export_strategy=strategyoptions.heading_level_offset=1# shift all headings down one level# Step # Step 5: Convert and save the Markdown outputconverter.convert("export-word-options.md",convert_options=options)if__name__=="__main__":export_word_with_options()
business-plan.docx is sample file used in this example. Click here to download it.