Skip to content

Commit 9721ffe

Browse files
feat: add enabled flag to link footnote
## Details Based on: #362 Changes behavior of how footnotes are rendered. Previously setting `superscript = false` would completely disable the rendering of footnotes. Now this simply disables the conversion to superscripts. The `^` will continue to be hidden and `prefix` and `suffix` will be added to the contents. Disabling rendering for footnotes entirely is now controlled by the new `enabled` option under the `footnote` configuration. Co-Authored-By: Varun Narravula <[email protected]>
1 parent 08e1fa4 commit 9721ffe

File tree

8 files changed

+32
-19
lines changed

8 files changed

+32
-19
lines changed

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,13 @@ require('render-markdown').setup({
638638
render_modes = false,
639639
-- How to handle footnote links, start with a '^'.
640640
footnote = {
641+
-- Turn on / off footnote rendering.
642+
enabled = true,
641643
-- Replace value with superscript equivalent.
642644
superscript = true,
643-
-- Added before link content when converting to superscript.
645+
-- Added before link content.
644646
prefix = '',
645-
-- Added after link content when converting to superscript.
647+
-- Added after link content.
646648
suffix = '',
647649
},
648650
-- Inlined with 'image' elements.
@@ -1288,11 +1290,13 @@ require('render-markdown').setup({
12881290
render_modes = false,
12891291
-- How to handle footnote links, start with a '^'.
12901292
footnote = {
1293+
-- Turn on / off footnote rendering.
1294+
enabled = true,
12911295
-- Replace value with superscript equivalent.
12921296
superscript = true,
1293-
-- Added before link content when converting to superscript.
1297+
-- Added before link content.
12941298
prefix = '',
1295-
-- Added after link content when converting to superscript.
1299+
-- Added after link content.
12961300
suffix = '',
12971301
},
12981302
-- Inlined with 'image' elements.

doc/render-markdown.txt

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 March 14
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 March 16
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -703,11 +703,13 @@ Default Configuration ~
703703
render_modes = false,
704704
-- How to handle footnote links, start with a '^'.
705705
footnote = {
706+
-- Turn on / off footnote rendering.
707+
enabled = true,
706708
-- Replace value with superscript equivalent.
707709
superscript = true,
708-
-- Added before link content when converting to superscript.
710+
-- Added before link content.
709711
prefix = '',
710-
-- Added after link content when converting to superscript.
712+
-- Added after link content.
711713
suffix = '',
712714
},
713715
-- Inlined with 'image' elements.
@@ -1333,11 +1335,13 @@ Link Configuration ~
13331335
render_modes = false,
13341336
-- How to handle footnote links, start with a '^'.
13351337
footnote = {
1338+
-- Turn on / off footnote rendering.
1339+
enabled = true,
13361340
-- Replace value with superscript equivalent.
13371341
superscript = true,
1338-
-- Added before link content when converting to superscript.
1342+
-- Added before link content.
13391343
prefix = '',
1340-
-- Added after link content when converting to superscript.
1344+
-- Added after link content.
13411345
suffix = '',
13421346
},
13431347
-- Inlined with 'image' elements.

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.1.2'
8+
M.version = '8.1.3'
99

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

lua/render-markdown/init.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ local M = {}
110110
---@field highlight? string
111111

112112
---@class (exact) render.md.UserFootnote
113+
---@field enabled? boolean
113114
---@field superscript? boolean
114115
---@field prefix? string
115116
---@field suffix? string
@@ -789,11 +790,13 @@ M.default_config = {
789790
render_modes = false,
790791
-- How to handle footnote links, start with a '^'.
791792
footnote = {
793+
-- Turn on / off footnote rendering.
794+
enabled = true,
792795
-- Replace value with superscript equivalent.
793796
superscript = true,
794-
-- Added before link content when converting to superscript.
797+
-- Added before link content.
795798
prefix = '',
796-
-- Added after link content when converting to superscript.
799+
-- Added after link content.
797800
suffix = '',
798801
},
799802
-- Inlined with 'image' elements.

lua/render-markdown/lib/converter.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ M.superscripts = {
7575

7676
---@param s string
7777
---@return string?
78-
function M.to_superscript(s)
78+
function M.superscript(s)
7979
local chars = {}
8080
for char in s:gmatch('.') do
8181
char = M.superscripts[char]

lua/render-markdown/render/shortcut.lua

+3-5
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,15 @@ function Render:footnote(text)
159159
if self.context:skip(self.link) then
160160
return
161161
end
162-
163162
local footnote = self.link.footnote
164-
if not footnote.superscript then
163+
if not footnote.enabled then
165164
return
166165
end
167-
168-
local value = Converter.to_superscript(footnote.prefix .. text .. footnote.suffix)
166+
local body = footnote.prefix .. text .. footnote.suffix
167+
local value = not footnote.superscript and body or Converter.superscript(body)
169168
if value == nil then
170169
return
171170
end
172-
173171
self.marks:add_over('link', self.node, {
174172
virt_text = { { value, self.link.highlight } },
175173
virt_text_pos = 'inline',

lua/render-markdown/state.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ function M.validate()
259259
component_rules(link)
260260
:type({ 'image', 'email', 'hyperlink', 'highlight' }, 'string')
261261
:nested('footnote', function(footnote)
262-
footnote:type('superscript', 'boolean'):type({ 'prefix', 'suffix' }, 'string'):check()
262+
footnote
263+
:type({ 'enabled', 'superscript' }, 'boolean')
264+
:type({ 'prefix', 'suffix' }, 'string')
265+
:check()
263266
end)
264267
:nested('wiki', function(wiki)
265268
wiki:type({ 'icon', 'highlight' }, 'string'):type('body', 'function'):check()

lua/render-markdown/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
---@field highlight string
6666

6767
---@class (exact) render.md.Footnote
68+
---@field enabled boolean
6869
---@field superscript boolean
6970
---@field prefix string
7071
---@field suffix string

0 commit comments

Comments
 (0)