Repository navigation
refactor(markdown-toolkit): move placeholder substitution into core - #214
Merged
Merged
Conversation
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
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)template/substitute.ts, unchanged except for how it gets each replacement.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.push(...blocks), which throws for a very large array.Template layer
placeholderReplacementsintemplate/replacements.tsbuilds those forms from a resolver, with the rules and error messages that were already there.substitutePlaceholdersstays intemplate/substitute.tsand builds its paragraphs through core.Nodes instead of trees
parseNodes), and the style reader and substitution take them. Code outside core no longer reads a tree's children or adds frontmatter to one.RootandPlaceholderNodetypes, which nothing outside it uses now.Layers test
{ type: 'text', value }. A node literal needs no import, so the import check misses it.