Skip to content

Commit a212596

Browse files
feat: pad suffix of latex so backgrounds are aligned
1 parent d69f0d8 commit a212596

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 May 30
1+
*render-markdown.txt* For NVIM v0.11.2 Last change: 2025 May 31
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/handler/latex.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ function Handler:expressions(node)
6565
for _ = 1, self.config.top_pad do
6666
result[#result + 1] = ''
6767
end
68-
for _, line in ipairs(self:convert(node.text)) do
69-
result[#result + 1] = Str.pad(node.start_col) .. line
68+
local lines = Str.split(self:convert(node.text), '\n', true)
69+
local width = vim.fn.max(Iter.list.map(lines, Str.width))
70+
for _, line in ipairs(lines) do
71+
local prefix = Str.pad(node.start_col)
72+
local suffix = Str.pad(width - Str.width(line))
73+
result[#result + 1] = prefix .. line .. suffix
7074
end
7175
for _ = 1, self.config.bottom_pad do
7276
result[#result + 1] = ''
@@ -76,7 +80,7 @@ end
7680

7781
---@private
7882
---@param text string
79-
---@return string[]
83+
---@return string
8084
function Handler:convert(text)
8185
local result = Handler.cache[text]
8286
if not result then
@@ -88,7 +92,7 @@ function Handler:convert(text)
8892
end
8993
Handler.cache[text] = result
9094
end
91-
return Str.split(result, '\n', true)
95+
return result
9296
end
9397

9498
---@private

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
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.4.9'
8+
M.version = '8.4.10'
99

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

tests/latex_spec.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ local function set_responses(converter, responses)
1919
end
2020

2121
---@param lines string[]
22+
---@param width integer
2223
---@return vim.api.keyset.set_extmark
23-
local function latex(lines)
24+
local function latex(lines, width)
2425
local virt_lines = vim.iter(lines)
2526
:map(function(line)
26-
return { { line, 'RmMath' } }
27+
return { { line .. (' '):rep(width - #line), 'RmMath' } }
2728
end)
2829
:totable()
2930
---@type vim.api.keyset.set_extmark
@@ -70,8 +71,8 @@ describe('latex.md', function()
7071
marks:add(row:get(), row:get(), 0, 1, util.heading.icon(1))
7172
marks:add(row:get(), row:inc(), 0, 0, util.heading.bg(1))
7273

73-
marks:add(row:inc(), nil, 0, nil, latex(inline.out))
74-
marks:add(row:inc(2), nil, 0, nil, latex(block.out))
74+
marks:add(row:inc(), nil, 0, nil, latex(inline.out, 17))
75+
marks:add(row:inc(2), nil, 0, nil, latex(block.out, 28))
7576

7677
util.assert_view(marks, {
7778
'󰫎 󰲡 LaTeX',

0 commit comments

Comments
 (0)