npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

marked-token-position

v2.0.1

Published

marked extension template

Readme

marked-token-position

Add position field for each token.

interface Position {
  /**
   * Positions for each line of the token. LinePositions will not include the newline character for the line.
   */
  lines: LinePosition[]
  /**
   * Position at the beginning of token
   */
  start: PositionFields;
  /**
   * Position at the end of token
   */
  end: PositionFields;
}

interface LinePosition {
  /**
   * Position at the beginning of line
   */
  start: PositionFields;
  /**
   * Position at the end of line. Will not include the newline character.
   */
  end: PositionFields;
}

interface PositionFields {
  /**
   * Number of characters from the beginning of the markdown string
   */
  offset: number;
  /**
   * Line number of the token. Starts at line 0.
   */
  line: number;
  /**
   * Column number of the token. Starts at column 0.
   */
  column: number;
}

Usage

Extension

import {Marked} from "marked";
import markedTokenPosition from "marked-token-position";

// or UMD script
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
// <script src="https://cdn.jsdelivr.net/npm/marked-token-position/lib/index.umd.js"></script>
// const Marked = marked.Marked;

const marked = new Marked();

function anotherExtension {
	return {
		walkTokens(token) {
			// token has `position` field
		}
		hooks: {
			processAllTokens(tokens) {
				// tokens have `position` field
			}
		}
	};
}

marked.use(anotherExtension(), markedTokenPosition());

marked.parse("# example markdown");

The position field will be added to the tokens so any other extension can use the position field in a walkTokens function or processAllTokens hook.

[!CAUTION] The processAllTokens hook is used by this extension so any other extension using processAllTokens that requires the position field must be added before this extension because marked calls the processAllTokens hooks in reverse order.

The tokens will look like:

[
  {
    "type": "heading",
    "raw": "# example markdown",
    "depth": 1,
    "text": "example markdown",
    "tokens": [
      {
        "type": "text",
        "raw": "example markdown",
        "text": "example markdown",
        "escaped": false,
        "position": {
          "start": {
            "offset": 2,
            "line": 0,
            "column": 2
          },
          "end": {
            "offset": 18,
            "line": 0,
            "column": 18
          }
        }
      }
    ],
    "position": {
      "start": {
        "offset": 0,
        "line": 0,
        "column": 0
      },
      "end": {
        "offset": 18,
        "line": 0,
        "column": 18
      }
    }
  }
]

addTokenPositions

Calling marked.lexer() will not add the position field with the extension since the extension is only called on marked.parse() and marked.parseInline().

An addTokenPositions function is exported to add the position field to the tokens returned by marked.lexer().

import {Marked} from "marked";
import {addTokenPositions} from "marked-token-position";

// or UMD script
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
// <script src="https://cdn.jsdelivr.net/npm/marked-token-position/lib/index.umd.js"></script>
// const Marked = marked.Marked;
// const addTokenPositions = markedTokenPosition.addTokenPositions;


const marked = new Marked();
const tokens = marked.lexer("# example markdown");

addTokenPositions(tokens);

// tokens now have a `position` field