perf(markdown): don't format with markdown-toc when no toc in the doc

This commit is contained in:
Folke Lemaitre
2024-06-29 15:37:48 +02:00
parent b43ace1ecf
commit 73e72ee21d

View File

@ -14,9 +14,20 @@ return {
"stevearc/conform.nvim",
optional = true,
opts = {
formatters = {
["markdown-toc"] = {
condition = function(_, ctx)
for _, line in ipairs(vim.api.nvim_buf_get_lines(ctx.buf, 0, -1, false)) do
if line:find("<!%-%- toc %-%->") then
return true
end
end
end,
},
},
formatters_by_ft = {
["markdown"] = { { "prettierd", "prettier" }, "markdownlint-cli2", "markdown-toc" },
["markdown.mdx"] = { { "prettierd", "prettier" }, "markdownlint-cli2", "markdown-toc" },
["markdown"] = { "prettier", "markdownlint-cli2", "markdown-toc" },
["markdown.mdx"] = { "prettier", "markdownlint-cli2", "markdown-toc" },
},
},
},