tessl install tessl/npm-marked@17.0.0A markdown parser built for speed
Work with Marked's token tree for advanced processing.
import { marked } from "marked";
marked.use({
walkTokens(token) {
if (token.type === 'heading') {
// Add custom ID to headings
token.id = token.text.toLowerCase().replace(/[^\w]+/g, '-');
}
},
renderer: {
heading({ tokens, depth, id }) {
const text = this.parser.parseInline(tokens);
return `<h${depth} id="${id}">${text}</h${depth}>\n`;
}
}
});import { marked } from "marked";
// Tokenize
const tokens = marked.lexer('# Hello\n\nThis is **markdown**.');
// Modify tokens
tokens.forEach(token => {
if (token.type === 'heading') {
token.depth += 1; // Demote all headings
}
});
// Parse modified tokens
const html = marked.parser(tokens);For complete token documentation, see:
See Real-World Scenarios for complete examples: