Skip to content

fix: preserve markdown line endings - #86

Merged
scalvert merged 1 commit into
mainfrom
fix/preserve-line-endings
Aug 31, 2026
Merged

scalvert merged 1 commit into
mainfrom
fix/preserve-line-endings

Conversation

@steve-calvert-glean

Copy link
Copy Markdown
Collaborator

Summary

This PR contains the focused implementation and regression coverage for fix: preserve markdown line endings.

Validation

The branch passed its focused tests, full test suite, typecheck, lint, build, and git diff checks.

@scalvert
scalvert merged commit 5b3ba31 into main Aug 31, 2026
2 checks passed
@scalvert
scalvert deleted the fix/preserve-line-endings branch August 31, 2026 23:36
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.
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.
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.

2 participants