diff --git a/lua/noice/text/markdown.lua b/lua/noice/text/markdown.lua index 1e2ff092..0d52ad4c 100644 --- a/lua/noice/text/markdown.lua +++ b/lua/noice/text/markdown.lua @@ -92,7 +92,7 @@ function M.parse(text, opts) end elseif M.is_code_block(line) then ---@type string - local lang = line:match("```(%S+)") or opts.ft or "text" + local lang = line:match("```%s*(%S+)") or opts.ft or "text" local block = { lang = lang, code = {} } while lines[l + 1] and not M.is_code_block(lines[l + 1]) do table.insert(block.code, lines[l + 1]) diff --git a/tests/text/markdown_spec.lua b/tests/text/markdown_spec.lua index 29efb8e8..0a6bc5d1 100644 --- a/tests/text/markdown_spec.lua +++ b/tests/text/markdown_spec.lua @@ -131,7 +131,7 @@ local b { input = [[ - *** + *** ```lua local a @@ -149,6 +149,24 @@ local a { input = [[ + *** + + ``` lua +local a + ``` + + --- + + ]], + output = { + { line = "---" }, + { code = { "local a" }, lang = "lua" }, + { line = "---" }, + }, + }, + { + input = [[ + ```lua local a ```