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 the Word document directly to a Markdown fileMarkdownConverter.to_file("business-plan.docx","export-word-static.md")if__name__=="__main__":export_word_to_markdown()
business-plan.docx is sample file used in this example. Click here to download it.
importosfromgroupdocs.markdownimportLicense,MarkdownConverter,ConvertOptions,ExportImagesToFileSystemStrategydefexport_word_with_options():"""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 5: Convert and save the Markdown outputconverter.convert("export-word-instance.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.