WebTools

307 Useful Tools & Utilities to make life easier.

HTML To Markdown

Convert HTML Documents to Markdown.

How the HTML to Markdown Converter Works

The HTML to Markdown tool is designed to seamlessly transform raw HyperText Markup Language into readable Markdown format. Rather than relying on simple string replacements or basic DOM parsing, this tool leverages the robust Showdown library under the hood. Showdown translates standard HTML components into their respective Markdown syntax rules.

The interface is built using Alpine.js for reactive data binding and state management. When you paste your HTML into the input panel, it is processed via an Ace Editor instance, which handles syntax highlighting and formatting. The tool initializes the Ace Editor with specific parameters including a 14px font size, line numbers, indent guides, and live autocompletion. It automatically binds to your system or page theme, swapping between ace/theme/monokai for dark mode and ace/theme/tomorrow for light mode dynamically through a MutationObserver.

Core Conversion Logic and Showdown Configuration

When you click the convert button, the tool initializes a new showdown.Converter instance. The conversion is highly specific, enabling several crucial Showdown extensions to ensure complex HTML structures are mapped correctly:

  • Tables (tables: true): Automatically parses HTML <table>, <tr>, <th>, and <td> tags into Markdown table syntax using pipes (|) and hyphens (-).
  • Tasklists (tasklists: true): Converts unordered lists containing checkboxes (e.g., <input type="checkbox">) into GitHub-flavored Markdown task lists ([ ] and [x]).
  • Strikethrough (strikethrough: true): Translates <strike>, <s>, or <del> tags into Markdown's double-tilde syntax (~~text~~).
  • Simplified Autolinks (simplifiedAutoLink: true): Ensures that bare URLs in the HTML are automatically recognized and converted into clickable Markdown links.

Following the primary conversion via converter.makeMarkdown(), the tool executes a targeted Regular Expression (regex) replacement: /\[([^\]]+)\]\(<([^>]+)>\)/g. This specific regex catches instances where Showdown might generate URLs wrapped in angle brackets (like [Link](<https://example.com>)) and standardizes them to the clean Markdown format: [Link](https://example.com).

Worked Example: From HTML to Markdown

To demonstrate exactly how the conversion logic processes your input, let's look at a concrete example using features explicitly enabled in the Showdown configuration.

Input (HTML):

<h1>Project Status</h1>
<p>Review the <s>old</s> new requirements at <a href="https://example.com">our site</a>.</p>
<ul>
  <li><input type="checkbox" checked> Design phase</li>
  <li><input type="checkbox"> Development phase</li>
</ul>
<table>
  <tr><th>Component</th><th>Status</th></tr>
  <tr><td>Frontend</td><td>Complete</td></tr>
</table>

Expected Output (Markdown):

# Project Status
Review the ~~old~~ new requirements at [our site](https://example.com).
- [x] Design phase
- [ ] Development phase

| Component | Status |
| --- | --- |
| Frontend | Complete |

In this example, the header is converted to an # tag. The <s> tag relies on the strikethrough: true setting to become ~~old~~. The checkbox inputs map to [x] and [ ] due to tasklists: true, and the table requires the tables: true configuration to output the pipes correctly.

Error Handling and Editor Constraints

The conversion process is wrapped in a try/catch block. If the Showdown compiler encounters catastrophically malformed HTML that breaks the parsing engine, it fails gracefully. The script intercepts the error, logs the stack trace to the browser console, and displays an alert stating, "Invalid HTML provided."

Both the input and output editors are constrained by the Ace editor options minLines: 10 and maxLines: 25. This means the editor will automatically resize to fit content up to 25 lines. After 25 lines, a scrollbar will appear, ensuring the interface remains manageable even if you paste thousands of lines of HTML. The output editor is strictly set to readOnly: true to prevent accidental modification of the generated Markdown before copying.

Frequently Asked Questions

Why are my table tags not converting properly?

The tool requires structurally sound HTML tables to trigger the tables: true configuration in Showdown. Ensure your table includes standard <tr>, <th> (for headers), and <td> tags. Tables constructed entirely out of <div> tags or missing row definitions cannot be parsed into Markdown table syntax.

Does the converter strip out inline CSS or classes?

Yes. Markdown inherently does not support inline styling, classes, or IDs. The Showdown converter parses the semantic meaning of the HTML (like headings, strong tags, lists) and outputs plain Markdown syntax. All style="..." or class="..." attributes are safely ignored during the conversion process.

How does the tool handle angle brackets in URLs?

In some edge cases, Markdown parsers wrap complex URLs in angle brackets to prevent parsing errors with parentheses. This tool includes a specific post-processing step utilizing the regex /\[([^\]]+)\]\(<([^>]+)>\)/g to strip these angle brackets. This ensures your final Markdown links look clean, changing [Text](<URL>) into [Text](URL) automatically.

Is there a size limit to the HTML I can convert?

There is no strict character limit hardcoded into the tool itself. However, because the conversion relies on JavaScript running on your device (via Showdown and Ace Editor), extremely large HTML documents might cause browser lag. The Ace editor UI is optimized to display up to 25 lines concurrently before enabling internal scrolling to maintain visual performance.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us