Skip to content

Commit 125258a

Browse files
fix: always add indent to column when right aligning code language
## Details Previously when right aligning code language the amount of indent added would only be accounted for with the `block` width. This means the default `full` width would end up drifting the heading more left as the level increased (if indent mode was enabled that is). This was not intended behavior, so add the indent regardless of `width`.
1 parent b8d93e8 commit 125258a

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

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

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

lua/render-markdown/render/base.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ function Base:new(marks, config, context, node)
2727
end
2828

2929
---@protected
30+
---@param enabled boolean
3031
---@param text? string
3132
---@param highlight? string
32-
function Base:sign(text, highlight)
33+
function Base:sign(enabled, text, highlight)
3334
local sign = self.config.sign
34-
if not sign.enabled or text == nil then
35+
if not enabled or not sign.enabled or text == nil then
3536
return
3637
end
3738
local sign_highlight = sign.highlight

lua/render-markdown/render/code.lua

+6-9
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function Render:language()
114114
return false
115115
end
116116

117-
local node = self.data.language_node
117+
local node, padding = self.data.language_node, self.data.language_padding
118118
if node == nil then
119119
return false
120120
end
@@ -127,9 +127,7 @@ function Render:language()
127127
return false
128128
end
129129

130-
if self.code.sign then
131-
self:sign(icon, icon_highlight)
132-
end
130+
self:sign(self.code.sign, icon, icon_highlight)
133131

134132
local text, highlight = icon .. ' ', { icon_highlight }
135133
if self.code.border ~= 'none' then
@@ -142,8 +140,7 @@ function Render:language()
142140
-- on the context they are in. This is lumped into the delimiter node
143141
-- and as a result, after concealing, the extmark would be shifted.
144142
local spaces = Str.spaces('start', self.node.text)
145-
local padding = Str.pad(spaces + self.data.language_padding)
146-
text = padding .. text .. node.text
143+
text = Str.pad(spaces + padding) .. text .. node.text
147144
end
148145
return self.marks:add('code_language', node.start_row, node.start_col, {
149146
virt_text = { { text, highlight } },
@@ -153,13 +150,13 @@ function Render:language()
153150
if self.code.language_name then
154151
text = text .. node.text
155152
end
156-
local win_col = self.data.max_width - self.data.language_padding
153+
local win_col = self.data.max_width - padding
157154
if self.code.width == 'block' then
158-
win_col = win_col - Str.width(text) + self.data.indent
155+
win_col = win_col - Str.width(text)
159156
end
160157
return self.marks:add('code_language', node.start_row, 0, {
161158
virt_text = { { text, highlight } },
162-
virt_text_win_col = win_col,
159+
virt_text_win_col = win_col + self.data.indent,
163160
})
164161
else
165162
return false

lua/render-markdown/render/heading.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ function Render:custom()
9898
end
9999

100100
function Render:render()
101-
if self.heading.sign then
102-
self:sign(self.data.sign, self.data.foreground)
103-
end
101+
self:sign(self.heading.sign, self.data.sign, self.data.foreground)
104102
local width = self:width(self:icon())
105103
self:background(width)
106104
self:left_pad(width)

0 commit comments

Comments
 (0)