Skip to content

Commit c4ff9ac

Browse files
fix: use display width for latex formula alignment
## Details Instead of using the byte offset for latex formula alignment, calculate the actual display width of the text before the current node. Co-authored-by: Lexey Khom <[email protected]>
1 parent 0087ee1 commit c4ff9ac

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
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.3 Last change: 2025 August 19
1+
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 August 21
22

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

lua/render-markdown/debug/marks.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ end
9999
---@param lines render.md.mark.Line[]
100100
---@return string
101101
function Mark.lines(lines)
102-
return #lines > 0 and Mark.line(lines[1]) or ''
102+
local result = {} ---@type string[]
103+
for _, line in ipairs(lines) do
104+
result[#result + 1] = Mark.line(line)
105+
end
106+
return ('{%s}'):format(table.concat(result, ', '))
103107
end
104108

105109
---@private
@@ -113,7 +117,7 @@ function Mark.line(line)
113117
Mark.highlight(text[2])
114118
)
115119
end
116-
return table.concat(result, ' + ')
120+
return ('[%s]'):format(table.concat(result, ', '))
117121
end
118122

119123
---@private

lua/render-markdown/handler/latex.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,26 @@ end
6161
---@param node render.md.Node
6262
---@return string[]
6363
function Handler:expressions(node)
64+
local col = node.start_col
65+
local _, first = node:line('first', 0)
66+
local prefix = str.pad(first and str.width(first:sub(1, col)) or col)
67+
6468
local result = {} ---@type string[]
6569
for _ = 1, self.config.top_pad do
6670
result[#result + 1] = ''
6771
end
72+
6873
local lines = str.split(self:convert(node.text), '\n', true)
6974
local width = vim.fn.max(iter.list.map(lines, str.width))
7075
for _, line in ipairs(lines) do
71-
local prefix = str.pad(node.start_col)
7276
local suffix = str.pad(width - str.width(line))
7377
result[#result + 1] = prefix .. line .. suffix
7478
end
79+
7580
for _ = 1, self.config.bottom_pad do
7681
result[#result + 1] = ''
7782
end
83+
7884
return result
7985
end
8086

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

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

tests/util.lua

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,12 @@ end
353353
function M.table.border(virtual, above, ...)
354354
local chars = above and { '', '', '' } or { '', '', '' }
355355
local highlight = above and 'RmTableHead' or 'RmTableRow'
356-
local parts = vim.tbl_map(function(length)
357-
return (''):rep(length)
358-
end, { ... })
359-
local text = chars[1] .. table.concat(parts, chars[2]) .. chars[3]
356+
local inner = vim.iter({ ... })
357+
:map(function(length)
358+
return (''):rep(length)
359+
end)
360+
:join(chars[2])
361+
local text = chars[1] .. inner .. chars[3]
360362
if virtual then
361363
---@type vim.api.keyset.set_extmark
362364
return {
@@ -376,15 +378,16 @@ end
376378
---@param ... integer[]
377379
---@return vim.api.keyset.set_extmark
378380
function M.table.delimiter(padding, ...)
379-
local parts = vim.tbl_map(function(widths)
380-
local section = vim.tbl_map(function(amount)
381-
return amount == 1 and '' or (''):rep(amount)
382-
end, widths)
383-
return table.concat(section, '')
384-
end, { ... })
385-
local line = {
386-
{ '' .. table.concat(parts, '') .. '', 'RmTableHead' },
387-
}
381+
local inner = vim.iter({ ... })
382+
:map(function(widths)
383+
return vim.iter(widths)
384+
:map(function(amount)
385+
return amount == 1 and '' or (''):rep(amount)
386+
end)
387+
:join('')
388+
end)
389+
:join('')
390+
local line = { { '' .. inner .. '', 'RmTableHead' } }
388391
if padding > 0 then
389392
line[#line + 1] = { (' '):rep(padding), 'Normal' }
390393
end

0 commit comments

Comments
 (0)