mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
fix(lsp): replace --- by a line in stylize_markdown
This commit is contained in:
parent
b28d458f87
commit
d7d1f40d2c
@ -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
|
||||
|
@ -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 / / conceal cchar=
|
||||
syntax match mkdLine /---/ conceal cchar=
|
||||
syntax match markdownH2 "" contained
|
||||
|
||||
hi def link mkdEscape special
|
||||
|
Loading…
Reference in New Issue
Block a user