fix: support hard line breaks
Fixes #212 based on @fiskhest's comment.
Updated glamour version and added a line in main.go to preserve line breaks.
Test case:
$ cat test.md
two spaces
break tag<br>
backslash\
hello world
Current behavior:
$ glow test.md
two spaces break tag backslash hello world
After this patch:
$ go build
$ ./glow test.md
two spaces
break tag
backslash
hello world
I think preserving current behavior (ignore hard line breaks) shouldn't even be an option.
Whether this feature should be an opt-in flag or not has been discussed multiple times in #212,
with concerns regarding this can be a "breaking change" since it changes the output of glow.
Here's why I think it is unnecessary:
1. When using glow itself to read markdown files
The breaking changes does not matter at all.
Current behavior is just considered as an annoying bug,
hurting the readability and consistency with other Markdown readers.
2. When using glow as backend to other TUI apps
If the creator of the app wanted to preserve current behavior after this patch,
it can easily be done by modifying the content before passing it to glow.
Substitute ␣␣\n, \\\n to \n and remove <br> and that's it!
Adding the option to preserve current behavior is unnecessary.
On the contrary, the reverse is near impossible in current state.
Line breaks in the input will be ignored, and there is no way to know where they were in the output.
3. Why would anyone want to remove hard line breaks?
It's just beyond my understanding.
@muesli https://github.com/charmbracelet/glow/issues/212#issuecomment-921692403
I'm used to open source issues taking 3+ years to get solved, but can you at least review my PR please?
I would appreciate this amazing tool much more if this issue gets fixed.
The change itself is sound, thank you.
Great! What's stopping this from getting merged then?
@muesli I just ran into this. Any way this could be merged?
It's been 2 months and I'm slowly losing hope
Please, just a bit more patience. I'll circle back to a maintenance round of glow soon.
It's been over a year and I lost hope a long time ago...
@muesli how soon is soon?
Soon™
bump
Is this small issue discovered back in 2020 really going to remain unsolved till 2023 ☹️
@muesli I still don't understand why this cannot be merged right away.
@muesli I still don't understand why this cannot be merged right away.
As mentioned, the change looks fine and it's very likely we will merge it before the next release. I could just click merge and assume everything will be fine right now, but I hope you'll appreciate us actually testing changes, especially with a few of the projects that use glow as a dependency now.
Please keep in mind that we're still a small team and we're also working on other fairly popular projects. Jumping back and forth between them will typically just slow things down. As such we've decided to first finish up on some important bubbletea, lipgloss, and glamour releases, which are all dependencies of glow and its upcoming release.
Sorry it's taking so long, I know how painful it can feel.
@muesli I know people dont say this very often but thank you very much to the team and you for all of your time and effort maintaining glow ❤️
Are you sure you don't want this to be an option? This goes against Markdown spec. I ended up self building Glow to remove this change...
You are wrong. It fully comply with Markdown specs: https://www.markdownguide.org/basic-syntax/#line-breaks
You are wrong. It fully comply with Markdown specs: https://www.markdownguide.org/basic-syntax/#line-breaks
You link is convenient because it doesn't follow what the CommonMark specification says on soft line breaks: https://spec.commonmark.org/0.30/#soft-line-breaks
EDIT: As it's not clear what I mean. The CommonMark specification is for rendering Markdown to HTML, but glow is a tool that renders Markdown to the terminal. As a line break in HTML is rendered as a space by web browsers, supposedly glow should render line breaks as spaces too.
Interesting. I've never heard of CommonMark. Authors literally say: "John Gruber’s canonical description of Markdown’s syntax does not specify the syntax unambiguously." what makes the issue you pointed to.
On the other hand, when we move the discussion to hard line breaks: https://spec.commonmark.org/0.30/#hard-line-breaks you get two spaces are a valid option.
Yes, I just found the pull request related to the commit that changed the behavior.
If you remove glamour.WithPreservedNewLines(), it doesn't support hard line-breaks either. So removing the line is not the right way to solve both soft and hard line-break support.
Related issue: https://github.com/charmbracelet/glamour/issues/84