Skip to content

Commit

Permalink
feat: Add markdown_header_marks opt to restore headers marks highli…
Browse files Browse the repository at this point in the history
…ghts
  • Loading branch information
polirritmico committed Mar 8, 2024
1 parent 1e5d64a commit c254a05
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Monokai Nightasty comes with these defaults:
dim_inactive = false, -- dims inactive windows
lualine_bold = true, -- Lualine headers will be bold or regular.
lualine_style = "default", -- "dark", "light" or "default" (Follows dark/light style)
markdown_header_marks = false, -- Add headers marks highlights (the `#` character) to Treesitter highlight query

--- You can override specific color groups to use other groups or a hex color
--- function will be called with the theme ColorScheme table
Expand Down Expand Up @@ -258,6 +259,15 @@ To use the generated config files with the corresponding external tool, check
the `extras` folder, copy, link or reference the file in each setting. Refer to
the respective program documentation.

### Markdown files

Nvim Tressiter no longer provide highlights captures for the headers `#` marks.
This plugin provide them for long as they work or nvim-treesitter provide any
way to highlight them.

To enable them, set the `markdown_header_marks` option to `true` (defaults to
`false`).

### Tmux

Just source the theme file:
Expand Down Expand Up @@ -366,4 +376,4 @@ some_plugin_config.another = util.darken(colors.bg, 0.3)
This plugin is made mainly for my personal use, but suggestions, issues, or pull
requests are very welcome.

Enjoy
***Enjoy***
16 changes: 14 additions & 2 deletions doc/monokai-nightasty.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*monokai-nightasty.nvim.txt* For Neovim >= 0.9 Last change: 2024 February 25
*monokai-nightasty.nvim.txt* For Neovim >= 0.9 Last change: 2024 March 08

==============================================================================
Table of Contents *monokai-nightasty.nvim-table-of-contents*
Expand All @@ -12,6 +12,7 @@ Table of Contents *monokai-nightasty.nvim-table-of-contents*
- Advanced configuration |monokai-nightasty.nvim-advanced-configuration|
6. Colors and Highlights |monokai-nightasty.nvim-colors-and-highlights|
7. Extras |monokai-nightasty.nvim-extras|
- Markdown files |monokai-nightasty.nvim-markdown-files|
- Tmux |monokai-nightasty.nvim-tmux|
- Using with other plugins |monokai-nightasty.nvim-using-with-other-plugins|
8. Color Palettes |monokai-nightasty.nvim-color-palettes|
Expand Down Expand Up @@ -131,6 +132,7 @@ Monokai Nightasty comes with these defaults:
dim_inactive = false, -- dims inactive windows
lualine_bold = true, -- Lualine headers will be bold or regular.
lualine_style = "default", -- "dark", "light" or "default" (Follows dark/light style)
markdown_header_marks = false, -- Add headers marks highlights (the `#` character) to Treesitter highlight query

--- You can override specific color groups to use other groups or a hex color
--- function will be called with the theme ColorScheme table
Expand Down Expand Up @@ -261,6 +263,16 @@ the `extras` folder, copy, link or reference the file in each setting. Refer to
the respective program documentation.


MARKDOWN FILES *monokai-nightasty.nvim-markdown-files*

Nvim Tressiter no longer provide highlights captures for the headers `#` marks.
This plugin provide them for long as they work or nvim-treesitter provide any
way to highlight them.

To enable them, set the `markdown_header_marks` option to `true` (defaults to
`false`).


TMUX *monokai-nightasty.nvim-tmux*

Just source the theme file:
Expand Down Expand Up @@ -340,7 +352,7 @@ LIGHT STYLE *monokai-nightasty.nvim-light-style*
This plugin is made mainly for my personal use, but suggestions, issues, or
pull requests are very welcome.

Enjoy
**Enjoy**

Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

Expand Down
8 changes: 7 additions & 1 deletion lua/monokai-nightasty/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local defaults = {
dim_inactive = false, -- dims inactive windows
lualine_bold = true, -- Lualine headers will be bold or regular.
lualine_style = "default", -- "dark", "light" or "default" (Follows dark/light style)
markdown_header_marks = false, -- Add headers marks highlights (the `#` character) to Treesitter highlight query

--- You can override specific color groups to use other groups or a hex color
--- function will be called with a ColorScheme table
Expand All @@ -40,11 +41,16 @@ local defaults = {

---@type Config
---@diagnostic disable-next-line: missing-fields
M.options = {}
M.options = M.options or {}

---@param options Config?
function M.setup(options)
M.options = vim.tbl_deep_extend("force", {}, defaults, options or {})
-- HACK: Add back the removed Treesitter header markers. Use this workaround
-- until they add something similar (if so)
if M.options.markdown_header_marks == true then
require("monokai-nightasty.extras.ts_markdown").set_headers_marks()
end
end

---@param options Config?
Expand Down
24 changes: 24 additions & 0 deletions lua/monokai-nightasty/extras/ts_markdown.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local M = {}

---Add markdown header marks into Treesitter highlights queries
-- HACK: Restore markdown header markers:
-- https://github.com/nvim-treesitter/nvim-treesitter/issues/6260
function M.set_headers_marks()
vim.treesitter.query.set(
"markdown",
"highlights",
[=[; extends
(atx_heading (atx_h1_marker) @markup.heading.1.marker)
(atx_heading (atx_h2_marker) @markup.heading.2.marker)
(atx_heading (atx_h3_marker) @markup.heading.3.marker)
(atx_heading (atx_h4_marker) @markup.heading.4.marker)
(atx_heading (atx_h5_marker) @markup.heading.5.marker)
(atx_heading (atx_h6_marker) @markup.heading.6.marker)
(setext_heading (setext_h1_underline) @markup.heading.1.marker)
(setext_heading (setext_h2_underline) @markup.heading.2.marker)
]=]
)
end

return M
3 changes: 3 additions & 0 deletions lua/monokai-nightasty/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function M.load(opts)
-- Set MonokaiToggleLight
if not M.loaded then
vim.cmd("command! MonokaiToggleLight lua MonokaiToggleLight()")
if opts and opts.markdown_header_marks == true then
require("monokai-nightasty.extras.ts_markdown").set_headers_marks()
end
M.loaded = true
end

Expand Down

0 comments on commit c254a05

Please sign in to comment.