This brief article covers how to convert HTML to Markdown in Java. It explains how to set up the environment and make a few API calls for performing this task while using the shared code snippet to convert HTML to MD in Java. Moreover, you can also load an input HTML file instead of the HTML string and save it as a Markdown file after processing it.
Steps to Convert HTML to Markdown in Java
- Install Aspose.HTML for Java API to convert the input HTML files
- Create an HTML file by using an HTML string
- Use the ConvertHTML method to create an output Markdown file
These steps are helpful to understand how to create HTML to MD converter in Java. The first step explains the environment configuration followed by the creation of an input HTML file using a string. Finally, convert the HTML file to Markdown format based on your needs.
Code to Convert HTML to Markdown in Java
The code snippet above is sufficient to convert HTML to MD in Java. However, little modifications need to be made if you want to convert an existing HTML file. Simply omit the file writing part and then you only need to call convertHTML() method while passing the MarkdownSaveOptions class object in the parameters.
This tutorial explains how to convert HTML to Markdown converter in Java. However, if you want to learn Markdown to XPS conversion, you may read the article on how to convert Markdown to XPS in Java.