Skip to content

refactor(markdown-toolkit): move placeholder substitution into core - #214

Merged
Jason3S merged 10 commits into
mainfrom
claude/md-core-substitute
Nov 22, 2026
Merged

Jason3S merged 10 commits into
mainfrom
claude/md-core-substitute

Conversation

@Jason3S

@Jason3S Jason3S commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The last step of moving markdown-toolkit's tree code into src/core/. The code that walks a tree and replaces its placeholders now lives in core, and nothing outside core imports mdast, remark, unified, unist or micromark. There's no behavior change, and the published types are the same.

Substitution (core/substitute.ts)

  • The walk moves here from template/substitute.ts, unchanged except for how it gets each replacement.
  • Core asks the template layer for each placeholder's replacement through PlaceholderReplacements, in the form its place takes:
    • line: alone on a line where blocks can go. Blocks split the paragraph, and anything else stays in the line.
    • inline: elsewhere inside a line.
    • string: inside code, HTML, a URL, a title or frontmatter.
  • The resolver is called as often as before: once per placeholder in the walk.
  • A paragraph's blocks are added in a loop instead of push(...blocks), which throws for a very large array.

Template layer

  • placeholderReplacements in template/replacements.ts builds those forms from a resolver, with the rules and error messages that were already there.
  • substitutePlaceholders stays in template/substitute.ts and builds its paragraphs through core.
  • A new test pins that a paragraph a replacement empties becomes an empty fragment.

Nodes instead of trees

  • The parser returns nodes (parseNodes), and the style reader and substitution take them. Code outside core no longer reads a tree's children or adds frontmatter to one.
  • Core no longer re-exports the Root and PlaceholderNode types, which nothing outside it uses now.

Layers test

  • No file is exempt from the import check any more.
  • A new check fails when a file outside core writes a node literal, such as { type: 'text', value }. A node literal needs no import, so the import check misses it.

Builders, element/ and the template helpers call constructors and readers in
core/ instead of writing mdast nodes by hand, and they name node types from
core/'s index. Only the substitution walk still imports mdast; it moves next.

The mdast augmentations move to core/customNodes.ts, which nothing imports.
Next to their nodes, a type import from core/ carried them into the published
types, and the build failed on @types/mdast.
…e/md-core-substitute

# Conflicts:
#	packages/markdown-toolkit/src/core/index.ts
#	packages/markdown-toolkit/src/core/nodes.ts
Base automatically changed from claude/md-core-nodes to main November 15, 2026 12:23
…tute

# Conflicts:
#	packages/markdown-toolkit/src/core/index.ts
#	packages/markdown-toolkit/src/core/nodes.ts
#	packages/markdown-toolkit/src/layers.test.ts
#	packages/markdown-toolkit/src/template/fragment.ts
#	packages/markdown-toolkit/src/template/parse.ts
#	packages/markdown-toolkit/src/template/replacements.ts
#	packages/markdown-toolkit/src/template/substitute.ts
#	packages/markdown-toolkit/src/template/template.ts
@Jason3S
Jason3S marked this pull request as ready for review November 15, 2026 12:30
…on move

- Pin that a paragraph a replacement empties becomes an empty fragment, and say why the one-node check is needed.
- Name the second layers check for what it matches: node literals.
- Correct the comments on the string place and its method.
- Name the replacements variable for what it holds.
@Jason3S
Jason3S merged commit d95436c into main Nov 22, 2026
8 checks passed
@Jason3S
Jason3S deleted the claude/md-core-substitute branch November 22, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant