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

feature: Highlight groups #70

Closed
scottmckendry opened this issue Jul 17, 2024 · 8 comments
Closed

feature: Highlight groups #70

scottmckendry opened this issue Jul 17, 2024 · 8 comments
Labels
enhancement New feature or request

Comments

@scottmckendry
Copy link
Contributor

Is your feature request related to a problem? Please describe.

There is currently no easy way for colorsheme maintainers to add support for this plugin. While the defaults are sensible, there are a few things one might like to change to give the best out-of-the-box experience without users having to make too many changes in the config.

Describe the solution you'd like

Each component currently has one or more "highlight` properties that use either tree-sitter groups or a default Neovim highlight group.

What I propose is to define new highlight groups in the plugin that link to the existing highlights. This can be executed somewhere in the plugin's setup() logic.

For example, for headings, you might add something to the effect of:

vim.api.nvim_set_hl(0, "RenderMarkdownHeading1", { link = "@markup.heading.1.markdown", default = true })
vim.api.nvim_set_hl(0, "RenderMarkdownHeading2", { link = "@markup.heading.2.markdown", default = true })

vim.api.nvim_set_hl(0, "RenderMarkdownHeading1Bg", { link = "DiffAdd", default = true })
vim.api.nvim_set_hl(0, "RenderMarkdownHeading2Bg", { link = "DiffChange", default = true })

default = true is important here as it preserves the current setting if the highlight group is already defined somewhere else (like in a colorscheme 😉)

The naming convention I've used in the example is just a suggestion. Feel free to use whatever you see fit - the namespace is global so unique-ness is important.

Using links keeps the current highlight groups the same for existing users, so no breaking changes should be expected. But it allows colorschemes to adopt their own styling should they choose to add support in the future.

Describe alternatives you've considered

N/A

Additional information

For a good example of how to define many highlight groups at once, I recommend looking at Folke's implementation in trouble.nvim:
https://github.com/folke/trouble.nvim/blob/main/lua/trouble/config/highlights.lua

@scottmckendry scottmckendry added the enhancement New feature or request label Jul 17, 2024
MeanderingProgrammer added a commit that referenced this issue Jul 18, 2024
…port colorschemes

## Details

Request: #70

The current approach of using standard highlight groups works well,
however if color scheme maintainers wish to support this plugin specifically
it will impact everywhere else the highlight groups are used.

To improve this add a level of indirection. Create custom highlights
that link to all the same defaults as currently used. That way changing
the underlying links still has the same impact as well as being backwards
compatible. Users setting custom values also remain unaffected.

However color scheme maintainers can override the highlights used by
this plugin giving them the ability to apply their theme better to this
plugin specifically.

I do not think this will be a very common trend, but I am more than
happy to support it. Add a table to the README with all the highlghts
and default links.
@MeanderingProgrammer
Copy link
Owner

Proposal makes sense to me, the idea of setting a default = true link to allow color schemes to override the value is neat. Super simple and powerful.

I implemented it here: 0f32655, and used the RenderMarkdown prefix as suggested.

Added a table with all of the highlights and their defaults to the README as well: https://github.com/MeanderingProgrammer/markdown.nvim?tab=readme-ov-file#colors

LMK if I missed anything, really curious how you go about integrating this. Thanks for the interest and the proposal!

@scottmckendry
Copy link
Contributor Author

This is excellent! Pretty much exactly what I had in mind 🙂

The only (minor) changes I would suggest would be:

  1. Add H4-H6 bg groups, linking all three to the H3Bg group. This will allow me to consistently set backgrounds that match headings.
    image
  2. In the image above, all the signs are the same color. I think it would be a nice addition to have the sign match the fg color of each heading.
  3. Create a group for the border at the bottom of code blocks. I don't see a straightforward way of setting this currently.
    image

@scottmckendry
Copy link
Contributor Author

Ignore #2 in my previous comment! I've got it working now :)

image

@scottmckendry
Copy link
Contributor Author

It looks like 3 was due to the same error I was running into with the signs. This looks good now:
image

That just leaves heading 4-6 background groups.

@MeanderingProgrammer
Copy link
Owner

Ah, understandable, updated here: 6aa19e9.

Am curious what updates you needed to make to resolve issues 2 & 3? Since if you had a fg defined for headings 1 through 6 I would expect the signs to be correctly colored. Similar but both a fg and a bg for the code block highlight.

@scottmckendry
Copy link
Contributor Author

Legend! Thanks so much @MeanderingProgrammer!

Here's the final look:
image

scottmckendry added a commit to scottmckendry/cyberdream.nvim that referenced this issue Jul 19, 2024
thanks to the latest updates in MeanderingProgrammer/render-markdown.nvim#70 we
now have offical support for markdown.nvim!
@MeanderingProgrammer
Copy link
Owner

Looks great!

@jeremija
Copy link
Contributor

@scottmckendry how did you solve the issue with horizontal line color? I just opened an issue #77, but now I'm wondering if there's something wrong with my config perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants