Skip to content
New issue

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

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

Already on GitHub? # to your account

🐛 Markdown coloring problem #281

Closed
kjmph opened this issue Aug 7, 2020 · 9 comments · Fixed by #435
Closed

🐛 Markdown coloring problem #281

kjmph opened this issue Aug 7, 2020 · 9 comments · Fixed by #435

Comments

@kjmph
Copy link

kjmph commented Aug 7, 2020

I noticed when delta is used to color Markdown files, it shortens the frag to fit into a fixed width. However, if the frag was a link (which is often the case in Markdown), it messes up the coloring by not stopping the link coloring:

Screen Shot 2020-08-07 at 9 59 47 AM

Is there anything else I can supply for this issue?

@kjmph
Copy link
Author

kjmph commented Sep 17, 2020

I notice that I upgraded to 0.4.3, and I still see this behavior. Anything I can do to help?

@dandavison
Copy link
Owner

Hi @kjmph, thanks! Sorry to be slow, this does clearly look like a bug. It suggests that the highlighter is retaining state between the frag and the code, which should be easy to fix.

By the way, do you have anything special configured for your markdown highlighting? I wanted to reproduce your example, but in a very brief attempt I see that bat and delta are only highlighting HTML chunks in markdown files for me.

@kjmph
Copy link
Author

kjmph commented Oct 7, 2020

Sorry my slow response! I suppose I have ran the bat cache --build command, because I am using a few syntaxes locally and I haven't taken the time to open a PR against bat yet. However, none of them are related to Markdown. I see there were a few Markdown related changes around May? Perhaps it is due to me building the cache from bat's master branch?

For instance:

Screen Shot 2020-10-06 at 10 58 39 PM

@dandavison
Copy link
Owner

@kjmph sorry not to have fixed this yet.... Ok, I've found a way to reproduce this. Here I've captured some diff output and doctored it to have a hunk header ("frag") that will trigger the bug you've reported:

diff --git a/README.md b/README.md
index f1db9d6..ddeeff3 100644
--- a/README.html
+++ b/README.html
@@ -14,6 +14,8 @@ <img width=500px src="https://
   <img width=500px src="https://user-images.githubusercontent.com/52205/80056404-23745500-84f2-11ea-9ecd-832376faf2f1.png" alt="image" />
 </td></tr></table>

+This is a new line
+
 If you run emacs as a terminal application (`emacs -nw`) and colors are not being rendered correctly, then follow the instructions here: https://www.gnu.org/software/emacs/manual/html_node/efaq/Colors-on-a-TTY.html.

Now feeding that to delta on stdin reproduces it:

image

Thanks very much; I'll fix this.

Incidentally, the reason I wasn't getting detailed markdown highlighting was because my default theme (GitHub, ironically perhaps) doesn't seem to do that. However there is still one thing I'm baffled by: taking delta out of the equation, it seems that your git is giving you hunk headers ("frags") for markdown. But mine is not. For example, with the magit-delta repo at dandavison/magit-delta@b8526f8, I insert a new line like you did, and I don't get a hunk header (I just get @@ -14,6 +14,8 @@). Do you have a special gitattributes rule for markdown by any chance?

$ git --no-pager diff
diff --git a/README.md b/README.md
index f1db9d6..ddeeff3 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,8 @@
   <img width=500px src="https://user-images.githubusercontent.com/52205/80056404-23745500-84f2-11ea-9ecd-832376faf2f1.png" alt="image" />
 </td></tr></table>
 
+This is a new line
+
 If you run emacs as a terminal application (`emacs -nw`) and colors are not being rendered correctly, then follow the instructions here: https://www.gnu.org/software/emacs/manual/html_node/efaq/Colors-on-a-TTY.html.

@dandavison
Copy link
Owner

This is fixed in master (not released yet).

@kjmph
Copy link
Author

kjmph commented Dec 7, 2020

Interesting question you posed to me. I tried with a brand new user account (with no configuration), and I still see the hunk header. I tried on macOS and Linux, same deal. The output is mostly the equivalent of using diff -u -p <old> <new>. Where -p is shorthand for --show-c-function, which makes sense that this would be the default given the roots of git.

If anything, I followed the attributes gist you linked, and using the diff parser for Markdown removes the hunk header's context. I don't actually know how to answer your question, other than, no.. I don't think I'm doing anything special here.

@kjmph
Copy link
Author

kjmph commented Dec 7, 2020

Oh, and my apologies, I was so flummoxed by the question; I forgot to say thank you for fixing this. :)

@kjmph
Copy link
Author

kjmph commented Dec 7, 2020

If we go back in time, we see this was added in git v1.3.0: git/git@acb7257

While it has had a few modifications to date, it is still the default: https://github.com/git/git/blob/bf0a430f70b53f94454692c9ae8ddadd18891aaa/diff.c#L3596

I can see why it is preferred to use git attributes to change the search for the function header, lots more languages out there now.. Yet, any default git config should reproduce this error.

@dandavison
Copy link
Owner

This is released now (v0.4.5).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants