Streamline Your Documentation with Reader-LM's HTML to Markdown Conversion Action

23 Apr 2025
Streamline Your Documentation with Reader-LM's HTML to Markdown Conversion Action

In today's digital landscape, content creation and management often require a seamless transition between different formats. The justmalhar/reader-lm API offers a powerful Cognitive Action designed specifically for this purpose: converting HTML content into Markdown. This action utilizes the Jina Reader-LM, a sophisticated model trained on extensive collections of HTML and corresponding Markdown content, ensuring accurate and efficient conversion suitable for streamlined documentation workflows.

Prerequisites

Before you get started with the HTML to Markdown conversion action, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with JSON format and API interaction, as you'll be structuring your input payload in JSON.

For authentication, you'll typically pass your API key in the headers of your requests, allowing you to securely access the Cognitive Actions.

Cognitive Actions Overview

Convert HTML to Markdown

The Convert HTML to Markdown action is designed to facilitate the transformation of HTML content into a Markdown format, which is simpler and more readable for documentation purposes.

  • Category: Data Conversion
  • Purpose: This action helps users, such as web developers and technical writers, convert complex HTML structures into a lightweight, easy-to-read Markdown format.

Input

The input for this action requires a JSON object with the following fields:

  • prompt (required): The HTML content you wish to convert.
  • topP (optional): A number controlling the diversity of the output using nucleus sampling, defaulting to 0.95.
  • temperature (optional): A number that determines the randomness of the output, defaulting to 0.5.

Here’s an example of the input structure:

{
  "topP": 0.95,
  "prompt": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>HTML to Markdown using Reader LM</title>\n</head>\n<body>\n    <header>\n        <h1>HTML to Markdown Conversion: A Comprehensive Guide</h1>\n        <nav>\n            <ul>\n                <li><a href=\"#intro\">Introduction</a></li>\n                <li><a href=\"#steps\">Steps to Convert HTML to Markdown</a></li>\n                <li><a href=\"#examples\">Examples</a></li>\n                <li><a href=\"#conclusion\">Conclusion</a></li>\n            </ul>\n        </nav>\n    </header>\n    <section id=\"intro\">\n        <h2>Introduction</h2>\n        <p>Welcome to this in-depth guide on converting HTML to Markdown using the Reader LM tool.</p>\n    </section>\n</body>\n</html>"
}

Output

The action will typically return a structured array of strings, where each element represents processed content from the original HTML. Here’s an example of what the output might look like:

[
  "Introduction",
  "\n------------\n\n",
  "Welcome to this in-depth guide on converting HTML to Markdown using the Reader LM tool."
]

This output captures the essential elements of the input HTML in a Markdown format, making it easy to read and manipulate.

Conceptual Usage Example (Python)

Here’s how you might call the Convert HTML to Markdown action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "b10ac3f9-48c7-451e-88c7-c90a6d1a283b" # Action ID for Convert HTML to Markdown

# Construct the input payload based on the action's requirements
payload = {
    "topP": 0.95,
    "prompt": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>HTML to Markdown using Reader LM</title>\n</head>\n<body>\n    <header>\n        <h1>HTML to Markdown Conversion: A Comprehensive Guide</h1>\n    </header>\n</body>\n</html>"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this example, replace the placeholder API key and endpoint with your actual credentials. The payload variable is structured according to the action's input requirements, allowing you to effectively convert HTML to Markdown.

Conclusion

The Convert HTML to Markdown action from the justmalhar/reader-lm API is an invaluable tool for developers and content creators looking to streamline their documentation processes. By leveraging this action, you can effortlessly convert HTML content into a Markdown format that is more manageable and user-friendly.

Explore the potential of this Cognitive Action and enhance your workflow by integrating it into your applications today!