godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.94k stars 20.17k forks source link

Saving to .md files in the editor removes trailing spaces (changing markdown syntax unintentionally) #96440

Open Alzurana opened 1 week ago

Alzurana commented 1 week ago

Tested versions

System information

Windows 10 - Godot 4.3 - Forward+

Issue description

The godot editor recognizes .md as a file format. I can open such files as text files in and crate a new file of that type. It's part of the list of possible text formats. I edited my readme.md directly in the godot editor and saved it. I then noticed that it removed trailing spaces, which are used to denote newlines in markdown. Godot shouldn't sanitize these upon saving a .md as that effectively changes the syntax

Steps to reproduce

Minimal reproduction project (MRP)

markdown-example.zip

Alzurana commented 1 week ago

While investigating I found that trimming are editor settings: https://github.com/godotengine/godot/blob/61598c5c88d95b96811d386cb20d714c35f4c6d7/editor/plugins/script_editor_plugin.cpp#L2942 This setting is false by default.

This opens up the question if it should be configurable which file formats exept from trim settings as they are generally very useful for any other format.

I would propose a new setting that comes with trimming settings, that determines file types exempt from trimming. It would be a single setting to determine these exceptions. It would default to .md files.

akien-mga commented 1 week ago

Godot shouldn't sanitize these upon saving a .md as that effectively changes the syntax

Does Markdown really use trailing whitespace as syntax? That's such a bad design :( Tested it and it seems to be used for manual line breaks indeed... I tend to prefer an explicit <br> so it's clear.

For the record, most IDEs and text editors I've used have options to trim whitespace on save, and I haven't ever seen it specific to only some types of files.

I think excluding Markdown files specifically would probably solve the issue in your case, and be a bother for other users who don't rely on Markdown's double trailing spaces to make line breaks.

We could add another option to allow configuring which file types should be exempted from this feature but an option to configure an option starts becoming pretty niche and something that only people who somehow land on this issue would discover IMO.

Alzurana commented 1 week ago

That's such a bad design :(

I agree, I never liked it. It seems to be controversial as well: https://www.markdownguide.org/basic-syntax/#line-break-best-practices
Trailing whitespace removal is not the default setting anyways. I had to enable it, I guess that's why few stumbled across this. Maybe it is enough to just add to the config description that enabling this can trim newlines in markdown?

aaronfranke commented 1 week ago

Note that you don't actually need trailing spaces in Markdown. While \s\s\n (space, space, newline) is a line break in Markdown, so is \\n (backslash at the end of the line). You may wish to switch over to this style in your Markdown files to prevent tools (even outside Godot) from automatically trimming trailing space characters.