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

mdast-util-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

mdast-util-substitute

mdast utility to parse and serialize inline substitution (:sub[...]{...})

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

mdast-util-substitute

mdast utilities for inline substitution (:sub[INITIAL]{REPLACEMENT}).

Inline substitution enables progressive disclosure — show brief content initially, reveal full content on activation. This package provides the mdast utilities; for a complete solution, use remark-substitute.

Install

npm install mdast-util-substitute

Usage

import { fromMarkdown } from 'mdast-util-from-markdown'
import { toMarkdown } from 'mdast-util-to-markdown'
import { sub } from 'micromark-extension-substitute'
import { subFromMarkdown, subToMarkdown } from 'mdast-util-substitute'

// Parse
const tree = fromMarkdown(':sub[initial]{replacement}', {
  extensions: [sub()],
  mdastExtensions: [subFromMarkdown()]
})

// Stringify
const md = toMarkdown(tree, {
  extensions: [subToMarkdown()]
})

AST

Sub

interface Sub extends Parent {
  type: 'sub'
  children: PhrasingContent[]      // Empty at this layer
  data: {
    replacement: PhrasingContent[] // Empty at this layer
    rawInitial: string             // Raw INITIAL text (escapes processed)
    rawReplacement: string         // Raw REPLACEMENT text (escapes processed)
  }
}

At the mdast-util layer, raw content is stored in rawInitial and rawReplacement. The children and replacement arrays are populated later by remark-substitute, which re-parses the raw content as inline Markdown.

Escaping

When serializing to markdown:

  • Unbalanced ] in INITIAL is escaped as \]
  • Unbalanced } in REPLACEMENT is escaped as \}
  • Balanced brackets/braces don't need escaping

License

MIT

Keywords

mdast

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