From 73e72ee21d7673e4040bb99f4de834410219d6cb Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 29 Jun 2024 15:37:48 +0200 Subject: [PATCH] perf(markdown): don't format with markdown-toc when no toc in the doc --- lua/lazyvim/plugins/extras/lang/markdown.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/markdown.lua b/lua/lazyvim/plugins/extras/lang/markdown.lua index fd7c6723..776ae0d7 100644 --- a/lua/lazyvim/plugins/extras/lang/markdown.lua +++ b/lua/lazyvim/plugins/extras/lang/markdown.lua @@ -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("") 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" }, }, }, },