aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/lsp/util.lua23
-rw-r--r--runtime/syntax/lsp_markdown.vim4
2 files changed, 18 insertions, 9 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index afe1ead9ee..326005dac4 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1166,8 +1166,13 @@ function M.stylize_markdown(bufnr, contents, opts)
return line:match(string.format("^%%s*%s%%s*$", pattern[3]))
end
+ -- Clean up
+ contents = M._trim(contents, opts)
+
local stripped = {}
local highlights = {}
+ -- keep track of lnums that contain markdown
+ local markdown_lines = {}
do
local i = 1
while i <= #contents do
@@ -1192,17 +1197,24 @@ function M.stylize_markdown(bufnr, contents, opts)
})
else
table.insert(stripped, line)
+ markdown_lines[#stripped] = true
i = i + 1
end
end
end
- -- Clean up
- stripped = M._trim(stripped, opts)
-- Compute size of float needed to show (wrapped) lines
opts.wrap_at = opts.wrap_at or (vim.wo["wrap"] and api.nvim_win_get_width(0))
local width, height = M._make_floating_popup_size(stripped, opts)
+ local sep_line = string.rep("─", math.min(width, opts.wrap_at or width))
+
+ for l in pairs(markdown_lines) do
+ if stripped[l]:match("^---+$") then
+ stripped[l] = sep_line
+ end
+ end
+
-- Insert blank line separator after code block
local insert_separator = opts.separator
if insert_separator == nil then insert_separator = true end
@@ -1213,10 +1225,8 @@ function M.stylize_markdown(bufnr, contents, opts)
h.finish = h.finish + offset
-- check if a seperator already exists and use that one instead of creating a new one
if h.finish + 1 <= #stripped then
- if stripped[h.finish + 1]:match("^---+$") then
- stripped[h.finish + 1] = string.rep("─", math.min(width, opts.wrap_at or width))
- else
- table.insert(stripped, h.finish + 1, string.rep("─", math.min(width, opts.wrap_at or width)))
+ if stripped[h.finish + 1] ~= sep_line then
+ table.insert(stripped, h.finish + 1, sep_line)
offset = offset + 1
height = height + 1
end
@@ -1224,6 +1234,7 @@ function M.stylize_markdown(bufnr, contents, opts)
end
end
+
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
local idx = 1
diff --git a/runtime/syntax/lsp_markdown.vim b/runtime/syntax/lsp_markdown.vim
index 1099ba204e..d9b50be54c 100644
--- a/runtime/syntax/lsp_markdown.vim
+++ b/runtime/syntax/lsp_markdown.vim
@@ -8,12 +8,10 @@
" markdown.vim syntax files
execute 'source' expand('<sfile>:p:h') .. '/markdown.vim'
-syn cluster mkdNonListItem add=mkdEscape,mkdNbsp,mkdLine
+syn cluster mkdNonListItem add=mkdEscape,mkdNbsp
syntax region mkdEscape matchgroup=mkdEscape start=/\\\ze[\\\x60*{}\[\]()#+\-,.!_>~|"$%&'\/:;<=?@^ ]/ end=/.\zs/ keepend contains=mkdEscapeCh oneline concealends
syntax match mkdEscapeCh /./ contained
syntax match mkdNbsp /&nbsp;/ conceal cchar=
-syntax match mkdLine /---/ conceal cchar=
-syntax match markdownH2 "" contained
hi def link mkdEscape special