Skip to content

Commit 18c7ef7

Browse files
feat: allow language name to be disabled
## Details Request: #205 Adds `code.language_name` argument which when false will not render the language name next to the icon. Defaults to true to keep current behavior unchanged.
1 parent 965c222 commit 18c7ef7

File tree

8 files changed

+21
-5
lines changed

8 files changed

+21
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[d20d19f](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/d20d19fa54965f6eb94558c0b84fe9a942169fb4)
99
- `on.attach` buffer callback [8b4149b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8b4149b122cfbf58b79a552ae89b3df2ddc39786)
1010
- allow empty lists for all heading properties [0c6de74](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/0c6de743a8d3c61b87bc7db9ab97dcda12ca6818)
11+
- wiki link config & language highlight [#205](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/205)
12+
[965c222](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/965c222076b2d289ed498730845d533780f3c7c7)
1113

1214
### Bug Fixes
1315

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ require('render-markdown').setup({
290290
-- Amount of padding to add around the language
291291
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
292292
language_pad = 0,
293+
-- Whether to include the language name next to the icon
294+
language_name = true,
293295
-- A list of language names for which background highlighting will be disabled
294296
-- Likely because that language has background highlights itself
295297
disable_background = { 'diff' },
@@ -707,6 +709,8 @@ require('render-markdown').setup({
707709
-- Amount of padding to add around the language
708710
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
709711
language_pad = 0,
712+
-- Whether to include the language name next to the icon
713+
language_name = true,
710714
-- A list of language names for which background highlighting will be disabled
711715
-- Likely because that language has background highlights itself
712716
disable_background = { 'diff' },

doc/render-markdown.txt

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ Default Configuration ~
339339
-- Amount of padding to add around the language
340340
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
341341
language_pad = 0,
342+
-- Whether to include the language name next to the icon
343+
language_name = true,
342344
-- A list of language names for which background highlighting will be disabled
343345
-- Likely because that language has background highlights itself
344346
disable_background = { 'diff' },
@@ -750,6 +752,8 @@ Code Block Configuration ~
750752
-- Amount of padding to add around the language
751753
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
752754
language_pad = 0,
755+
-- Whether to include the language name next to the icon
756+
language_name = true,
753757
-- A list of language names for which background highlighting will be disabled
754758
-- Likely because that language has background highlights itself
755759
disable_background = { 'diff' },

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.3.5'
7+
M.version = '7.3.6'
88

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

lua/render-markdown/init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ local M = {}
130130
---@field public style? render.md.code.Style
131131
---@field public position? render.md.code.Position
132132
---@field public language_pad? number
133+
---@field public language_name? boolean
133134
---@field public disable_background? string[]
134135
---@field public width? render.md.code.Width
135136
---@field public left_margin? number
@@ -382,6 +383,8 @@ M.default_config = {
382383
-- Amount of padding to add around the language
383384
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
384385
language_pad = 0,
386+
-- Whether to include the language name next to the icon
387+
language_name = true,
385388
-- A list of language names for which background highlighting will be disabled
386389
-- Likely because that language has background highlights itself
387390
disable_background = { 'diff' },

lua/render-markdown/render/code.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ function Render:language(add_background)
116116
if add_background then
117117
table.insert(highlight, self.code.highlight)
118118
end
119+
local icon_text = icon .. ' '
119120
if self.code.position == 'left' then
120-
local icon_text = icon .. ' '
121-
if self.context:hidden(info) then
121+
if self.code.language_name and self.context:hidden(info) then
122122
-- Code blocks will pick up varying amounts of leading white space depending on the
123123
-- context they are in. This gets lumped into the delimiter node and as a result,
124124
-- after concealing, the extmark will be left shifted. Logic below accounts for this.
@@ -130,7 +130,9 @@ function Render:language(add_background)
130130
virt_text_pos = 'inline',
131131
})
132132
elseif self.code.position == 'right' then
133-
local icon_text = icon .. ' ' .. info.text
133+
if self.code.language_name then
134+
icon_text = icon_text .. info.text
135+
end
134136
local win_col = self.data.max_width - self.data.language_padding
135137
if self.code.width == 'block' then
136138
win_col = win_col - str.width(icon_text) + self.data.indent

lua/render-markdown/state.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function M.validate()
152152
get_spec('paragraph'):type('enabled', 'boolean'):type({ 'left_margin', 'min_width' }, 'number'):check()
153153

154154
get_spec('code')
155-
:type({ 'enabled', 'sign' }, 'boolean')
155+
:type({ 'enabled', 'sign', 'language_name' }, 'boolean')
156156
:type({ 'language_pad', 'left_margin', 'left_pad', 'right_pad', 'min_width' }, 'number')
157157
:type({ 'above', 'below', 'highlight', 'highlight_inline' }, 'string')
158158
:type('highlight_language', { 'string', 'nil' })

lua/render-markdown/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
---@field public style render.md.code.Style
107107
---@field public position render.md.code.Position
108108
---@field public language_pad number
109+
---@field public language_name boolean
109110
---@field public disable_background string[]
110111
---@field public width render.md.code.Width
111112
---@field public left_margin number

0 commit comments

Comments
 (0)