From fcd1d58a11f7de6dcffecb5bdc1855a3bb8f0302 Mon Sep 17 00:00:00 2001 From: bezlant Date: Thu, 22 Jan 2026 22:06:55 +0700 Subject: [PATCH] feat: allow ignoring languages to fix conflicts with image renderers --- lua/render-markdown/render/markdown/code.lua | 10 ++++++ lua/render-markdown/settings.lua | 4 +++ lua/render-markdown/types.lua | 1 + tests/ignore_spec.lua | 34 ++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 tests/ignore_spec.lua diff --git a/lua/render-markdown/render/markdown/code.lua b/lua/render-markdown/render/markdown/code.lua index d7d6ff2..6b7d806 100644 --- a/lua/render-markdown/render/markdown/code.lua +++ b/lua/render-markdown/render/markdown/code.lua @@ -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 diff --git a/lua/render-markdown/settings.lua b/lua/render-markdown/settings.lua index 928ad56..d0449fd 100644 --- a/lua/render-markdown/settings.lua +++ b/lua/render-markdown/settings.lua @@ -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 @@ -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. @@ -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' }, diff --git a/lua/render-markdown/types.lua b/lua/render-markdown/types.lua index db18e10..fef8d3b 100644 --- a/lua/render-markdown/types.lua +++ b/lua/render-markdown/types.lua @@ -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 diff --git a/tests/ignore_spec.lua b/tests/ignore_spec.lua new file mode 100644 index 0000000..4169268 --- /dev/null +++ b/tests/ignore_spec.lua @@ -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) \ No newline at end of file