aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2021-06-25 09:02:28 -0700
committerGitHub <noreply@github.com>2021-06-25 09:02:28 -0700
commit7b5a233d64b9fbd99727271e14178e0132ec1e98 (patch)
tree7e609f4b581a3487618526f932c130411ff11ce3 /runtime/lua/vim/lsp/util.lua
parent22c27c0fb4fd79118506f540d771ef49e148ec5d (diff)
parentaa1e20497ae9f87b7f955032c1bcf2df33d472bd (diff)
downloadrneovim-7b5a233d64b9fbd99727271e14178e0132ec1e98.tar.gz
rneovim-7b5a233d64b9fbd99727271e14178e0132ec1e98.tar.bz2
rneovim-7b5a233d64b9fbd99727271e14178e0132ec1e98.zip
Merge pull request #14617 from folke/fancy_markdown_fences_support
feat(lsp): use `g:markdown_fenced_languages` in `vim.lsp.util.stylized_markdown`
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 7c0132822e..43542949d8 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1056,6 +1056,20 @@ function M._trim(contents, opts)
return contents
end
+-- Generates a table mapping markdown code block lang to vim syntax,
+-- based on g:markdown_fenced_languages
+-- @return a table of lang -> syntax mappings
+local function get_markdown_fences()
+ local fences = {}
+ for _, fence in pairs(vim.g.markdown_fenced_languages or {}) do
+ local lang, syntax = fence:match("^(.*)=(.*)$")
+ if lang then
+ fences[lang] = syntax
+ end
+ end
+ return fences
+end
+
--- Converts markdown into syntax highlighted regions by stripping the code
--- blocks and converting them into highlighted code.
--- This will by default insert a blank line separator after those code block
@@ -1187,11 +1201,13 @@ function M.stylize_markdown(bufnr, contents, opts)
-- keep track of syntaxes we already inlcuded.
-- no need to include the same syntax more than once
local langs = {}
+ local fences = get_markdown_fences()
local function apply_syntax_to_region(ft, start, finish)
if ft == "" then
vim.cmd(string.format("syntax region markdownCode start=+\\%%%dl+ end=+\\%%%dl+ keepend extend", start, finish + 1))
return
end
+ ft = fences[ft] or ft
local name = ft..idx
idx = idx + 1
local lang = "@"..ft:upper()