Use GroupDocs.Markdown to convert TXT, XML, and other text-based formats to clean Markdown.
Using static method
The simplest way to convert a text file:
importosfromgroupdocs.markdownimportLicense,MarkdownConverterdefexport_text_to_markdown():"""Convert an XML/text file 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 XML to a Markdown string in one callmarkdown=MarkdownConverter.to_markdown("llms-tech.xml")# Step 3: Or save the conversion result directly to a fileMarkdownConverter.to_file("llms-tech.xml","export-text.md")if__name__=="__main__":export_text_to_markdown()
llms-tech.xml is sample file used in this example. Click here to download it.
`<Technologies>`
`<Category name="Model Architectures">`
`<Technology>`
`<Name>Transformer</Name>`
`<Description>Attention-based neural architecture used by most modern LLMs.</Description>`
...
`<Technologies>`
`<Category name="Model Architectures">`
`<Technology>`
`<Name>Transformer</Name>`
`<Description>Attention-based neural architecture used by most modern LLMs.</Description>`
[TRUNCATED]
importosfromgroupdocs.markdownimportLicense,MarkdownConverter,ConvertOptionsdefexport_text_with_options():"""Convert an XML/text file to Markdown using the instance API with 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 text file with a context managerwithMarkdownConverter("llms-tech.xml")asconverter:# Step 3: Configure conversion optionsoptions=ConvertOptions()options.heading_level_offset=1# shift all headings down one level# Step # Step 4: Convert and save the Markdown outputconverter.convert("export-text-options.md",convert_options=options)if__name__=="__main__":export_text_with_options()
llms-tech.xml is sample file used in this example. Click here to download it.
`<Technologies>`
`<Category name="Model Architectures">`
`<Technology>`
`<Name>Transformer</Name>`
`<Description>Attention-based neural architecture used by most modern LLMs.</Description>`
...
`<Technologies>`
`<Category name="Model Architectures">`
`<Technology>`
`<Name>Transformer</Name>`
`<Description>Attention-based neural architecture used by most modern LLMs.</Description>`
[TRUNCATED]