snarkdown Documentation

repository·main·Indexed 25 days ago

https://github.com/developit/snarkdown

A tiny (1kb), fast Markdown parser that transforms Markdown strings into HTML strings. Designed for minimal use-cases and constrained environments, it supports common syntax including headings, code blocks, lists, and inline formatting, though it does not support tables or HTML sanitization.

Tokens
422
Snippets
1
Records
4
Agent score
32%

What's inside snarkdown

  1. Install and use Snarkdown

    main

    Snarkdown is a minimal, 1kb Markdown parser designed for constrained environments. It works by taking a Markdown string as input and returning an HTML string as output.

    Important Security Note: Snarkdown does not sanitize HTML. It is intended for use cases where XSS protection is handled elsewhere or is not required.

    Limitations: Tables are not currently supported.

    import snarkdown from 'snarkdown';
    
    let md = '_this_ is **easy** to `use`.';
    let html = snarkdown(md);
    console.log(html);
    // <em>this</em> is <strong>easy</strong> to <code>use</code>.
  2. Use the snarkdown function

    main
    The snarkdown module exports a single function. When called with a Markdown string, it returns the corresponding HTML string. It is available in multiple module formats including ES Modules, CommonJS, and UMD.
  3. Parse Markdown with parse()

    main

    The parse function is the primary entry point for snarkdown. It converts a Markdown string into an HTML string. It supports common Markdown syntax including headings, code blocks, lists, blockquotes, images, links, and inline formatting (em, strong, strike, etc.).

    Parameters:

    • md (String): The Markdown content to be parsed.
    • prevLinks (Object, optional): An object containing previously defined link references. This allows for incremental parsing or maintaining link state across multiple calls.

    Returns:

    • (String): The resulting HTML string.