Skip to content

Commit 1b5d117

Browse files
feat: configurable footnote prefix & suffix
## Details Request: #241 Rather than surrounding footnotes in parenthesis by default the prefix and suffix are now configurable properties. The default behavior has changed in that nothing is added by default. To get the previous behavior users can set the following: ```lua require('render-markdown').setup({ link = { footnote = { prefix = '(', suffix = ')' }, }, }) ```
1 parent 634acd5 commit 1b5d117

File tree

8 files changed

+34
-9
lines changed

8 files changed

+34
-9
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ require('render-markdown').setup({
511511
footnote = {
512512
-- Replace value with superscript equivalent
513513
superscript = true,
514+
-- Added before link content when converting to superscript
515+
prefix = '',
516+
-- Added after link content when converting to superscript
517+
suffix = '',
514518
},
515519
-- Inlined with 'image' elements
516520
image = '󰥶 ',
@@ -1059,6 +1063,10 @@ require('render-markdown').setup({
10591063
footnote = {
10601064
-- Replace value with superscript equivalent
10611065
superscript = true,
1066+
-- Added before link content when converting to superscript
1067+
prefix = '',
1068+
-- Added after link content when converting to superscript
1069+
suffix = '',
10621070
},
10631071
-- Inlined with 'image' elements
10641072
image = '󰥶 ',

doc/render-markdown.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 November 27
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 November 30
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -558,6 +558,10 @@ Default Configuration ~
558558
footnote = {
559559
-- Replace value with superscript equivalent
560560
superscript = true,
561+
-- Added before link content when converting to superscript
562+
prefix = '',
563+
-- Added after link content when converting to superscript
564+
suffix = '',
561565
},
562566
-- Inlined with 'image' elements
563567
image = '󰥶 ',
@@ -1086,6 +1090,10 @@ Link Configuration ~
10861090
footnote = {
10871091
-- Replace value with superscript equivalent
10881092
superscript = true,
1093+
-- Added before link content when converting to superscript
1094+
prefix = '',
1095+
-- Added after link content when converting to superscript
1096+
suffix = '',
10891097
},
10901098
-- Inlined with 'image' elements
10911099
image = '󰥶 ',

lua/render-markdown/health.lua

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

66
---@private
7-
M.version = '7.6.2'
7+
M.version = '7.6.3'
88

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

lua/render-markdown/init.lua

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ local M = {}
5656

5757
---@class (exact) render.md.UserFootnote
5858
---@field public superscript? boolean
59+
---@field public prefix? string
60+
---@field public suffix? string
5961

6062
---@class (exact) render.md.UserLink
6163
---@field public enabled? boolean
@@ -633,6 +635,10 @@ M.default_config = {
633635
footnote = {
634636
-- Replace value with superscript equivalent
635637
superscript = true,
638+
-- Added before link content when converting to superscript
639+
prefix = '',
640+
-- Added after link content when converting to superscript
641+
suffix = '',
636642
},
637643
-- Inlined with 'image' elements
638644
image = '󰥶 ',

lua/render-markdown/render/shortcut.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ end
115115
---@private
116116
---@param text string
117117
function Render:footnote(text)
118-
if not self.link.enabled or not self.link.footnote.superscript then
118+
local footnote = self.link.footnote
119+
if not self.link.enabled or not footnote.superscript then
119120
return
120121
end
121122

122-
local value = Converter.to_superscript('(' .. text .. ')')
123+
local value = Converter.to_superscript(footnote.prefix .. text .. footnote.suffix)
123124
if value == nil then
124125
return
125126
end

lua/render-markdown/state.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function M.validate()
235235
link:type('enabled', 'boolean')
236236
:type({ 'image', 'email', 'hyperlink', 'highlight' }, 'string')
237237
:nested('footnote', function(footnote)
238-
footnote:type('superscript', 'boolean'):check()
238+
footnote:type('superscript', 'boolean'):type({ 'prefix', 'suffix' }, 'string'):check()
239239
end)
240240
:nested('wiki', function(wiki)
241241
wiki:type({ 'icon', 'highlight' }, 'string'):check()

lua/render-markdown/types.lua

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
---@class (exact) render.md.Footnote
4545
---@field public superscript boolean
46+
---@field public prefix string
47+
---@field public suffix string
4648

4749
---@class (exact) render.md.Link
4850
---@field public enabled boolean

tests/ad_hoc_spec.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe('ad_hoc.md', function()
8787

8888
vim.list_extend(expected, {
8989
util.bullet(row:increment(), 0, 1),
90-
link(row:get(), 16, 25, '¹ ᴵⁿᶠᵒ', 'Link', ''),
91-
link(row:increment(2), 0, 9, '¹ ᴵⁿᶠᵒ', 'Link', ''),
90+
link(row:get(), 16, 25, '¹ ᴵⁿᶠᵒ', 'Link', ''),
91+
link(row:increment(2), 0, 9, '¹ ᴵⁿᶠᵒ', 'Link', ''),
9292
})
9393

9494
util.assert_view(expected, {
@@ -103,9 +103,9 @@ describe('ad_hoc.md', function()
103103
' 9 ● 󱗖 With Alias Something important',
104104
' 10 ● 󰀓 [email protected] Email',
105105
' 11 ●  Youtube Link',
106-
' 12 ● Footnote Link ¹ ᴵⁿᶠᵒ',
106+
' 12 ● Footnote Link ¹ ᴵⁿᶠᵒ',
107107
' 13',
108-
' 14 ¹ ᴵⁿᶠᵒ: Some Info',
108+
' 14 ¹ ᴵⁿᶠᵒ: Some Info',
109109
})
110110
end)
111111
end)

0 commit comments

Comments
 (0)