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

Code highlighting colours the whole line in --md-code-hl-color #6017

Closed
4 tasks done
mocdaniel opened this issue Sep 14, 2023 · 12 comments
Closed
4 tasks done

Code highlighting colours the whole line in --md-code-hl-color #6017

mocdaniel opened this issue Sep 14, 2023 · 12 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@mocdaniel
Copy link

Context

I'm working on a freshly setup instance of Material for MkDocs and code highlighting seems to be off, compared to the results shown in the docs.

strange code highlighting

Bug description

Compared to the example from the docs, the result rendered on my end is

a) yellowish instead of blue

b) renders the whole line in --md-code-hl-color instead of just the left border and the remainder in --md-code-hl-color according to my dev tools:

.highlight .hll {
    background-color: var(--md-code-hl-color);
    display: block;
    margin: 0 -1.1764705882em;
    padding: 0 1.1764705882em;
}

My related configuration looks like this, I went by the book, i.e. the docs, if not mistaken:

markdown_extensions:
  - abbr
  - admonition
  - attr_list
  - md_in_html
  - pymdownx.details
  - pymdownx.highlight:
      use_pygments: true
      pygments_lang_class: true
      line_spans: __span
  - pymdownx.snippets
  - pymdownx.superfences
  - pymdownx.tabbed:
      alternate_style: true

Related links

I took a good look at the pygments/Highlight configuration:

as well as the docs regarding how to do highlighting and how to theme it:

I managed to get the bluish highlight working this way, but it still covered the whole line in the darker variant and omitted the --light variant altogether.

Reproduction

9.3.1-highlight-wrong-css.zip

Steps to reproduce

  1. Enable code highlighting as per my example and the documentation linked above
  2. Run mkdocs serve or mkdocs build
  3. Open the result and see code highlighting be different from the examples in the docs linked above

Browser

No response

Before submitting

@alexvoss
Copy link
Sponsor Collaborator

Hi,

thanks for the report and the reproduction. I have run it and see the same result as you do. However, when I compiled the reproduction earlier using my mkdocs install the issue did not appear. I was using the insiders version, though. Let me see if I can figure out where this comes from and get back to you. (I just started to contribute to material-mkdocs, so may take a little longer than squidfunk would, please bear with me.)

Cheers,

Alex

@alexvoss alexvoss added the needs investigation Issue must be investigated by the maintainers label Sep 15, 2023
@alexvoss
Copy link
Sponsor Collaborator

Quick update: I found no relevant differences in what mkdocs build produces once the info plugin is deactivated again. As far as I can tell, both the insiders and the public version produce the same html for the code segment. This suggests to me that it is not some regression in mkdocs-material but that the difference lies in the pymdownx plugin or its dependencies. I will have a look to see if I can spot what the crucial difference is there and figure out if the intended behaviour changed there or whether it is a regression on their part.

@facelessuser
Copy link
Contributor

@alexvoss, you are welcome to dig into pymdownx plugins if you like, but there have been no significant changes to the output format for a very long time. Line highlights are controlled by Pygments. We simply feed in the specified lines.

I am more than happy to fix anything if you were somehow able to point to pymdownx, but I am very skeptical.

@alexvoss
Copy link
Sponsor Collaborator

@facelessuser thanks, that is good to know. I will have a look - mainly to learn about the interactions between mkdocs, mkdocs-material, plugins and JS libraries / CSS used. I am a new contributor, so this is a useful exercise, methinks.

@alexvoss
Copy link
Sponsor Collaborator

Ok, I think I understand what is going on. There is a difference in _highlight.scss between the public version and the insiders version. Sorry, took me a little to figure out where to look. It seems trivial, so will make a pull request to see if squidfunk is happy to change it. This merely involves adding a box-shadow to the highlighted lines and changing the highlight color to be the same as shown in the documentation.

@alexvoss
Copy link
Sponsor Collaborator

Alright, pull request #6024 should fix this unwanted divergence between public and insider.

@mocdaniel
Copy link
Author

Wow, that was fast! Thanks for your efforts, let's wait for a merge ^^

@alexvoss
Copy link
Sponsor Collaborator

I managed to create a pull request but not actually request a review from squidfunk, which is now fixed.

squidfunk added a commit that referenced this issue Sep 18, 2023
fix: unwanted divergence public vs. insider #6017
@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open and removed needs investigation Issue must be investigated by the maintainers labels Sep 18, 2023
@squidfunk
Copy link
Owner

squidfunk commented Sep 18, 2023

Fixed via #6024, thanks to @alexvoss!

@squidfunk
Copy link
Owner

Released as part of 9.3.2.

@bforbis
Copy link

bforbis commented Apr 4, 2024

Hello, sorry to barge in here but could you take a look at the above linked ticket from backstage and tell me if this highlighting change is intentional, or do I have some sort of incompatibility? I have a large set of mkdocs documentation that was using these full line highlighting and they have now suddenly switched to only highlighting the side of the line with no background color once upgrading mkdocs-material. In my case I do not get the background color as linked in the docs

@squidfunk
Copy link
Owner

squidfunk commented Apr 5, 2024

As highlighting works without problems on our side, the problem can be anywhere, as I understand that Backstage does heavy customization of Material for MkDocs. Thus, I recommend stripping down customizations on your side one-by-one to isolate the cause of this. In any case, it's a downstream customization. You may ask on our discussion board for help, but we don't consider this to be an issue on our side, as everything is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

5 participants