Skip to content

Commit ba50c2f

Browse files
feat: configurable left and right language text
## Details Allow users to configure text to add around the language border using `code.language_left` and `code.language_right`. This surrounds the main section, remainder continues to be filled with `code.language_border`. Some example configurations are: ```lua require('render-markdown').setup({ code = { language_border = '▃', language_left = '🭃', language_right = '🭎', }, }) ``` ```lua require('render-markdown').setup({ code = { language_border = ' ', language_left = '', language_right = '', }, }) ``` ```lua require('render-markdown').setup({ code = { language_border = '▄', language_left = '█', language_right = '█', }, }) ```
1 parent ec92f60 commit ba50c2f

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ require('render-markdown').setup({
467467
border = 'hide',
468468
-- Used above code blocks to fill remaining space around language.
469469
language_border = '',
470+
-- Added to the left of language.
471+
language_left = '',
472+
-- Added to the right of language.
473+
language_right = '',
470474
-- Used above code blocks for thin border.
471475
above = '',
472476
-- Used below code blocks for thin border.
@@ -1084,6 +1088,10 @@ require('render-markdown').setup({
10841088
border = 'hide',
10851089
-- Used above code blocks to fill remaining space around language.
10861090
language_border = '',
1091+
-- Added to the left of language.
1092+
language_left = '',
1093+
-- Added to the right of language.
1094+
language_right = '',
10871095
-- Used above code blocks for thin border.
10881096
above = '',
10891097
-- Used below code blocks for thin border.

doc/render-markdown.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ Default Configuration ~
532532
border = 'hide',
533533
-- Used above code blocks to fill remaining space around language.
534534
language_border = '█',
535+
-- Added to the left of language.
536+
language_left = '',
537+
-- Added to the right of language.
538+
language_right = '',
535539
-- Used above code blocks for thin border.
536540
above = '▄',
537541
-- Used below code blocks for thin border.
@@ -1143,6 +1147,10 @@ Code Block Configuration ~
11431147
border = 'hide',
11441148
-- Used above code blocks to fill remaining space around language.
11451149
language_border = '█',
1150+
-- Added to the left of language.
1151+
language_left = '',
1152+
-- Added to the right of language.
1153+
language_right = '',
11461154
-- Used above code blocks for thin border.
11471155
above = '▄',
11481156
-- Used below code blocks for thin border.

lua/render-markdown/config/code.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
---@field min_width integer
1515
---@field border render.md.code.Border
1616
---@field language_border string
17+
---@field language_left string
18+
---@field language_right string
1719
---@field above string
1820
---@field below string
1921
---@field inline_left string
@@ -113,6 +115,10 @@ M.default = {
113115
border = 'hide',
114116
-- Used above code blocks to fill remaining space around language.
115117
language_border = '',
118+
-- Added to the left of language.
119+
language_left = '',
120+
-- Added to the right of language.
121+
language_right = '',
116122
-- Used above code blocks for thin border.
117123
above = '',
118124
-- Used below code blocks for thin border.
@@ -155,6 +161,8 @@ function M.validate(spec)
155161
spec:type('min_width', 'number')
156162
spec:one_of('border', vim.tbl_values(Border))
157163
spec:type('language_border', 'string')
164+
spec:type('language_left', 'string')
165+
spec:type('language_right', 'string')
158166
spec:type('above', 'string')
159167
spec:type('below', 'string')
160168
spec:type('inline_left', 'string')

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

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

lua/render-markdown/render/markdown/code.lua

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ function Render:setup()
3232
end
3333
local widths = self.node:widths()
3434
local width = vim.fn.max(widths)
35+
3536
local language = self:offset(self.config.language_pad, width)
3637
local left = self:offset(self.config.left_pad, width)
3738
local right = self:offset(self.config.right_pad, width)
38-
local body = math.max(
39-
widths[1] + language,
40-
left + width + right,
41-
self.config.min_width
42-
)
39+
40+
local body = str.width(self.config.language_left)
41+
+ str.width(self.config.language_right)
42+
+ language
43+
+ widths[1]
44+
body = math.max(body, left + width + right, self.config.min_width)
45+
4346
self.data = {
4447
language = language,
4548
padding = left,
@@ -120,20 +123,24 @@ function Render:language(info, language, delim)
120123
border_hl = colors.bg_as_fg(border_hl)
121124
end
122125

123-
local body = self:line()
126+
local text = self:line()
124127
if self.config.language_icon and icon then
125-
body:text(icon .. ' ', language_hl)
128+
text:text(icon .. ' ', language_hl)
126129
end
127130
if self.config.language_name then
128-
body:text(language.text, language_hl)
131+
text:text(language.text, language_hl)
129132
end
130133
if self.config.language_info then
131-
body:text(info.text:sub(#language.text + 1), info_hl)
134+
text:text(info.text:sub(#language.text + 1), info_hl)
132135
end
133-
if body:empty() then
136+
if text:empty() then
134137
return false
135138
end
136139

140+
local left = self:line():text(self.config.language_left, border_hl)
141+
local right = self:line():text(self.config.language_right, border_hl)
142+
local body = left:extend(text):extend(right)
143+
137144
local border = border_hl and self.config.language_border or ' '
138145
local width = self.data.body - delim.start_col
139146

lua/render-markdown/types.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
---@field min_width? integer
9898
---@field border? render.md.code.Border
9999
---@field language_border? string
100+
---@field language_left? string
101+
---@field language_right? string
100102
---@field above? string
101103
---@field below? string
102104
---@field inline_left? string

0 commit comments

Comments
 (0)