Skip to content

Commit ceff151

Browse files
feat: add footnote icon
## Details Adds the ability to set an icon that appears before footnotes along with a default value of `󰯔 `. To go back to having no icon users will need to set the value to the empty string: ```lua require('render-markdown').setup({ link = { footnote = { icon = '' } }, }) ```
1 parent e174f52 commit ceff151

File tree

8 files changed

+38
-75
lines changed

8 files changed

+38
-75
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ require('render-markdown').setup({
757757
footnote = {
758758
-- Turn on / off footnote rendering.
759759
enabled = true,
760+
-- Inlined with content.
761+
icon = '󰯔 ',
760762
-- Replace value with superscript equivalent.
761763
superscript = true,
762764
-- Added before link content.
@@ -1497,6 +1499,8 @@ require('render-markdown').setup({
14971499
footnote = {
14981500
-- Turn on / off footnote rendering.
14991501
enabled = true,
1502+
-- Inlined with content.
1503+
icon = '󰯔 ',
15001504
-- Replace value with superscript equivalent.
15011505
superscript = true,
15021506
-- Added before link content.

doc/render-markdown.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ Default Configuration ~
819819
footnote = {
820820
-- Turn on / off footnote rendering.
821821
enabled = true,
822+
-- Inlined with content.
823+
icon = '󰯔 ',
822824
-- Replace value with superscript equivalent.
823825
superscript = true,
824826
-- Added before link content.
@@ -1539,6 +1541,8 @@ Link Configuration ~
15391541
footnote = {
15401542
-- Turn on / off footnote rendering.
15411543
enabled = true,
1544+
-- Inlined with content.
1545+
icon = '󰯔 ',
15421546
-- Replace value with superscript equivalent.
15431547
superscript = true,
15441548
-- Added before link content.

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.9.2'
9+
M.version = '8.9.3'
1010

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

lua/render-markdown/lib/converter.lua

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,26 @@
11
---@class render.md.Converter
22
local M = {}
33

4+
-- stylua: ignore
45
---@private
56
M.superscripts = {
6-
[' '] = ' ',
7-
['('] = '',
8-
[')'] = '',
7+
[' '] = ' ', ['('] = '', [')'] = '',
98

10-
['0'] = '',
11-
['1'] = '¹',
12-
['2'] = '²',
13-
['3'] = '³',
14-
['4'] = '',
15-
['5'] = '',
16-
['6'] = '',
17-
['7'] = '',
18-
['8'] = '',
19-
['9'] = '',
9+
['0'] = '', ['1'] = '¹', ['2'] = '²', ['3'] = '³', ['4'] = '',
10+
['5'] = '', ['6'] = '', ['7'] = '', ['8'] = '', ['9'] = '',
2011

21-
['a'] = '',
22-
['b'] = '',
23-
['c'] = '',
24-
['d'] = '',
25-
['e'] = '',
26-
['f'] = '',
27-
['g'] = '',
28-
['h'] = 'ʰ',
29-
['i'] = '',
30-
['j'] = 'ʲ',
31-
['k'] = '',
32-
['l'] = 'ˡ',
33-
['m'] = '',
34-
['n'] = '',
35-
['o'] = '',
36-
['p'] = '',
37-
['q'] = nil,
38-
['r'] = 'ʳ',
39-
['s'] = 'ˢ',
40-
['t'] = '',
41-
['u'] = '',
42-
['v'] = '',
43-
['w'] = 'ʷ',
44-
['x'] = 'ˣ',
45-
['y'] = 'ʸ',
12+
['a'] = '', ['b'] = '', ['c'] = '', ['d'] = '', ['e'] = '',
13+
['f'] = '', ['g'] = '', ['h'] = 'ʰ', ['i'] = '', ['j'] = 'ʲ',
14+
['k'] = '', ['l'] = 'ˡ', ['m'] = '', ['n'] = '', ['o'] = '',
15+
['p'] = '', ['q'] = nil, ['r'] = 'ʳ', ['s'] = 'ˢ', ['t'] = '',
16+
['u'] = '', ['v'] = '', ['w'] = 'ʷ', ['x'] = 'ˣ', ['y'] = 'ʸ',
4617
['z'] = '',
4718

48-
['A'] = '',
49-
['B'] = '',
50-
['C'] = nil,
51-
['D'] = '',
52-
['E'] = '',
53-
['F'] = nil,
54-
['G'] = '',
55-
['H'] = '',
56-
['I'] = '',
57-
['J'] = '',
58-
['K'] = '',
59-
['L'] = '',
60-
['M'] = '',
61-
['N'] = '',
62-
['O'] = '',
63-
['P'] = '',
64-
['Q'] = nil,
65-
['R'] = 'ᴿ',
66-
['S'] = nil,
67-
['T'] = '',
68-
['U'] = '',
69-
['V'] = '',
70-
['W'] = '',
71-
['X'] = nil,
72-
['Y'] = nil,
19+
['A'] = '', ['B'] = '', ['C'] = nil, ['D'] = '', ['E'] = '',
20+
['F'] = nil, ['G'] = '', ['H'] = '', ['I'] = '', ['J'] = '',
21+
['K'] = '', ['L'] = '', ['M'] = '', ['N'] = '', ['O'] = '',
22+
['P'] = '', ['Q'] = nil, ['R'] = 'ᴿ', ['S'] = nil, ['T'] = '',
23+
['U'] = '', ['V'] = '', ['W'] = '', ['X'] = nil, ['Y'] = nil,
7324
['Z'] = nil,
7425
}
7526

lua/render-markdown/render/inline/shortcut.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ end
3232
---@protected
3333
function Render:run()
3434
local _, line = self.node:line('first', 0)
35-
local wiki_pattern = '[' .. self.node.text .. ']'
36-
if line and line:find(wiki_pattern, 1, true) then
35+
if line and line:find('[' .. self.node.text .. ']', 1, true) then
3736
Wiki:execute(self.context, self.marks, self.node)
3837
return
3938
end
@@ -48,19 +47,19 @@ end
4847
---@param text string
4948
function Render:footnote(text)
5049
local config = self.config.footnote
50+
local highlight = self.config.highlight
5151
if not config.enabled then
5252
return
5353
end
54-
local body = config.prefix .. text .. config.suffix
55-
local value = body ---@type string?
54+
local body = config.prefix .. text .. config.suffix ---@type string?
5655
if config.superscript then
57-
value = converter.superscript(body)
56+
body = body and converter.superscript(body)
5857
end
59-
if not value then
58+
if not body then
6059
return
6160
end
6261
self.marks:over(self.config, 'link', self.node, {
63-
virt_text = { { value, self.config.highlight } },
62+
virt_text = { { config.icon .. body, highlight } },
6463
virt_text_pos = 'inline',
6564
conceal = '',
6665
})

lua/render-markdown/settings.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ M.link = {}
11741174

11751175
---@class (exact) render.md.link.footnote.Config
11761176
---@field enabled boolean
1177+
---@field icon string
11771178
---@field superscript boolean
11781179
---@field prefix string
11791180
---@field suffix string
@@ -1207,6 +1208,8 @@ M.link.default = {
12071208
footnote = {
12081209
-- Turn on / off footnote rendering.
12091210
enabled = true,
1211+
-- Inlined with content.
1212+
icon = '󰯔 ',
12101213
-- Replace value with superscript equivalent.
12111214
superscript = true,
12121215
-- Added before link content.
@@ -1272,6 +1275,7 @@ function M.link.schema()
12721275
footnote = {
12731276
record = {
12741277
enabled = { type = 'boolean' },
1278+
icon = { type = 'string' },
12751279
superscript = { type = 'boolean' },
12761280
prefix = { type = 'string' },
12771281
suffix = { type = 'string' },

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213

214214
---@class (exact) render.md.link.footnote.UserConfig
215215
---@field enabled? boolean
216+
---@field icon? string
216217
---@field superscript? boolean
217218
---@field prefix? string
218219
---@field suffix? string

tests/ad_hoc_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ describe('ad hoc', function()
111111
})
112112
local marks = util.marks()
113113
marks:add({ 0, 0 }, { 14, 23 }, {
114-
virt_text = { { '¹ ᴵⁿᶠᵒ', 'RmLink' } },
114+
virt_text = { { '󰯔 ¹ ᴵⁿᶠᵒ', 'RmLink' } },
115115
virt_text_pos = 'inline',
116116
conceal = '',
117117
})
118118
marks:add({ 1, 1 }, { 0, 9 }, {
119-
virt_text = { { '¹ ᴵⁿᶠᵒ', 'RmLink' } },
119+
virt_text = { { '󰯔 ¹ ᴵⁿᶠᵒ', 'RmLink' } },
120120
virt_text_pos = 'inline',
121121
conceal = '',
122122
})
123123
util.assert_view(marks, {
124-
'Footnote Link ¹ ᴵⁿᶠᵒ',
125-
'¹ ᴵⁿᶠᵒ: Some Info',
124+
'Footnote Link 󰯔 ¹ ᴵⁿᶠᵒ',
125+
'󰯔 ¹ ᴵⁿᶠᵒ: Some Info',
126126
})
127127
end)
128128

0 commit comments

Comments
 (0)