glow icon indicating copy to clipboard operation
glow copied to clipboard

fix: support hard line breaks

Open WieeRd opened this issue 3 years ago • 10 comments

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

WieeRd avatar Jul 16 '22 10:07 WieeRd

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.

WieeRd avatar Jul 19 '22 07:07 WieeRd

@muesli https://github.com/charmbracelet/glow/issues/212#issuecomment-921692403 image 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.

WieeRd avatar Jul 26 '22 10:07 WieeRd

The change itself is sound, thank you.

muesli avatar Jul 26 '22 11:07 muesli

Great! What's stopping this from getting merged then?

WieeRd avatar Jul 26 '22 12:07 WieeRd

@muesli I just ran into this. Any way this could be merged?

subterfugue avatar Sep 17 '22 14:09 subterfugue

It's been 2 months and I'm slowly losing hope

WieeRd avatar Sep 18 '22 09:09 WieeRd

Please, just a bit more patience. I'll circle back to a maintenance round of glow soon.

muesli avatar Sep 18 '22 14:09 muesli

It's been over a year and I lost hope a long time ago...

@muesli how soon is soon?

fiskhest avatar Oct 18 '22 08:10 fiskhest

Soon™

WieeRd avatar Oct 22 '22 20:10 WieeRd

bump

syabil-carbon6 avatar Nov 03 '22 10:11 syabil-carbon6

Is this small issue discovered back in 2020 really going to remain unsolved till 2023 ☹️

WieeRd avatar Dec 30 '22 09:12 WieeRd

@muesli I still don't understand why this cannot be merged right away.

WieeRd avatar Jan 17 '23 12:01 WieeRd

@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 avatar Jan 17 '23 12:01 muesli

@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 ❤️

syabil-carbon6 avatar Jan 17 '23 14:01 syabil-carbon6

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...

Exagone313 avatar Dec 28 '23 15:12 Exagone313

You are wrong. It fully comply with Markdown specs: https://www.markdownguide.org/basic-syntax/#line-breaks

skiwichu avatar Dec 28 '23 15:12 skiwichu

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.

Exagone313 avatar Dec 28 '23 15:12 Exagone313

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.

skiwichu avatar Dec 28 '23 16:12 skiwichu

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

Exagone313 avatar Dec 28 '23 16:12 Exagone313