Skip to content

Commit 48934b4

Browse files
feat: support math superscript characters and body transformer for footnotes
## Details Adds some missing standard superscript characters for +, -, =. Also adds a `body` option to footnotes that allows the user to modify the text however they want before adding prefix / suffix and converting to superscript. User can define this and disable the superscript to completely control the rendering. Default implementation simply returns the input text without any modifications.
1 parent 996ec12 commit 48934b4

8 files changed

Lines changed: 48 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- link.highlight_title option [#583](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/583)
88
[ae89236](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/ae89236e2389836cf1c3787b2b80d5d8685cc13f)
99
- toggle WikiLink rendering via enabled flag [8314d14](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8314d14b9f56306bc876fb3b386f31dc8c5a2711)
10+
- center code language position [#591](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/591)
11+
[99bfa5d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/99bfa5d61381a29eedc75810898cb9c0fc755064)
12+
- add priority to sign configuration [#601](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/601)
13+
[996ec12](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/996ec12e1164e56401babf236c56cb2d9321d923)
1014

1115
## 8.11.0 (2026-01-07)
1216

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,11 @@ require('render-markdown').setup({
784784
enabled = true,
785785
-- Inlined with content.
786786
icon = '󰯔 ',
787+
-- Custom processing for footnote body to show.
788+
-- Runs before prefix / suffix are added and superscript processing.
789+
body = function(ctx)
790+
return ctx.text
791+
end,
787792
-- Replace value with superscript equivalent.
788793
superscript = true,
789794
-- Added before link content.
@@ -1566,6 +1571,11 @@ require('render-markdown').setup({
15661571
enabled = true,
15671572
-- Inlined with content.
15681573
icon = '󰯔 ',
1574+
-- Custom processing for footnote body to show.
1575+
-- Runs before prefix / suffix are added and superscript processing.
1576+
body = function(ctx)
1577+
return ctx.text
1578+
end,
15691579
-- Replace value with superscript equivalent.
15701580
superscript = true,
15711581
-- Added before link content.

doc/render-markdown.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,11 @@ Default Configuration ~
850850
enabled = true,
851851
-- Inlined with content.
852852
icon = '󰯔 ',
853+
-- Custom processing for footnote body to show.
854+
-- Runs before prefix / suffix are added and superscript processing.
855+
body = function(ctx)
856+
return ctx.text
857+
end,
853858
-- Replace value with superscript equivalent.
854859
superscript = true,
855860
-- Added before link content.
@@ -1612,6 +1617,11 @@ Link Configuration ~
16121617
enabled = true,
16131618
-- Inlined with content.
16141619
icon = '󰯔 ',
1620+
-- Custom processing for footnote body to show.
1621+
-- Runs before prefix / suffix are added and superscript processing.
1622+
body = function(ctx)
1623+
return ctx.text
1624+
end,
16151625
-- Replace value with superscript equivalent.
16161626
superscript = true,
16171627
-- 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.11.4'
9+
M.version = '8.11.5'
1010

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

lua/render-markdown/lib/converter.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local M = {}
55
---@private
66
M.superscripts = {
77
[' '] = ' ', ['('] = '', [')'] = '',
8+
['+'] = '', ['-'] = '', ['='] = '',
89

910
['0'] = '', ['1'] = '¹', ['2'] = '²', ['3'] = '³', ['4'] = '',
1011
['5'] = '', ['6'] = '', ['7'] = '', ['8'] = '', ['9'] = '',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function Render:footnote(text)
5151
if not config.enabled then
5252
return
5353
end
54-
local body = config.prefix .. text .. config.suffix ---@type string?
54+
local body = config.body({ text = text })
55+
body = body and config.prefix .. body .. config.suffix
5556
if config.superscript then
5657
body = body and converter.superscript(body)
5758
end

lua/render-markdown/settings.lua

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,25 +1228,29 @@ M.link = {}
12281228
---@field wiki render.md.link.wiki.Config
12291229
---@field custom table<string, render.md.link.custom.Config>
12301230

1231-
---@class (exact) render.md.link.Context
1232-
---@field buf integer
1233-
---@field row integer
1234-
---@field start_col integer
1235-
---@field end_col integer
1236-
---@field destination string
1237-
---@field alias? string
1231+
---@class (exact) render.md.link.footnote.Context
1232+
---@field text string
12381233

12391234
---@class (exact) render.md.link.footnote.Config
12401235
---@field enabled boolean
12411236
---@field icon string
1237+
---@field body fun(ctx: render.md.link.footnote.Context): string?
12421238
---@field superscript boolean
12431239
---@field prefix string
12441240
---@field suffix string
12451241

1242+
---@class (exact) render.md.link.wiki.Context
1243+
---@field buf integer
1244+
---@field row integer
1245+
---@field start_col integer
1246+
---@field end_col integer
1247+
---@field destination string
1248+
---@field alias? string
1249+
12461250
---@class (exact) render.md.link.wiki.Config
12471251
---@field enabled boolean
12481252
---@field icon string
1249-
---@field body fun(ctx: render.md.link.Context): render.md.mark.Text|string?
1253+
---@field body fun(ctx: render.md.link.wiki.Context): render.md.mark.Text|string?
12501254
---@field highlight string
12511255
---@field scope_highlight? string
12521256

@@ -1275,6 +1279,11 @@ M.link.default = {
12751279
enabled = true,
12761280
-- Inlined with content.
12771281
icon = '󰯔 ',
1282+
-- Custom processing for footnote body to show.
1283+
-- Runs before prefix / suffix are added and superscript processing.
1284+
body = function(ctx)
1285+
return ctx.text
1286+
end,
12781287
-- Replace value with superscript equivalent.
12791288
superscript = true,
12801289
-- Added before link content.
@@ -1353,6 +1362,7 @@ function M.link.schema()
13531362
record = {
13541363
enabled = { type = 'boolean' },
13551364
icon = { type = 'string' },
1365+
body = { type = 'function' },
13561366
superscript = { type = 'boolean' },
13571367
prefix = { type = 'string' },
13581368
suffix = { type = 'string' },

lua/render-markdown/types.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,15 @@
223223
---@class (exact) render.md.link.footnote.UserConfig
224224
---@field enabled? boolean
225225
---@field icon? string
226+
---@field body? fun(ctx: render.md.link.footnote.Context): string?
226227
---@field superscript? boolean
227228
---@field prefix? string
228229
---@field suffix? string
229230

230231
---@class (exact) render.md.link.wiki.UserConfig
231232
---@field enabled? boolean
232233
---@field icon? string
233-
---@field body? fun(ctx: render.md.link.Context): render.md.mark.Text|string?
234+
---@field body? fun(ctx: render.md.link.wiki.Context): render.md.mark.Text|string?
234235
---@field highlight? string
235236
---@field scope_highlight? string
236237

0 commit comments

Comments
 (0)