Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lua/render-markdown/render/markdown/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ function Render:setup()
if not self.config.enabled then
return false
end
-- ignore specific languages
local info = self.node:child('info_string')
local language = info and info:child('language')
if
language
and self.config.ignore
and vim.tbl_contains(self.config.ignore, language.text)
then
return false
end
-- skip single line code block
if self.node:height() <= 2 then
return false
Expand Down
4 changes: 4 additions & 0 deletions lua/render-markdown/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ M.code = {}

---@class (exact) render.md.code.Config: render.md.base.Config
---@field sign boolean
---@field ignore string[]
---@field conceal_delimiters boolean
---@field language boolean
---@field position render.md.code.Position
Expand Down Expand Up @@ -447,6 +448,8 @@ M.code.default = {
enabled = true,
-- Additional modes to render code blocks.
render_modes = false,
-- List of languages to ignore rendering for.
ignore = {},
-- Turn on / off sign column related rendering.
sign = true,
-- Whether to conceal nodes at the top and bottom of code blocks.
Expand Down Expand Up @@ -536,6 +539,7 @@ M.code.default = {
---@return render.md.Schema
function M.code.schema()
return M.base.schema({
ignore = { list = { type = 'string' } },
sign = { type = 'boolean' },
conceal_delimiters = { type = 'boolean' },
language = { type = 'boolean' },
Expand Down
1 change: 1 addition & 0 deletions lua/render-markdown/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@

---@class (exact) render.md.code.UserConfig: render.md.base.UserConfig
---@field sign? boolean
---@field ignore? string[]
---@field conceal_delimiters? boolean
---@field language? boolean
---@field position? render.md.code.Position
Expand Down
34 changes: 34 additions & 0 deletions tests/ignore_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local util = require('tests.util')

describe('code ignore', function()
it('ignores configured languages', function()
util.setup.text({
'```mermaid',
'graph TD;',
' A-->B;',
'```',
}, {
code = {
ignore = { 'mermaid' },
},
})

-- Should have no marks
util.assert_marks({})
end)

it('ignores nothing by default', function()
util.setup.text({
'```mermaid',
'graph TD;',
' A-->B;',
'```',
})

util.assert_screen({
'mermaid█████████████████████████████████████████████████████████████████████████',
'graph TD;',
' A-->B;',
})
end)
end)