folke / tokyonight.nvim

🏙 A clean, dark Neovim theme written in Lua, with support for lsp, treesitter and lots of plugins. Includes additional themes for Kitty, Alacritty, iTerm and Fish.
Apache License 2.0
6.44k stars 433 forks source link

feature: Allow users to configure codeblock background when using markdown #614

Closed kevinrobayna closed 3 months ago

kevinrobayna commented 3 months ago

Did you check the docs?

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

With the recent change in https://github.com/LazyVim/LazyVim/pull/4139 to use MeanderingProgrammer/markdown.nvim. I lost the ability to hack the bg colour of the code blocks so that my full IDE was transparent.

vim.cmd([[highlight CodeBlock guibg=none]])

image __

Describe the solution you'd like

Currently, with toyko you can configure several different styles and I think letting the user choose how the code_blocks appear might be beneficial as I can see this being a user preference

return {
  "tokyonight.nvim",
  opts = function()
    return {
      style = "moon",
      transparent = true,
      styles = {
        sidebars = "transparent",
        floats = "transparent",
      },
    }
  end,
}
styles = {
  code_blocks = "transparent",
  sidebars = "transparent",
  floats = "transparent",
},

Describe alternatives you've considered

I tried to keep using my hack but it does not work now (I didn't try too hard if I'm honest)

Additional context

I'd be happy to give it a go but I wanted to ask first

folke commented 3 months ago

The hl group is RenderMarkdownCode

kevinrobayna commented 3 months ago

The hl group is RenderMarkdownCode

oh! That solves a bit of the issue.

There's a weird black line under the code block.

image

So you would not be interested in allowing the users to avoid the highlight group setting?

folke commented 3 months ago

You can already easily override the group using on_highlights. Not needed to add a separate config option for that. That weird black line you see is probably the thin border for the markdown.nvim plugin. I thought that was the same hl group. No idea. Check the tokyonight.nvim and markdown.nvim code

kevinrobayna commented 3 months ago

I figured it out. Thank you for your pointers!

image

  {
    "MeanderingProgrammer/markdown.nvim",
    opts = {
      code = {
        -- NOTE: Remove borders of code blocks
        above = "",
        below = "",
      },
    },
    config = function(_, opts)
      require("render-markdown").setup(opts)
      -- NOTE: This needs to be after the setup
      vim.cmd([[highlight RenderMarkdownCode guibg=none]])
      vim.cmd([[highlight RenderMarkdownCodeBorder guibg=none]])
    end,
  },

This is the config I wrote to make the colours were applied and also removed the characters for the borders that the plugin defaults to.

I tried doing it on the tokyo config but it was being overridden for some reason

        on_highlights = function(hl, c)
          hl.RenderMarkdownCode = {
            bg = c.none,
          }
          hl.RenderMarkdownCodeBorder = {
            bg = c.none,
          }
        end,