html to markdown

Convert HTML to Markdown online

The HTML format is one of the primary formats for websites as a majority of the browsers support this standard. Whereas, a Markdown file is a text file created using one of several possible dialects of the Markdown language. It uses plain text formatting but contains inline text symbols that specify how to format the text (e.g., *bold* for bold text, or other markups for italics, indentation, headers, etc.). Please be aware that Markdown files may use .MD, .MARKDN, and .MDOWN extensions, where “.markdown” and “.md” extensions are the most popular ones. So in this article, we are going to discuss the details of converting HTML to Markdown using REST API.

HTML to Markdown Conversion API

Aspose.HTML Cloud is a leading HTML file processing API providing the capabilities to manipulate HTML files. It also supports the feature to convert HTML to PDF, JPG, TIFF, XPS, and other supported formats. It also supports the feature to convert HTML to MD format. Now in order to develop HTML to markdown converter using Java language, we first need to first add Aspose.HTML Cloud SDK for Java reference in the pom.xml file of maven build type.

<repositories> 
    <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>http://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words-cloud</artifactId>
        <version>22.8.0</version>
    </dependency>
</dependencies>

After the installation, please create a free subscription account on our cloud services via Aspose.Cloud dashboard using GitHub or Google account. Or, simply create a new Account and obtain your Client Credentials details.

Convert HTML to Markdown in Java

Please follow the instructions specified below to convert HTML to Markdown.

  • Firstly, pass client credentials against Configuration.setAPP_SID and Configuration.setAPI_KEY methods.
  • Secondly, set details for setBasePath(..), setAuthPath(..) and specify setUserAgent(…) as WebKit.
  • Thirdly, pass true to setDebug(..) method.
  • After configuration, please create an object of ConversionApi class.
  • Finally, call PutConvertDocumentToMarkdown(…) method to convert HTML to Markdown and save the output in cloud storage.

HTML to MD using cURL Commands

As Aspose.HTML Cloud is based on REST architecture, so it can easily be accessed via cURL commands. Now, as a prerequisite, we need to generate JWT access token based on client credentials specified against your account on cloud dashboard. Now, please execute the following command to generate the JWT token:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once we have the JWT token, please execute the following command to HTML to MD.

curl -v -X PUT "https://api.aspose.cloud/html/list.html/convert/md?outPath=Converted.md&useGit=false" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Conclusion

This article has provided a great source for learning the steps to develop HTML to Markdown converter using Java Cloud SDK. We have observed that with fewer code lines, we managed to convert HTML to MD format. You may also consider exploring the APIs through Swagger UI within a web browser. Should you have any related queries, or you encounter any issues, please do not hesitate to contact us via the free technical support forum.

We highly recommend going through the following articles to learn more about them: