or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/marked@17.0.x

docs

index.md
tile.json

tessl/npm-marked

tessl install tessl/npm-marked@17.0.0

A markdown parser built for speed

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