emdp
v1.0.0
Published
A CommonMark-compliant Markdown parser with optional GFM support
Maintainers
Readme
CommonMark Parser (with GFM support)
A CommonMark-compliant Markdown parser with an optional GitHub Flavored Markdown (GFM) mode, plus a small set of cmark-gfm compatible extensions.
Features
- CommonMark parser with block and inline support
- GFM mode (tables, strikethrough, task lists, extended autolinks, tag filtering)
- Footnotes (GFM-style)
- HTML rendering with safe-mode controls
- CLI for pipeline usage
- TypeScript types with dual ESM/CJS exports
Installation
npm install emdpQuick Start
CommonMark
import { markdown } from 'emdp';
const html = markdown('# Hello *world*');
console.log(html);CommonJS
const { markdown } = require('emdp');
const html = markdown('# Hello *world*');
console.log(html);GFM
import { gfm } from 'emdp/gfm';
const html = gfm('- [x] done\n- [ ] todo');
console.log(html);Usage Examples
Render with Options
import { gfm } from 'emdp/gfm';
const html = gfm(source, {
safe: true,
smart: true,
tablePreferStyleAttributes: true,
fullInfoString: true,
tagfilter: true,
extensions: ['table', 'strikethrough', 'autolink', 'tagfilter', 'tasklist', 'footnotes'],
});Parse and Render Separately
import { parse, render } from 'emdp';
import { parse as gfmParse, render as gfmRender } from 'emdp/gfm';
const doc = parse(source);
const html = render(doc);
const gfmDoc = gfmParse(source);
const gfmHtml = gfmRender(gfmDoc, { smart: true });CLI
# CommonMark
mdparse < README.md
# GFM
mdparse --gfm < README.mdCLI Flags
--gfm- enable GFM parsing-e <extension>- enable specific extensions (for test compatibility)--smart- smart punctuation--table-prefer-style-attributes- use style attributes for table alignment--full-info-string- render full info string as data-meta on code blocks--unsafe- ignored (compatibility flag)
API Reference
CommonMark
markdown(input, options)- parse + renderparse(input, options)- parse into ASTrender(document, options)- render AST to HTML
GFM
gfm(input, options)- parse + render (GFM)parse(input, options)- parse into AST (GFM)render(document, options)- render AST to HTML (GFM)
Render Options
safe- omit raw HTML outputsoftbreak- string used for soft line breaks (default:\n)smart- enable smart punctuationtablePreferStyleAttributes- use style attributes for table alignmentfullInfoString- include full info string asdata-metaon code blockstagfilter- escape disallowed raw HTML tags (GFM tag filter)extensions- list of GFM extensions to enable (defaults to all supported)
