kramed
raw JSON → 0.5.6 verified Fri May 01 auth: no javascript abandoned
A markdown parser and compiler forked from marked, designed to be kramdown-compatible and support MathJax. The current stable version is 0.5.6, with no active development since 2016. It offers synchronous and asynchronous rendering, customizable renderers, and built-in highlighting integration. Unlike marked, kramed aims to align with the kramdown standard (common in Jekyll) and provides enhanced math support, making it suitable for documentation tools like GitBook. However, it is now largely superseded by modern markdown parsers such as marked (post-0.6) and markdown-it.
Common errors
error ReferenceError: kramed is not defined ↓
cause Using ESM import with wrong syntax (e.g., import { kramed } from 'kramed') instead of default import.
fix
Use 'import kramed from 'kramed';' or 'const kramed = require('kramed');'
error TypeError: kramed is not a function ↓
cause Rarely, bundlers may mangle the default export if mixing CJS/ESM.
fix
Ensure your bundler config uses esModuleInterop or use require().
error kramed(...).trim is not a function ↓
cause Nowadays with bundlers, if you import kramed and try to call a method on the result, but kramed returns a string; this error usually occurs when you accidentally call kramed on an object.
fix
Check that the argument to kramed() is a string, not a buffer or HTML.
error Cannot find module 'kramed' ↓
cause Not installed or typo in package name (e.g., 'kramed' vs 'kraemde').
fix
Run 'npm install kramed' and verify package.json has 'kramed' in dependencies.
Warnings
breaking kramed.setOptions does not return the kramed function, but sets global state. ↓
fix Call setOptions before rendering, or pass options directly to kramed() instead.
deprecated The package is no longer maintained; last release in 2016. Unpatched vulnerabilities may exist. ↓
fix Migrate to a maintained alternative like marked, markdown-it, or unified/remark.
gotcha sanitize option defaults to true, which strips HTML tags from output. This may break intended inline HTML. ↓
fix Set sanitize: false if you want to allow raw HTML, but be aware of XSS risks.
gotcha kramed.lexer and kramed.parser are not documented and their API may change without notice. ↓
fix Use the high-level kramed() function instead of calling lexer/parser directly.
breaking Async callback style (kramed(str, callback)) is only valid when options.highlight uses async highlighting. ↓
fix Do not pass a callback unless you have set an async highlight function; otherwise use synchronous return.
gotcha MathJax support requires custom renderer; not built-in despite documentation claims. ↓
fix Extend the Renderer class to handle math tokens, or use a dedicated math plugin.
Install
npm install kramed yarn add kramed pnpm add kramed Imports
- kramed wrong
import { kramed } from 'kramed';correctimport kramed from 'kramed'; // or const kramed = require('kramed') - Renderer wrong
import Renderer from 'kramed';correctimport { Renderer } from 'kramed'; - Lexer / Parser
import { Lexer, Parser } from 'kramed';
Quickstart
import kramed from 'kramed';
const options = {
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
};
const markdownString = '# Hello World\n\nThis is **bold** and `code`.';
const html = kramed(markdownString, options);
console.log(html);
// Output: <h1 id="hello-world">Hello World</h1>\n<p>This is <strong>bold</strong> and <code>code</code>.</p>\n