aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters/injected.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-12-26 15:14:42 +0000
committerSteven Arcangeli <stevearc@stevearc.com>2023-12-26 16:49:54 +0000
commit9245b616d1edb159775a0832c03324bf92884494 (patch)
treebeb9aa2c5af4385d4579375a30e91114d480de5b /lua/conform/formatters/injected.lua
parentf245cca8ad42c9d344b53a18c3fc1a3c6724c2d4 (diff)
fix(injected): code block at end of markdown file
Diffstat (limited to 'lua/conform/formatters/injected.lua')
-rw-r--r--lua/conform/formatters/injected.lua5
1 files changed, 4 insertions, 1 deletions
diff --git a/lua/conform/formatters/injected.lua b/lua/conform/formatters/injected.lua
index 363889e..fd67439 100644
--- a/lua/conform/formatters/injected.lua
+++ b/lua/conform/formatters/injected.lua
@@ -127,7 +127,10 @@ return {
local errors = require("conform.errors")
local log = require("conform.log")
local util = require("conform.util")
- local text = table.concat(lines, "\n")
+ -- Need to add a trailing newline; some parsers need this.
+ -- For example, if a markdown code block ends at the end of the file, a trailing newline is
+ -- required otherwise the ``` will be grabbed as part of the injected block
+ local text = table.concat(lines, "\n") .. "\n"
local buf_lang = vim.treesitter.language.get_lang(vim.bo[ctx.buf].filetype)
local ok, parser = pcall(vim.treesitter.get_string_parser, text, buf_lang)
if not ok then