Skip to content

Fix in-place processing dropping lines from files without mdsh tags#99

Open
mwittie wants to merge 3 commits intozimbatm:mainfrom
mwittie:main
Open

Fix in-place processing dropping lines from files without mdsh tags#99
mwittie wants to merge 3 commits intozimbatm:mainfrom
mwittie:main

Conversation

@mwittie
Copy link

@mwittie mwittie commented Feb 10, 2026

Fixes #98

Summary

  • Remove trim_ascii_end which stripped all trailing whitespace (including newlines) on in-place writes
  • Normalize input with a trailing \n so the parser can handle every line
  • Preserve the file's original trailing newline convention on output
  • Add integration tests covering both trailing newline cases

Approach

The fix is in main.rs (the file I/O layer) rather than the parser because:

  • The parser uses chained nom combinators; changing it to handle EOF without \n would add complexity to every alternative in markdown_piece()
  • Normalizing input at the I/O boundary is simpler and more defensive — the parser shouldn't need to worry about missing trailing newlines
  • Removing trim_ascii_end is correct because mdsh should not modify content that isn't mdsh-related

* Add tests for in-place processing of files without mdsh tags

These tests verify that files with no mdsh tags are not modified by
in-place processing, regardless of whether they have a trailing newline.
Both tests currently fail, documenting the bug where lines are
progressively deleted from the end of the file.

* Fix in-place processing dropping lines from files without mdsh tags

Remove trim_ascii_end which stripped all trailing whitespace including
newlines, causing the parser to silently drop the last line on
subsequent runs. Instead, ensure the input is newline-terminated for
the parser and preserve the file's original trailing newline convention
when writing back.
Move transition text (e.g. `:: which outputs:`) from a separate
`<!-- :: text -->` comment line into the mdsh invocation itself,
supported across all invocation types: code blocks, inline code,
comments, and links. The old comment-based syntax is kept as a
fallback for backward compatibility.
* Reorganize transition tests under existing execute sections

* Add instructions for transition text in the mdsh invocation and in a comment following the invocation
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.

In-place processing of files without mdsh tags progressively deletes lines

1 participant