Skip to content

Commit

Permalink
feat(toc): add toc item filter (nvim-neorg#1195)
Browse files Browse the repository at this point in the history
Co-authored-by: vhyrro <76052559+vhyrro@users.noreply.github.com>
  • Loading branch information
2 people authored and benlubas committed Jan 11, 2024
1 parent 53fba50 commit 573b1e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/neorg/modules/core/qol/toc/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ module.config.public = {
-- If `true`, the width of the Table of Contents window will automatically
-- fit its longest line
fit_width = true,

-- A function that takes node type as argument and returns true if this
-- type of node should appear in the Table of Contents
toc_filter = function(node_type) return node_type:match("^heading") end,
}

module.public = {
Expand Down Expand Up @@ -149,6 +153,7 @@ module.public = {

local prefix, title
local extmarks = {}
local toc_filter = module.config.public.toc_filter

local success = module.required["core.integrations.treesitter"].execute_query(
[[
Expand All @@ -163,7 +168,7 @@ module.public = {
local capture = query.captures[id]

if capture == "prefix" then
if node:type():match("_prefix$") then
if node:type():match("_prefix$") and (type(toc_filter) ~= 'function' or toc_filter(node:type())) then
prefix = node
else
prefix = nil
Expand Down

0 comments on commit 573b1e5

Please sign in to comment.