mirror of
https://github.com/neovim/neovim.git
synced 2026-08-01 05:09:08 +00:00
fix(lsp): incorrect rendering of markdown codeblock #40861
Problem:
LSP hover erroneously drops blank lines before a 4-space-indented
codeblock, which is not valid Markdown. This causes incorrect parsing
and wrong display.
Solution:
Fix `split_lines` so that it doesn't drop the blank line just before
a 4-space-indented codeblock.
fix https://github.com/neovim/neovim/issues/40860
(cherry picked from commit 317c5ddda6)
This commit is contained in:
committed by
github-actions[bot]
parent
37d7b11bc1
commit
ba2ea67a1f
@@ -92,18 +92,29 @@ end
|
||||
---
|
||||
--- @param s string Multiline string
|
||||
--- @param no_blank boolean? Drop blank lines for each @param/@return (except one empty line
|
||||
--- separating each). Workaround for https://github.com/LuaLS/lua-language-server/issues/2333
|
||||
--- separating each, and before a codeblock).
|
||||
--- Workaround for https://github.com/LuaLS/lua-language-server/issues/2333
|
||||
local function split_lines(s, no_blank)
|
||||
s = string.gsub(s, '\r\n?', '\n')
|
||||
local raw = vim.split(s, '\n', { plain = true, trimempty = true })
|
||||
|
||||
--- @return boolean # true if line begins a (4-space-indented) codeblock. #40860
|
||||
local function codeblock(l)
|
||||
return l:find('^ ') or l:find('^\t')
|
||||
end
|
||||
|
||||
local lines = {}
|
||||
local in_desc = true -- Main description block, before seeing any @foo.
|
||||
for line in vim.gsplit(s, '\n', { plain = true, trimempty = true }) do
|
||||
for i, line in ipairs(raw) do
|
||||
local start_annotation = not not line:find('^ ?%@.?[pr]')
|
||||
in_desc = (not start_annotation) and in_desc or false
|
||||
if start_annotation and no_blank and not (lines[#lines] or ''):find('^%s*$') then
|
||||
table.insert(lines, '') -- Separate each @foo with a blank line.
|
||||
end
|
||||
if in_desc or not no_blank or not line:find('^%s*$') then
|
||||
|
||||
local blank = line:find('^%s*$')
|
||||
local keep_blank = blank and codeblock(raw[i + 1] or '') -- Keep if it precedes a codeblock. #40860
|
||||
if in_desc or not no_blank or not blank or keep_blank then
|
||||
table.insert(lines, line)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user