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

@peaceroad/markown-figure-num-setting

v0.2.0

Published

Set figure number for p7d-markdown-it-p-captions.

Readme

markown-figure-num-setting

Set sequential numbers for Markdown caption labels (and optionally image alt text).

Caption label detection is based on p7d-markdown-it-p-captions language regex rules.

Install

npm i @peaceroad/markown-figure-num-setting

Usage

import setMarkdownFigureNum from '@peaceroad/markown-figure-num-setting'

// The first argument must be Markdown content text (not a file path).
const outputMarkdown = setMarkdownFigureNum(markdownText, option)

If you have a file path, read the file content first:

import fs from 'node:fs'
import setMarkdownFigureNum from '@peaceroad/markown-figure-num-setting'

const markdownText = fs.readFileSync(markdownPath, 'utf8')
const outputMarkdown = setMarkdownFigureNum(markdownText)

Basic behavior

Input:

Paragraph.

Figure. A caption

![A alt text.](image.jpg)

Paragraph.

Figure. A caption

![A alt text.](image.jpg)

Output (default option):

Paragraph.

Figure 1. A caption

![A alt text.](image.jpg)

Paragraph.

Figure 2. A caption

![A alt text.](image.jpg)

Options

Default options:

{
  img: true,
  video: false,
  table: false,
  'pre-code': false,
  'pre-samp': false,
  blockquote: false,
  slide: false,
  audio: false,
  labelMarkMap: null,
  noSetAlt: true,
  setNumberAlt: false,
  setImgAlt: false,
}
  • img, video, table, pre-code, pre-samp, blockquote, slide, audio: Enable numbering for each caption type.
  • setNumberAlt: true: Also set numbered label text to related image alt text.
  • setImgAlt: true: Alias behavior for alt-text numbering.
  • noSetAlt: false: Legacy-compatible switch to enable alt-text numbering.
  • labelMarkMap: Optional map to resolve overlapping labels by mark name. Example: { '図': 'pre-samp', 'リスト': 'pre-samp' }.

All type options above are active in the current implementation.

When multiple type options are enabled, counters are maintained per type.

Label overlap note (from p7d-markdown-it-p-captions dictionaries):

  • Japanese can match both img and pre-samp.
  • Japanese リスト can match both pre-code and pre-samp.

If an input label can match multiple enabled types, the first matched type wins in this order: img -> video -> table -> pre-code -> pre-samp -> blockquote -> slide -> audio.

You can override this default with labelMarkMap.

Alt text numbering example

Input:

図 キャプション

![ALT-A](image.jpg)

図 キャプション

![ALT-B](image.jpg)

Output ({ setNumberAlt: true }):

図1 キャプション

![図1](image.jpg)

図2 キャプション

![図2](image.jpg)

Notes

  • Original line endings are preserved, including mixed \r\n and \n.
  • Fenced code blocks are skipped:
    • Backtick/tilde fences with 3+ markers (including variable-length fences like `````).
    • Full-line math fences ($$, $$$, ...).
  • Indented code blocks (4 spaces or tab) are currently out of scope. Use fenced code blocks if you need guaranteed skip behavior.
  • Non-string input is returned as-is.
  • Alt-text rewriting targets inline image syntax such as ![alt](url "title") (including escaped chars and trailing attrs).
  • Reference-style image links are out of scope.
  • If caption-to-image pairing is ambiguous in dense sections, separate blocks explicitly (for example with <!---->).