Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

micromark-extension-substitute

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-extension-substitute

Micromark extension for inline substitution syntax (:sub[...]{...})

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

micromark-extension-substitute

micromark extension for inline substitution syntax (:sub[INITIAL]{REPLACEMENT}).

Inline substitution enables progressive disclosure — show brief content initially, reveal full content on activation. Useful for TL;DR summaries, spoilers, and interactive learning. For a complete solution, use remark-substitute.

Install

npm install micromark-extension-substitute

Usage

import { micromark } from 'micromark'
import { sub } from 'micromark-extension-substitute'

const html = micromark(':sub[initial]{replacement}', {
  extensions: [sub()],
  htmlExtensions: [{
    enter: {
      sub() { this.tag('<span class="sub">') }
    },
    exit: {
      subInitialData(token) {
        this.tag('<span class="initial">')
        this.raw(this.sliceSerialize(token))
        this.tag('</span>')
      },
      subReplacementData(token) {
        this.tag('<span class="replacement">')
        this.raw(this.sliceSerialize(token))
        this.tag('</span>')
      },
      sub() { this.tag('</span>') }
    }
  }]
})

// Output: <p><span class="sub"><span class="initial">initial</span><span class="replacement">replacement</span></span></p>

Note: This extension only tokenizes the syntax. You must provide an htmlExtensions handler to render output, or use remark-substitute for a complete solution.

Tokens

  • sub — The whole construct
  • subMarker — The :sub[, ], {, and } markers
  • subInitialData — The INITIAL content
  • subReplacementData — The REPLACEMENT content

Syntax

  • Starts with :sub[ (no whitespace allowed)
  • INITIAL ends with ] (with bracket balancing)
  • REPLACEMENT is between { and } (with brace balancing)
  • Cannot span multiple lines
  • Must not be preceded by a word character (a-z, A-Z, 0-9, _)

Escaping

In INITIAL:

  • \] → literal ] (doesn't close)
  • \[ → literal [ (no depth change)
  • \\ → literal \

In REPLACEMENT:

  • \} → literal } (doesn't close)
  • \{ → literal { (no depth change)
  • \\ → literal \

License

MIT

Keywords

micromark

FAQs

Package last updated on 03 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts