Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Trailing newlines are removed following markup #167

Open
1 task done
mtoohey31 opened this issue Apr 11, 2024 · 3 comments
Open
1 task done

Trailing newlines are removed following markup #167

mtoohey31 opened this issue Apr 11, 2024 · 3 comments

Comments

@mtoohey31
Copy link
Contributor

  • I have tested with the master version of typstfmt and not just typst-lsp

Describe the bug

When formatting a document that ends in a normal paragraph, trailing newlines are removed. This doesn't appear to happen with other syntax elements, such as lists, headings, code blocks, etc.

To Reproduce

Format a document consisting of the following string: "_Glaciers_ form an important part of the earth's climate system.\n". After formatting, this produces: "_Glaciers_ form an important part of the earth's climate system." (note that the trailing newline is missing).

@astrale-sharp
Copy link
Owner

Running on a bigger example, i get this result (input and output are the same, it's stable)

_Glaciers_ form an important part of the earth's climate system.
_Glaciers_ form an important part of the earth's climate system.
_Glaciers_ form an important part of the earth's climate system.

_Glaciers_ form an important part of the earth's climate system.
_Glaciers_ form an important part of the earth's climate system.
_Glaciers_ form an important part of the earth's climate system.

_Glaciers_ form an important part of the earth's climate system.
_Glaciers_ form an important part of the earth's climate system.
_Glaciers_ form an important part of the earth's climate system.⏎               

Only the last line has whitespaces removed, I think this could be improved by :
instead of always removing all whitespace, remove all whitespace and add \n

@mtoohey31
Copy link
Contributor Author

Only the last line has whitespaces removed, I think this could be improved by :
instead of always removing all whitespace, remove all whitespace and add \n

Yeah that matches what I saw in my testing when the last line was a paragraph. The suggested fix sounds good to me.

@mtoohey31
Copy link
Contributor Author

Spent a little more time looking at this. For the ending node kinds which I originally reported that the issue didn't appear for (lists, headings, etc.) it looks like there's an opposite bug in that it'll leave two trailing newlines instead of one if there's two or more in the unformatted document.

For example, the string "= this is a heading\n\n\n" becomes "= this is a heading\n\n" but I'd expect "= this is a heading\n".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants