CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-marked

A markdown parser built for speed

Overview
Eval results
Files

token-manipulation.mddocs/guides/

Token Manipulation Guide

Work with Marked's token tree for advanced processing.

Token Walking

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`;
    }
  }
});

Low-Level API

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);

Detailed Documentation

For complete token documentation, see:

  • Lexer Reference
  • Token Types Reference

Common Token Patterns

See Real-World Scenarios for complete examples:

  • Table of contents generation
  • Heading ID generation
  • Link validation
  • Metadata extraction
  • Token statistics

Install with Tessl CLI

npx tessl i tessl/npm-marked

docs

index.md

tile.json