Repository navigation
fix: make eject safe and preserve fence metadata - #82
Merged
Merged
Conversation
scalvert
added a commit
that referenced
this pull request
Sep 30, 2026
Introduce MarkdownDocument: parse a Markdown/MDX string once, expose its code blocks (language, content, directive, line, column, lineEnding), queue setBody/setDirective edits, and serialise with toString(). Fence handling (marker, indentation, meta, line endings) now lives in one place instead of three offset splicers in sync, extract, and eject — each of which recent fixes (#82, #86) had to patch separately. Move the snippet directive grammar into snippet-directive.ts: parseSnippetDirective (moved, quote-aware scanner from #85), formatSnippetDirective (canonical output, quotes paths with whitespace), and findSnippetDirectiveToken, which the document uses so fence edits touch exactly the token the parser read. Line-ending helpers move to line-endings.ts and remain re-exported from parser.ts. Behaviour fixes that fall out of the shared grammar: - eject removes quoted directives (snippet="a b.ts") whole instead of leaving a dangling fragment - extract quotes generated references whose directory contains spaces, so they parse back correctly - setBody no longer treats the last content line of an unclosed fence as its closing fence - check's out-of-sync message uses the directive form (snippet=a.ts#L10) instead of snippet://a.ts#L10-L10 parseMarkdownFile, parseMarkdownForExtraction, replaceCodeBlock, and the CodeBlock/MarkdownFile types are deprecated wrappers over the new module and will be removed in 2.0. Adds CONTEXT.md with the project's domain glossary.
3 tasks done
scalvert
added a commit
that referenced
this pull request
Sep 30, 2026
#98) * Deepen Markdown document module Introduce MarkdownDocument: parse a Markdown/MDX string once, expose its code blocks (language, content, directive, line, column, lineEnding), queue setBody/setDirective edits, and serialise with toString(). Fence handling (marker, indentation, meta, line endings) now lives in one place instead of three offset splicers in sync, extract, and eject — each of which recent fixes (#82, #86) had to patch separately. Move the snippet directive grammar into snippet-directive.ts: parseSnippetDirective (moved, quote-aware scanner from #85), formatSnippetDirective (canonical output, quotes paths with whitespace), and findSnippetDirectiveToken, which the document uses so fence edits touch exactly the token the parser read. Line-ending helpers move to line-endings.ts and remain re-exported from parser.ts. Behaviour fixes that fall out of the shared grammar: - eject removes quoted directives (snippet="a b.ts") whole instead of leaving a dangling fragment - extract quotes generated references whose directory contains spaces, so they parse back correctly - setBody no longer treats the last content line of an unclosed fence as its closing fence - check's out-of-sync message uses the directive form (snippet=a.ts#L10) instead of snippet://a.ts#L10-L10 parseMarkdownFile, parseMarkdownForExtraction, replaceCodeBlock, and the CodeBlock/MarkdownFile types are deprecated wrappers over the new module and will be removed in 2.0. Adds CONTEXT.md with the project's domain glossary. * Address second-pass review feedback - Only keep a closing fence in setBody when it matches the opening fence's character and is at least as long, so an unclosed ~~~ block ending in ``` no longer loses content. - setDirective is a no-op when the directive is unchanged (including after an intermediate edit), so fence lines are rewritten only when their directive actually changes. - formatSnippetDirective falls back to single quotes when the reference contains a double quote, and rejects references containing both, so formatted directives always parse back. - Move readMarkdownDocument into parser.ts; the deprecated wrappers and eject reuse it instead of a duplicate helper and a sync.js import. - Rename the resolved directive local in sync.ts to match CONTEXT.md. - Pin check's out-of-sync message in an integration test. - Update CONTRIBUTING.md project structure for the new modules.
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
Validation