glow
glow copied to clipboard
Support hard line breaks
Please add support for hard line breaks.
https://spec.commonmark.org/0.30/#hard-line-breaks
Yes, please.
I too endorse this. To reproduce:
$ echo "hello\nworld" > test.md
$ cat test.md
hello
world
whereas
$ glow test.md
Wait... isn't markdown newline equal to two enters?
@gennaro-tedesco Your code should not work. In order to have a single line break be interpreted as a new line, you need to precede it with at least two spaces, like this (select the text to see that there are two spaces after hello
):
hello
world
Alternatively, you can end your line with a backslash \
like this:
hello\
world
Neither of the above examples work in glow though, which is why I created this issue.
@wantyapps
Wait... isn't markdown newline equal to two enters?
Not quite. Two line breaks in Markdown result in a new <p>
element whereas a line break preceded by either two or more spaces or a \
results in a <br>
element.
Compare Paragraphs with Hard line breaks.
Thank you for the clarification @jordanbtucker, I did not know, so bad on my side; however I do confirm that neither of the above (proper) examples work in Glow.
You're right, we're reflowing the text, but I think we can make that optional fairly easily.
@gennaro-tedesco Your code should not work. In order to have a single line break be interpreted as a new line, you need to precede it with at least two spaces, like this (select the text to see that there are two spaces after
hello
):hello world
Alternatively, you can end your line with a backslash
\
like this:hello\ world
Neither of the above examples work in glow though, which is why I created this issue.
@wantyapps
Wait... isn't markdown newline equal to two enters?
Not quite. Two line breaks in Markdown result in a new
<p>
element whereas a line break preceded by either two or more spaces or a\
results in a<br>
element.Compare Paragraphs with Hard line breaks.
Thank you for the clarification.
This is pretty crucial for me, I'm really enjoying glow for reading my markdown notes in terminal, but I use double-space line breaks all over the place and right now there's no way to get a single line break to render via glow at all as far as I can tell!
Is there a reason this has not been implemented yet? This makes glow render markdown incorrectly, in a pretty serious way
Looks like this is solved in the upstream dependency https://github.com/charmbracelet/glamour/pull/115, I updated glamour version in go.mod
:
github.com/charmbracelet/glamour v0.3.1-0.20210906181425-86a99924d7f6
and added:
diff --git a/main.go b/main.go
index b36d902..1852704 100644
--- a/main.go
+++ b/main.go
@@ -248,6 +248,7 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
gs,
glamour.WithWordWrap(int(width)),
glamour.WithBaseURL(baseURL),
+ glamour.WithPreservedNewLines(),
)
if err != nil {
return err
and my example file test.md
renders correctly:
hello
world
$ glow test.md
hello
world
@muesli @meowgorithm Any chance we could see a new release for glow addressing this issue? Looks simple enough, though I'm probably overlooking something (I'm new to go/the project)
@fiskhest Working on it! Just not sure yet if we shouldn't keep the current setting as our default.
That's great, thank you!
I might be misunderstanding your statement, but the current setting is not adhering to the markdown specification and as such should not be the default. If anything, the opposite should be the default, and the current behavior require setting a param.
I agree that the current behaviour shouldn't be preserved, I don't know why you would even offer a compatability flag with the current output, as it isn't standard and I really doubt there is anyone who wanted the behaviour of two-spaces-ending-a-line to not be a line break. Seems like adding needless complexity.
Also, does it also work with backslashes ending a line rather than 2 spaces?
Any updates on this matter @muesli ?
Also curious about updates on this? @muesli I agree that this behavior should be the default. This issue unfortunately makes using Glow unusable for me. It's a pretty significant compatibility issue.
I think I have the same behaviour.
A <br>
tag is shown as a double space rather than a break line in glow.
$ cat test.md
Hello
<br>
World
Expectation:
$ glow test.md
Hello
World
Reality:
$ glow test.md
Hello World
I don't know if this is directly linked to this issue as you guys seem to talk about double space and not specifically about <br>
tags but that's the same thing right ? (Sorry if I'm wrong).
Anyway, I don't know if it is still planned to fix this (as it has been raised a long time ago) but I would also be interested by a fix :) I wish I could help more with that...
By the way, thanks for your amazing work !
@Antiz96 That is a separate but valid issue. I recommend opening an issue for it in the glamour repo, which is the code base that performs the markdown conversion. Technically, this issue should be there too.
@jordanbtucker Thanks for your answer !
I didn't knew about glamour. After looking at the currently opened issues in the glamour repo, it seems like a similar issue has already been raised here.
It is mostly about double spaces and back slashes, not specifically about <br>
tags tho...
But if at least one of those 3 options works, I'd be fine with it :)
I'm still going to open an issue anyway in order to get it documented.
Thanks again !
@jordanbtucker technically this issue is solved in glamour, only need a default setting flipped in glow.
@fiskhest @jordanbtucker So should I still post in glamour repo or glow then ?
@Antiz96 sadly, I don't know or have the time to verify that your issue is resolved in glamour or not - you could follow the instructions posted in my comment earlier in this issue thread and verify that yourself.
@muesli Are there any future plans for this?
I think this is a serious problem making glow unusable and inconsistent with other md viewers.
It should be specified in the README along with the plans and current workaround.
@muesli, FWIW, this impacts the help
command I'm implementing for the Elvish shell. There are a few commands with explicitly multiline usage text. For example: https://elv.sh/ref/builtin.html#str-cmp. That is rendered thusly by glow
regardless of whether I end each line with two spaces, a backslash or <br/>
:
< $number... # less <= $number... # less or equal == $number... # equal !=
$number... # not equal > $number... # greater >= $number... # greater or
equal
I've tested @fiskhest's solution (https://github.com/charmbracelet/glow/issues/212#issuecomment-921632355) and it still works very well.
As you can see from above I've created a PR #362 based on that.
Hopefully this is the right way to fix it and gets merged soon.
Working on it! Just not sure yet if we shouldn't keep the current setting as our default.
This would technically be a breaking change. So, if users are relying on current behavior, or if they expect minor versions of glow to not change the output, then I would recommend taking a Semantic Versioning approach and implement CommonMark compliant output behind an optional flag in this version. When you release v2, the setting can be turned on by default.
If you've already been changing output in minor versions of glow (i.e. not adhering to semver) then I would just turn the setting on by default.
Please don't make this not default. People either don't use this functionality or came to complain about it on this issue. Just my thoughts.
Please don't make this not default. People either don't use this functionality or came to complain about it on this issue. Just my thoughts.
I second this motion.
I've updated my comments to point to the latest version of the CommonMark spec. No conformance changes were made to hard line breaks. Only changes to the prose occurred in that section.
FWIW, this impacts the
help
command I'm implementing for the Elvish shell.
@krader1961 Wouldn't that be better placed in a code block, like it is in the doc comment? Glow will maintain line breaks inside code blocks, even without two spaces at the end of the line.
I think preserving current behavior shouldn't even be an option.
I wrote some thoughts about it in https://github.com/charmbracelet/glow/pull/362#issuecomment-1188688606.
TLDR it should be applied right away in the next release as default.
FWIW, this impacts the
help
command I'm implementing for the Elvish shell.@krader1961 Wouldn't that be better placed in a code block, like it is in the doc comment? Glow will maintain line breaks inside code blocks, even without two spaces at the end of the line.
No, because people don't write markdown files to make them compatible with glow. That's why I agree with @WieeRd 's latest comment
@magnus-ISU I wasn't saying that they should change their Markdown to accommodate glow. I was saying that the example they referenced is already in a code block, so I don't see why they would need to use hard line breaks at all.
But you do make a good point that Markdown users generally don't write Markdown to render with glow, at least not exclusively. They write it to render as HTML typically on some platform like GitHub or in a static site generator like Jekyll, and rendering a line break by ending a line with two spaces has been a feature of Markdown since its inception. So, regardless of breaking changes, the current behavior should be treated like a bug, and I don't see a reason to keep the behavior either.