Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line feed following printable character is detected as an error for VimL #827

Closed
mmrwoods opened this issue Aug 21, 2023 · 5 comments
Closed

Comments

@mmrwoods
Copy link

mmrwoods commented Aug 21, 2023

I'm using glow to preview markdown within Vim and have noticed that for code blocks with the language set to vim, a line feed following a printable character is always shown as an error, e.g.

Screenshot 2023-08-21 at 12 31 49

The first code block here has the language set to vim, the other set to ruby, line feed following a printable character is always shown as an error for vim code blocks.

Glow depends on glamour to render markdown, and Glamour depends on Chroma to add syntax highlighting to code blocks.

It looks like the root cause of this issue is that Chroma is detecting a line feed following a printable character as an error, e.g.

$ echo "set foo" > foo.vim
$ chroma -f json foo.vim
[
  {"type":"NameOther","value":"set"},
  {"type":"Text","value":" "},
  {"type":"NameOther","value":"foo"},
  {"type":"Error","value":"\n"}
]

Glamour then highlights this as an error with a red background when rendering the code block, and that's what I end up seeing in the output from Glow. I can work around this telling glow to use custom styles and just override the rendering of errors in code blocks, but that's quite a nasty hack, so it would be really nice to see this fixed in Chroma (assuming Chroma is really the root cause here, and I may well have assumed incorrectly that Chroma is at fault).

I will try to find some time to fix this myself and open a PR, but I'm not familiar with this code at all, so It thought I'd open an issue first as this might be a simple fix for someone who knows the code.

@alecthomas
Copy link
Owner

I would suggest trying to replicate this in the Chroma playground, which will eliminate the many layers of indirection at play.

@mmrwoods
Copy link
Author

You can re-produce it in the playground, you will see the error span in the html output.

@alecthomas
Copy link
Owner

alecthomas commented Aug 21, 2023

Ah sorry, I somehow missed your invocation from the command line 🤦

Thanks for doing that.

@alecthomas
Copy link
Owner

Should be fixed. I also added a couple more keywords to vim, though there are millions of them so...

@mmrwoods
Copy link
Author

Fantastic, thank you very much 👍

mmrwoods added a commit to mmrwoods/glamour that referenced this issue Aug 29, 2023
Glamour renders \n as visible error when rendering VimL code blocks.
This is due to a bug in Chroma, now fixed, but yet to be released,
combined with the code block error style in Glamour rendering errors
with a red background (rather than Chroma default of using red text).

Updating Glamour styles to use red text rather than a red background
works around this, because there is no printable text to highlight.

See alecthomas/chroma#827 for more info

Although this might seem like a fugly hack to address one specific
issue, it seems a pretty reasonable default to me as Glamour has no
control over Chroma's parsing of code blocks, only the highlighting.
mmrwoods added a commit to mmrwoods/glamour that referenced this issue Aug 29, 2023
Glamour renders \n as visible error when rendering VimL code blocks.
This is due to a bug in Chroma, now fixed, but yet to be released,
combined with the code block error style in Glamour rendering errors
with a red background (rather than Chroma default of using red text).

See alecthomas/chroma#827 for more info

Updating Glamour styles to use red text rather than a red background
works around this, because there is no printable text to highlight.

For dracula I've swapped the code block error and generic deleted
styles, as otherwise both would be styled using the same red text.

Although this might seem like a fugly hack to address one specific
issue, it seems a pretty reasonable default to me as Glamour has no
control over Chroma's parsing of code blocks, only the highlighting.
mmrwoods added a commit to mmrwoods/glamour that referenced this issue Aug 29, 2023
Glamour renders \n as visible error when rendering VimL code blocks.
This is due to lexer bug in Chroma, now fixed, but yet to be released,
combined with the code block error style in Glamour rendering errors
with a red background (rather than Chroma default of using red text).

See alecthomas/chroma#827 for more info

Updating Glamour styles to use red text rather than a red background
works around this, because there is no printable text to highlight.

Note that for dracula, the style for generic deleted and error are now
the same, but this seems a reasonable compromise as generic deleted is
primarily for diffs, which seem less likely to result in lexer errors.

Although this might seem like a fugly hack to address one specific
issue, it seems a pretty reasonable default to me as Glamour has no
control over Chroma's parsing of code blocks, only the highlighting,
and barring a new release of Glamour with updated dependencies, cannot
do anything about Chroma lexer errors other than highlight them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants