Skip to content

Commit f3cda24

Browse files
feat: add code border none
## Details Request: #246 Adds `none` to the possible values for `code.border`. Using this value when paired with `code.disable_background = true` allows the user to only keep the language icon rendering feature. The `code.disable_background` feature functions in the same way as `code.style = 'language'`. Ideally I would remove the `style` options, it seems better to control everything more granularly and then group settings under a `preset` option, but it is what is is, will keep both around even though they end up being redundant. Will consider a major version bump that breaks styles in the future.
1 parent 1b5d117 commit f3cda24

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## Pre-release
44

5+
### Features
6+
7+
- footnote text superscript rendering [#241](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/241)
8+
[634acd5](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/634acd5da964c32f6947cd0c7802d7a116662665)
9+
[1b5d117](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/1b5d11734122d9451d2e5e2e567fd61a62822293)
10+
11+
### Bug Fixes
12+
13+
- highlight index width calculation [#212](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/212)
14+
[3a319cd](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/3a319cdbefebf0079a7012dab6b1bfc18ca5b97f)
15+
516
## 7.6.0 (2024-11-25)
617

718
### Features

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ require('render-markdown').setup({
328328
-- Minimum width to use for code blocks when width is 'block'
329329
min_width = 0,
330330
-- Determines how the top / bottom of code block are rendered:
331+
-- none: do not render a border
331332
-- thick: use the same highlight as the code body
332333
-- thin: when lines are empty overlay the above & below icons
333334
border = 'thin',
@@ -775,6 +776,7 @@ require('render-markdown').setup({
775776
-- Minimum width to use for code blocks when width is 'block'
776777
min_width = 0,
777778
-- Determines how the top / bottom of code block are rendered:
779+
-- none: do not render a border
778780
-- thick: use the same highlight as the code body
779781
-- thin: when lines are empty overlay the above & below icons
780782
border = 'thin',

doc/render-markdown.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 November 30
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 December 01
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -375,6 +375,7 @@ Default Configuration ~
375375
-- Minimum width to use for code blocks when width is 'block'
376376
min_width = 0,
377377
-- Determines how the top / bottom of code block are rendered:
378+
-- none: do not render a border
378379
-- thick: use the same highlight as the code body
379380
-- thin: when lines are empty overlay the above & below icons
380381
border = 'thin',
@@ -816,6 +817,7 @@ Code Block Configuration ~
816817
-- Minimum width to use for code blocks when width is 'block'
817818
min_width = 0,
818819
-- Determines how the top / bottom of code block are rendered:
820+
-- none: do not render a border
819821
-- thick: use the same highlight as the code body
820822
-- thin: when lines are empty overlay the above & below icons
821823
border = 'thin',

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.6.3'
7+
M.version = '7.6.4'
88

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

lua/render-markdown/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ local M = {}
135135
---@alias render.md.code.Style 'full'|'normal'|'language'|'none'
136136
---@alias render.md.code.Position 'left'|'right'
137137
---@alias render.md.code.Width 'full'|'block'
138-
---@alias render.md.code.Border 'thin'|'thick'
138+
---@alias render.md.code.Border 'thin'|'thick'|'none'
139139

140140
---@class (exact) render.md.UserCode
141141
---@field public enabled? boolean
@@ -452,6 +452,7 @@ M.default_config = {
452452
-- Minimum width to use for code blocks when width is 'block'
453453
min_width = 0,
454454
-- Determines how the top / bottom of code block are rendered:
455+
-- none: do not render a border
455456
-- thick: use the same highlight as the code body
456457
-- thin: when lines are empty overlay the above & below icons
457458
border = 'thin',

lua/render-markdown/render/code.lua

+24-5
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,32 @@ function Render:language()
106106
if not vim.tbl_contains({ 'language', 'full' }, self.code.style) then
107107
return false
108108
end
109+
109110
local node = self.data.language_node
110111
if node == nil then
111112
return false
112113
end
114+
113115
local icon, icon_highlight = Icons.get(node.text)
114116
if self.code.highlight_language ~= nil then
115117
icon_highlight = self.code.highlight_language
116118
end
117119
if icon == nil or icon_highlight == nil then
118120
return false
119121
end
122+
120123
if self.code.sign then
121124
self:sign(icon, icon_highlight)
122125
end
126+
123127
local icon_text = icon .. ' '
124-
local highlight = { icon_highlight, self.code.highlight }
128+
local highlight = { icon_highlight }
129+
if self.code.border ~= 'none' then
130+
table.insert(highlight, self.code.highlight)
131+
end
132+
125133
if self.code.position == 'left' then
126-
if self.code.language_name and self.context:width(node) == 0 then
134+
if self.code.language_name and self:hidden(node) then
127135
-- Code blocks will pick up varying amounts of leading white space depending on the
128136
-- context they are in. This gets lumped into the delimiter node and as a result,
129137
-- after concealing, the extmark will be left shifted. Logic below accounts for this.
@@ -154,12 +162,16 @@ end
154162
---@private
155163
---@param icon boolean
156164
function Render:border(icon)
165+
if self.code.border == 'none' then
166+
return
167+
end
168+
157169
---@param row integer
158170
---@param border string
159171
---@param context_hidden boolean
160172
local function add_border(row, border, context_hidden)
161-
local delim_hidden = self.context:width(self.node:child('fenced_code_block_delimiter', row)) == 0
162-
if self.code.border == 'thin' and context_hidden and delim_hidden then
173+
local delim_node = self.node:child('fenced_code_block_delimiter', row)
174+
if self.code.border == 'thin' and context_hidden and self:hidden(delim_node) then
163175
local width = self.code.width == 'block' and self.data.max_width or vim.o.columns
164176
self.marks:add('code_border', row, self.data.col, {
165177
virt_text = { { border:rep(width - self.data.col), colors.bg_to_fg(self.code.highlight) } },
@@ -170,10 +182,17 @@ function Render:border(icon)
170182
end
171183
end
172184

173-
add_border(self.node.start_row, self.code.above, not icon and self.context:width(self.data.code_node) == 0)
185+
add_border(self.node.start_row, self.code.above, not icon and self:hidden(self.data.code_node))
174186
add_border(self.node.end_row - 1, self.code.below, true)
175187
end
176188

189+
---@private
190+
---@param node? render.md.Node
191+
---@return boolean
192+
function Render:hidden(node)
193+
return self.context:width(node) == 0
194+
end
195+
177196
---@private
178197
---@param start_row integer
179198
---@param end_row integer

lua/render-markdown/state.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function M.validate()
174174
:one_of('style', { 'full', 'normal', 'language', 'none' })
175175
:one_of('position', { 'left', 'right' })
176176
:one_of('width', { 'full', 'block' })
177-
:one_of('border', { 'thin', 'thick' })
177+
:one_of('border', { 'thin', 'thick', 'none' })
178178
:check()
179179
end)
180180
:nested('dash', function(dash)

0 commit comments

Comments
 (0)