summaryrefslogtreecommitdiff
path: root/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
commitc80a54e42b52ce297f0f2f71af23c562832025c7 (patch)
treedcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua
init
Diffstat (limited to 'ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua')
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua
new file mode 100644
index 0000000..1b1c591
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua
@@ -0,0 +1,26 @@
+local M = {}
+
+-- foldtext for Neovim < 0.10.0
+function M.foldtext()
+ return vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1]
+end
+
+-- optimized treesitter foldexpr for Neovim >= 0.10.0
+function M.foldexpr()
+ local buf = vim.api.nvim_get_current_buf()
+ if vim.b[buf].ts_folds == nil then
+ -- as long as we don't have a filetype, don't bother
+ -- checking if treesitter is available (it won't)
+ if vim.bo[buf].filetype == "" then
+ return "0"
+ end
+ if vim.bo[buf].filetype:find("dashboard") then
+ vim.b[buf].ts_folds = false
+ else
+ vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf)
+ end
+ end
+ return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or "0"
+end
+
+return M