Skip to content

Commit 9ab9dad

Browse files
feat: scope highlight for html tags
## Details Request: #528 Adds an optional `scope_highlight` value that can be set for individual html tags which will be applied as the highlight group around the body of a tag's content. As part of this change all existing fields of html tags have been made optional, meaning `icon` and `highlight` are no longer required. In order to render an icon both `icon` and `highlight` are required, specifying one without the other will not cause errors, but will result in no icon being shown so really does not make sense to do. Similarly specifying no values for a tag will not cause errors, but will result in no rendering so also does not make sense to do.
1 parent 67f2c7c commit 9ab9dad

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,9 @@ require('render-markdown').setup({
853853
},
854854
-- HTML tags whose start and end will be hidden and icon shown.
855855
-- The key is matched against the tag name, value type below.
856-
-- | icon | gets inlined at the start |
857-
-- | highlight | highlight for the icon |
856+
-- | icon | optional icon inlined at start of tag |
857+
-- | highlight | optional highlight for the icon |
858+
-- | scope_highlight | optional highlight for item associated with tag |
858859
tag = {},
859860
},
860861
win_options = {

doc/render-markdown.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 September 17
1+
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 September 22
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -915,8 +915,9 @@ Default Configuration ~
915915
},
916916
-- HTML tags whose start and end will be hidden and icon shown.
917917
-- The key is matched against the tag name, value type below.
918-
-- | icon | gets inlined at the start |
919-
-- | highlight | highlight for the icon |
918+
-- | icon | optional icon inlined at start of tag |
919+
-- | highlight | optional highlight for the icon |
920+
-- | scope_highlight | optional highlight for item associated with tag |
920921
tag = {},
921922
},
922923
win_options = {

lua/render-markdown/config/html.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
---@field highlight string
99

1010
---@class (exact) render.md.html.Tag
11-
---@field icon string
12-
---@field highlight string
11+
---@field icon? string
12+
---@field highlight? string
13+
---@field scope_highlight? string
1314

1415
---@class render.md.html.Cfg
1516
local M = {}
@@ -30,8 +31,9 @@ M.default = {
3031
},
3132
-- HTML tags whose start and end will be hidden and icon shown.
3233
-- The key is matched against the tag name, value type below.
33-
-- | icon | gets inlined at the start |
34-
-- | highlight | highlight for the icon |
34+
-- | icon | optional icon inlined at start of tag |
35+
-- | highlight | optional highlight for the icon |
36+
-- | scope_highlight | optional highlight for item associated with tag |
3537
tag = {},
3638
}
3739

@@ -40,8 +42,9 @@ function M.schema()
4042
---@type render.md.Schema
4143
local tag = {
4244
record = {
43-
icon = { type = 'string' },
44-
highlight = { type = 'string' },
45+
icon = { optional = true, type = 'string' },
46+
highlight = { optional = true, type = 'string' },
47+
scope_highlight = { optional = true, type = 'string' },
4548
},
4649
}
4750
return require('render-markdown.config.base').schema({

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local state = require('render-markdown.state')
66
local M = {}
77

88
---@private
9-
M.version = '8.8.9'
9+
M.version = '8.8.10'
1010

1111
function M.check()
1212
M.start('versions')

lua/render-markdown/render/html/tag.lua

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,30 @@ function Render:run()
2121
if not config then
2222
return
2323
end
24+
2425
self.marks:over(self.config, true, start_tag, { conceal = '' })
2526
self.marks:over(self.config, true, end_tag, { conceal = '' })
26-
self.marks:start(self.config, false, self.node, {
27-
virt_text = { { config.icon, config.highlight } },
28-
virt_text_pos = 'inline',
29-
})
27+
28+
local icon, highlight = config.icon, config.highlight
29+
if icon and highlight then
30+
self.marks:start(self.config, false, self.node, {
31+
virt_text = { { icon, highlight } },
32+
virt_text_pos = 'inline',
33+
})
34+
end
35+
36+
local scope_highlight = config.scope_highlight
37+
local start_row = start_tag and start_tag.end_row or self.node.start_row
38+
local start_col = start_tag and start_tag.end_col or self.node.start_col
39+
local end_row = end_tag and end_tag.start_row or self.node.end_row
40+
local end_col = end_tag and end_tag.start_col or self.node.end_col
41+
if scope_highlight then
42+
self.marks:add(self.config, true, start_row, start_col, {
43+
end_row = end_row,
44+
end_col = end_col,
45+
hl_group = scope_highlight,
46+
})
47+
end
3048
end
3149

3250
return Render

0 commit comments

Comments
 (0)