mirror of
https://github.com/neovim/neovim.git
synced 2025-11-11 13:05:37 +00:00
fix(lsp): replace --- by a line in stylize_markdown
This commit is contained in:
@@ -1166,8 +1166,13 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
return line:match(string.format("^%%s*%s%%s*$", pattern[3]))
|
return line:match(string.format("^%%s*%s%%s*$", pattern[3]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Clean up
|
||||||
|
contents = M._trim(contents, opts)
|
||||||
|
|
||||||
local stripped = {}
|
local stripped = {}
|
||||||
local highlights = {}
|
local highlights = {}
|
||||||
|
-- keep track of lnums that contain markdown
|
||||||
|
local markdown_lines = {}
|
||||||
do
|
do
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= #contents do
|
while i <= #contents do
|
||||||
@@ -1192,17 +1197,24 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
})
|
})
|
||||||
else
|
else
|
||||||
table.insert(stripped, line)
|
table.insert(stripped, line)
|
||||||
|
markdown_lines[#stripped] = true
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Clean up
|
|
||||||
stripped = M._trim(stripped, opts)
|
|
||||||
|
|
||||||
-- Compute size of float needed to show (wrapped) lines
|
-- 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))
|
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 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
|
-- Insert blank line separator after code block
|
||||||
local insert_separator = opts.separator
|
local insert_separator = opts.separator
|
||||||
if insert_separator == nil then insert_separator = true end
|
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
|
h.finish = h.finish + offset
|
||||||
-- check if a seperator already exists and use that one instead of creating a new one
|
-- check if a seperator already exists and use that one instead of creating a new one
|
||||||
if h.finish + 1 <= #stripped then
|
if h.finish + 1 <= #stripped then
|
||||||
if stripped[h.finish + 1]:match("^---+$") then
|
if stripped[h.finish + 1] ~= sep_line then
|
||||||
stripped[h.finish + 1] = string.rep("─", math.min(width, opts.wrap_at or width))
|
table.insert(stripped, h.finish + 1, sep_line)
|
||||||
else
|
|
||||||
table.insert(stripped, h.finish + 1, string.rep("─", math.min(width, opts.wrap_at or width)))
|
|
||||||
offset = offset + 1
|
offset = offset + 1
|
||||||
height = height + 1
|
height = height + 1
|
||||||
end
|
end
|
||||||
@@ -1224,6 +1234,7 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
|
||||||
|
|
||||||
local idx = 1
|
local idx = 1
|
||||||
|
|||||||
@@ -8,12 +8,10 @@
|
|||||||
" markdown.vim syntax files
|
" markdown.vim syntax files
|
||||||
execute 'source' expand('<sfile>:p:h') .. '/markdown.vim'
|
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 region mkdEscape matchgroup=mkdEscape start=/\\\ze[\\\x60*{}\[\]()#+\-,.!_>~|"$%&'\/:;<=?@^ ]/ end=/.\zs/ keepend contains=mkdEscapeCh oneline concealends
|
||||||
syntax match mkdEscapeCh /./ contained
|
syntax match mkdEscapeCh /./ contained
|
||||||
syntax match mkdNbsp / / conceal cchar=
|
syntax match mkdNbsp / / conceal cchar=
|
||||||
syntax match mkdLine /---/ conceal cchar=
|
|
||||||
syntax match markdownH2 "" contained
|
|
||||||
|
|
||||||
hi def link mkdEscape special
|
hi def link mkdEscape special
|
||||||
|
|||||||
Reference in New Issue
Block a user