Skip to content

Commit 965c222

Browse files
feat: wiki link config & language highlight override
## Details Request: #205 Add `link.wiki` config where users can specify icon and highlight group. Adds a `RenderMarkdownWikiLink` highlight which links to `RenderMarkdownLink` so nothing but the icon should change out of the box. Allow users to specify `code.highlight_language` which overrides the value from the icon provider. Minor other changes: - Remove logging of uncaptured groups, are no longer configurable - Refactor `markdown_inline` parser into separate renderers for inline code, links, and shortcuts - Change `render_modes` for `obsidian` preset to all modes, i.e. `true`
1 parent 0c6de74 commit 965c222

20 files changed

+323
-226
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- margin for paragraphs [#200](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/200)
88
[d20d19f](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/d20d19fa54965f6eb94558c0b84fe9a942169fb4)
99
- `on.attach` buffer callback [8b4149b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8b4149b122cfbf58b79a552ae89b3df2ddc39786)
10+
- allow empty lists for all heading properties [0c6de74](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/0c6de743a8d3c61b87bc7db9ab97dcda12ca6818)
1011

1112
### Bug Fixes
1213

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ require('render-markdown').setup({
321321
highlight = 'RenderMarkdownCode',
322322
-- Highlight for inline code
323323
highlight_inline = 'RenderMarkdownCodeInline',
324+
-- Highlight for language, overrides icon provider value
325+
highlight_language = nil,
324326
},
325327
dash = {
326328
-- Turn on / off thematic break rendering
@@ -488,6 +490,8 @@ require('render-markdown').setup({
488490
hyperlink = '󰌹 ',
489491
-- Applies to the fallback inlined icon
490492
highlight = 'RenderMarkdownLink',
493+
-- Applies to WikiLink elements
494+
wiki = { icon = '󱗖 ', highlight = 'RenderMarkdownWikiLink' },
491495
-- Define custom destination patterns so icons can quickly inform you of what a link
492496
-- contains. Applies to 'inline_link' and wikilink nodes.
493497
-- Can specify as many additional values as you like following the 'web' pattern below
@@ -734,6 +738,8 @@ require('render-markdown').setup({
734738
highlight = 'RenderMarkdownCode',
735739
-- Highlight for inline code
736740
highlight_inline = 'RenderMarkdownCodeInline',
741+
-- Highlight for language, overrides icon provider value
742+
highlight_language = nil,
737743
},
738744
})
739745
```
@@ -1006,6 +1012,8 @@ require('render-markdown').setup({
10061012
hyperlink = '󰌹 ',
10071013
-- Applies to the fallback inlined icon
10081014
highlight = 'RenderMarkdownLink',
1015+
-- Applies to WikiLink elements
1016+
wiki = { icon = '󱗖 ', highlight = 'RenderMarkdownWikiLink' },
10091017
-- Define custom destination patterns so icons can quickly inform you of what a link
10101018
-- contains. Applies to 'inline_link' and wikilink nodes.
10111019
-- Can specify as many additional values as you like following the 'web' pattern below
@@ -1094,9 +1102,10 @@ The table below shows all the highlight groups with their default link
10941102
| RenderMarkdownBullet | Normal | List item bullet points |
10951103
| RenderMarkdownQuote | @markup.quote | Block quote marker |
10961104
| RenderMarkdownDash | LineNr | Thematic break line |
1097-
| RenderMarkdownLink | @markup.link.label.markdown_inline | Image & hyperlink icons |
10981105
| RenderMarkdownSign | SignColumn | Sign column background |
10991106
| RenderMarkdownMath | @markup.math | LaTeX lines |
1107+
| RenderMarkdownLink | @markup.link.label.markdown_inline | Image & hyperlink icons |
1108+
| RenderMarkdownWikiLink | RenderMarkdownLink | WikiLink icon & text |
11001109
| RenderMarkdownUnchecked | @markup.list.unchecked | Unchecked checkbox |
11011110
| RenderMarkdownChecked | @markup.list.checked | Checked checkbox |
11021111
| RenderMarkdownTodo | @markup.raw | Todo custom checkbox |

doc/render-markdown.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 October 11
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 October 12
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -370,6 +370,8 @@ Default Configuration ~
370370
highlight = 'RenderMarkdownCode',
371371
-- Highlight for inline code
372372
highlight_inline = 'RenderMarkdownCodeInline',
373+
-- Highlight for language, overrides icon provider value
374+
highlight_language = nil,
373375
},
374376
dash = {
375377
-- Turn on / off thematic break rendering
@@ -537,6 +539,8 @@ Default Configuration ~
537539
hyperlink = '󰌹 ',
538540
-- Applies to the fallback inlined icon
539541
highlight = 'RenderMarkdownLink',
542+
-- Applies to WikiLink elements
543+
wiki = { icon = '󱗖 ', highlight = 'RenderMarkdownWikiLink' },
540544
-- Define custom destination patterns so icons can quickly inform you of what a link
541545
-- contains. Applies to 'inline_link' and wikilink nodes.
542546
-- Can specify as many additional values as you like following the 'web' pattern below
@@ -777,6 +781,8 @@ Code Block Configuration ~
777781
highlight = 'RenderMarkdownCode',
778782
-- Highlight for inline code
779783
highlight_inline = 'RenderMarkdownCodeInline',
784+
-- Highlight for language, overrides icon provider value
785+
highlight_language = nil,
780786
},
781787
})
782788
<
@@ -1035,6 +1041,8 @@ Link Configuration ~
10351041
hyperlink = '󰌹 ',
10361042
-- Applies to the fallback inlined icon
10371043
highlight = 'RenderMarkdownLink',
1044+
-- Applies to WikiLink elements
1045+
wiki = { icon = '󱗖 ', highlight = 'RenderMarkdownWikiLink' },
10381046
-- Define custom destination patterns so icons can quickly inform you of what a link
10391047
-- contains. Applies to 'inline_link' and wikilink nodes.
10401048
-- Can specify as many additional values as you like following the 'web' pattern below
@@ -1139,14 +1147,16 @@ The table below shows all the highlight groups with their default link
11391147

11401148
RenderMarkdownDash LineNr Thematic break line
11411149

1142-
RenderMarkdownLink @markup.link.label.markdown_inline Image & hyperlink
1143-
icons
1144-
11451150
RenderMarkdownSign SignColumn Sign column
11461151
background
11471152

11481153
RenderMarkdownMath @markup.math LaTeX lines
11491154

1155+
RenderMarkdownLink @markup.link.label.markdown_inline Image & hyperlink
1156+
icons
1157+
1158+
RenderMarkdownWikiLink RenderMarkdownLink WikiLink icon & text
1159+
11501160
RenderMarkdownUnchecked @markup.list.unchecked Unchecked checkbox
11511161

11521162
RenderMarkdownChecked @markup.list.checked Checked checkbox

lua/render-markdown/colors.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ M.colors = {
3535
Bullet = 'Normal',
3636
Quote = '@markup.quote',
3737
Dash = 'LineNr',
38-
Link = '@markup.link.label.markdown_inline',
3938
Sign = 'SignColumn',
4039
Math = '@markup.math',
40+
-- Links
41+
Link = '@markup.link.label.markdown_inline',
42+
WikiLink = 'RenderMarkdownLink',
4143
-- Checkboxes
4244
Unchecked = '@markup.list.unchecked',
4345
Checked = '@markup.list.checked',

lua/render-markdown/core/log.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ function M.node_info(capture, info)
4545
})
4646
end
4747

48-
---Encountered if user provides custom capture
49-
---@param group string
50-
---@param capture string
51-
function M.unhandled_capture(group, capture)
52-
M.add('error', 'unhandled capture', string.format('%s -> %s', group, capture))
53-
end
54-
5548
---Encountered if new type is seen for a particular group
5649
---@param language string
5750
---@param group string

lua/render-markdown/handler/markdown.lua

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local Context = require('render-markdown.core.context')
22
local list = require('render-markdown.core.list')
3-
local log = require('render-markdown.core.log')
43
local state = require('render-markdown.state')
54
local treesitter = require('render-markdown.core.treesitter')
65

@@ -80,13 +79,10 @@ end
8079
function Handler:parse(root)
8180
self.context:query(root, self.query, function(capture, info)
8281
local renderer = self.renderers[capture]
83-
if renderer ~= nil then
84-
local render = renderer:new(self.marks, self.config, self.context, info)
85-
if render:setup() then
86-
render:render()
87-
end
88-
else
89-
log.unhandled_capture('markdown', capture)
82+
assert(renderer ~= nil, 'Unhandled markdown capture: ' .. capture)
83+
local render = renderer:new(self.marks, self.config, self.context, info)
84+
if render:setup() then
85+
render:render()
9086
end
9187
end)
9288
return self.marks:get()

0 commit comments

Comments
 (0)