Summary of Javascript to convert Markdown/Textile to HTML (and, ideally, back to Markdown/Textile)

  • stackoverflow.com
  • Article
  • Summarized Content

    html

    Javascript Markdown to HTML: Finding the Right Converter

    This article dives into the world of javascript libraries that convert Markdown to HTML. We'll explore various options, comparing their features, sizes, and suitability for different use cases.

    Showdown: A Popular Javascript Markdown Parser

    Showdown is a widely used javascript library for converting Markdown to HTML. It offers comprehensive CommonMark support and was considered the gold standard for a long time. Showdown is known for its smaller size compared to other options.

    • It is significantly smaller than Markdown-It but is generally slower.
    • Showdown powers the popular PageDown library, which was used by StackOverflow before migrating to CommonMark.
    • Showdown is a good choice if you need a lightweight javascript library with good CommonMark support. However, it might not be the best option for complex documents or large projects.

    Markdown-It: The Current Gold Standard

    Markdown-It is a powerful and feature-rich javascript Markdown parser that has become the current gold standard. It offers comprehensive CommonMark support and is known for its speed and robustness.

    • Markdown-It powers StackExchange since its CommonMark migration.
    • It supports syntax extensions, making it a versatile choice for projects with custom markdown needs.
    • Markdown-It is also used in the popular online Markdown editor, Dillinger.io.
    • While it offers a robust solution, its size is larger than Showdown.

    PageDown: A Robust Markdown Converter

    PageDown is a well-established javascript Markdown converter that offers a solid foundation for Markdown parsing. It was widely used by StackOverflow before the CommonMark migration.

    • PageDown is highly robust but lacks support for features like tables, definition lists, and footnotes.
    • In addition to its converter, PageDown also provides editor and sanitizer scripts.
    • It is a lightweight option, making it suitable for projects with bandwidth constraints.

    Lightweight Options for Smaller Projects

    There are several lightweight javascript Markdown converters available that are ideal for smaller projects or situations where bandwidth is a concern.

    Drawdown: A Lightweight Converter with Broad Feature Scope

    Drawdown is a feather-weight javascript Markdown converter, developed by Adam Leggett. It offers a broad range of features, including support for most of the CommonMark spec.

    • Drawdown is a good option for web apps where you need a fast and efficient converter that handles most Markdown features.
    • It is not recommended for user-edited documents due to limitations in handling certain edge cases.
    • Drawdown is a lightweight option, with a file size less than 1.3KB.

    Exploring Other Lightweight Javascript Markdown Parsers

    Other lightweight javascript Markdown parsers include:

    • Marked: A comprehensive converter with support for custom lexer rules.
    • Micromarkdown: A converter supporting a wide range of features but missing some common Markdown elements and known for bugs.
    • Nano-Markdown: A robust converter with a limited feature scope but good performance.
    • Mmd.js: A minimal converter that supports a subset of Markdown features with a file size under 1KB.
    • Markdown-js: A comprehensive converter with tests, but not available as a minified version.
    • Meltdown: A jQuery plugin that supports Markdown Extra, including tables, definition lists, and footnotes.
    • Unified.js: A plugin-based system for converting between HTML, Markdown, and Prose.

    Textile to HTML: A Less Common Conversion Need

    Textile is a less common Markdown alternative. While it's more straightforward for basic formatting, finding robust javascript Textile converters can be challenging.

    Two popular Textile converters are:

    • Ben-Daglish Textile.js: A Javascript implementation of Textile.
    • Live Textile Preview: A simple Textile converter with a live preview example.

    The Importance of HTML to Markdown Conversion

    Converting HTML to Markdown can be tricky, but it is an essential step for projects where you need to work with Markdown content originating from existing HTML documents.

    • Storing both Markdown and HTML versions in your database can be a more reliable approach than relying on reverse conversion, ensuring consistency across your project.

    Ask anything...

    Sign Up Free to ask questions about anything you want to learn.