markdown-js
A sensible, dialect-based Markdown-to-HTML parser for JavaScript.
Repository Health
Technical Analysis
markdown-js (published to npm as markdown) converts Markdown text into well-formed HTML in both Node.js and the browser. Rather than treating conversion as a single opaque step, it exposes an intermediate JsonML representation at each stage of the pipeline, so callers can inspect or rewrite the parsed Markdown tree or the resulting HTML tree before it is stringified.
The library ships two built-in dialects — Gruber (standard Markdown syntax) and Maruku (adds tables and other extensions) — and is structured so additional dialects can be registered without touching the core parsing engine. A bundled md2html CLI wraps the same API for command-line conversion. The project has been explicitly unmaintained since 2020, with the README pointing users toward markdown-it, Showdown, and Marked as actively developed alternatives.
What You Get
- A single
markdown.toHTML(text)call that converts Markdown straight to an HTML string - An inspectable, mutable JsonML intermediate tree via
markdown.parse()for custom pre/post-processing (e.g. filling in missing link references) - Two built-in dialects — Gruber (standard Markdown) and Maruku (adds tables and extensions) — selectable by name
- A bundled
md2htmlcommand-line tool for converting files or stdin without writing any JS - Works identically in Node.js (CommonJS/ES6 import) and in the browser via a standalone bundled script
Common Use Cases
- Rendering user-authored Markdown (comments, wikis, docs) to HTML on the server
- Live Markdown preview in a browser textarea/editor
- Post-processing parsed Markdown to auto-resolve or generate link references before rendering
- One-off Markdown-to-HTML conversion from the command line via
md2html
Under The Hood
Architecture — markdown-js implements Markdown-to-HTML conversion as three explicit, independently callable stages rather than a single black-box function. src/parser.js parses raw Markdown text into a JsonML tree, storing any link references it encounters in the root node’s attribute hash. src/dialects/gruber.js (and src/dialects/maruku.js) then walk that tree and convert it into an HTML JsonML tree, renaming nodes (e.g. bulletlist to ul) and resolving link/image references. Finally src/render_tree.js stringifies the HTML tree, taking care to preserve whitespace around inline elements. src/core.js defines the central Markdown constructor and its dialects namespace, which is how new dialects register themselves without modifying the parsing engine itself; src/markdown.js assembles the public library by requiring the parser, helpers, renderer, and both bundled dialects. lib/index.js is a thin Node-facing wrapper (exports.markdown, exports.parse) over that assembled module.
Tech Stack — The codebase is vanilla ES5 JavaScript written as AMD modules (define(...)), with amdefine providing a define shim when loaded outside an AMD loader (e.g. plain Node require). There is no TypeScript and no transpilation step. The build is driven by Grunt (Gruntfile.js) using grunt-contrib-jshint for linting and grunt-contrib-uglify to produce concatenated/minified dist/markdown.js and markdown.min.js bundles for browser use. The CLI (bin/md2html.js) depends on nopt for argument parsing. devDependencies are pinned to Grunt 0.4.x, RequireJS 2.1.x, and tap 0.3.x — versions consistent with the project’s last real activity around 2013-2014.