aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorFolke Lemaitre <folke.lemaitre@gmail.com>2021-06-25 15:23:02 +0200
committerFolke Lemaitre <folke.lemaitre@gmail.com>2021-06-25 17:27:38 +0200
commitaa1e20497ae9f87b7f955032c1bcf2df33d472bd (patch)
tree4336d3a3e32f55879b6476e27b922e77c825ca6e /runtime/lua/vim/lsp/util.lua
parent510ed996d2a92de527c70888208e3ad7ce157126 (diff)
downloadrneovim-aa1e20497ae9f87b7f955032c1bcf2df33d472bd.tar.gz
rneovim-aa1e20497ae9f87b7f955032c1bcf2df33d472bd.tar.bz2
rneovim-aa1e20497ae9f87b7f955032c1bcf2df33d472bd.zip
feat(lsp): use markdown_fenced_languages in 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()