Skip to content

fix: preserve leading blank lines in MarkdownRenderer - #481

Open
BetterAndBetterII wants to merge 1 commit into
lepture:mainfrom
BetterAndBetterII:fix/leading-blank-lines
Open

fix: preserve leading blank lines in MarkdownRenderer#481
BetterAndBetterII wants to merge 1 commit into
lepture:mainfrom
BetterAndBetterII:fix/leading-blank-lines

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Fixes #366.

MarkdownRenderer dropped start-of-document blank lines, so a parse-then-markdown round trip of "\n\n\n\nabc" became 'abc\n'.

The parser now records the leading newline count on the first blank_line token (cursor == 0). The renderer emits those newlines when reformatting. Mid-document blanks are unchanged. The renderer still ends with a newline via strip_end, matching the rest of MarkdownRenderer.

Test: tests/test_renderers.py::TestMarkdownRendererRoundTrip::test_leading_blank_lines_preserved.

Blank-line tokens at the start of the document were rendered as empty
strings, so parse-then-markdown of a source that began with newlines
dropped them. Record the leading newline count on the first blank_line
token and emit it when reformatting.
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.

parse -> render to markdown misses leading newlines, appends extra newline

1 participant