Skip to content

Commit a53ac54

Browse files
feat: allow wiki body function to return string or string, highlight table
## Details Request: #228 Valid return types for `link.wiki.body` are now `nil`, `string` or `{ [1]: string, [2]: string|string[] }` where the first value is the text and the second is either a single highlight or a list of them.
1 parent 9e3393b commit a53ac54

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

Diff for: lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.0.17'
8+
M.version = '8.0.18'
99

1010
function M.check()
1111
M.start('version')

Diff for: lua/render-markdown/init.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ local M = {}
1515
---@field public extends? boolean
1616
---@field public parse fun(ctx: render.md.HandlerContext): render.md.Mark[]
1717

18+
---@class render.md.Text
19+
---@field [1] string text
20+
---@field [2] string|string[] highlights
21+
1822
---@class (exact) render.md.CallbackContext
1923
---@field public buf integer
2024

@@ -88,7 +92,7 @@ local M = {}
8892

8993
---@class (exact) render.md.UserWikiLink
9094
---@field public icon? string
91-
---@field public body? fun(ctx: render.md.LinkContext): string?
95+
---@field public body? fun(ctx: render.md.LinkContext): render.md.Text|string?
9296
---@field public highlight? string
9397

9498
---@class (exact) render.md.UserFootnote

Diff for: lua/render-markdown/render/base.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ local Iter = require('render-markdown.lib.iter')
22
local Str = require('render-markdown.lib.str')
33
local colors = require('render-markdown.colors')
44

5-
---@class render.md.line.Text
6-
---@field [1] string text
7-
---@field [2] string|string[] highlights
8-
9-
---@alias render.md.Line render.md.line.Text[]
5+
---@alias render.md.Line render.md.Text[]
106

117
---@class render.md.Renderer
128
---@field protected marks render.md.Marks

Diff for: lua/render-markdown/render/shortcut.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@ function Render:wiki_link()
127127
self:hide(ctx.start_col + 2, #ctx.destination + 1)
128128
end
129129
else
130+
local line = {}
131+
if type(body) == 'string' then
132+
table.insert(line, { icon .. body, highlight })
133+
else
134+
table.insert(line, { icon .. body[1], body[2] })
135+
end
130136
-- Inline icon & body, hide original text
131137
self.marks:add_over('link', self.node, {
132-
virt_text = { { icon .. body, highlight } },
138+
virt_text = line,
133139
virt_text_pos = 'inline',
134140
conceal = '',
135141
}, { 0, 1, 0, -1 })

Diff for: lua/render-markdown/types.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
---@class (exact) render.md.WikiLink
5656
---@field public icon string
57-
---@field public body fun(ctx: render.md.LinkContext): string?
57+
---@field public body fun(ctx: render.md.LinkContext): render.md.Text|string?
5858
---@field public highlight string
5959

6060
---@class (exact) render.md.Footnote

0 commit comments

Comments
 (0)