-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `:ObsidianTOC` command See #635 * fix docs workflow
- Loading branch information
Showing
6 changed files
with
38 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
local util = require "obsidian.util" | ||
|
||
---@param client obsidian.Client | ||
return function(client, _) | ||
local note = assert(client:current_note(0, { collect_anchor_links = true })) | ||
|
||
---@type obsidian.PickerEntry[] | ||
local picker_entries = {} | ||
for _, anchor in pairs(note.anchor_links) do | ||
local display = string.rep("#", anchor.level) .. " " .. anchor.header | ||
table.insert( | ||
picker_entries, | ||
{ value = display, display = display, filename = tostring(note.path), lnum = anchor.line } | ||
) | ||
end | ||
|
||
-- De-duplicate and sort. | ||
picker_entries = util.tbl_unique(picker_entries) | ||
table.sort(picker_entries, function(a, b) | ||
return a.lnum < b.lnum | ||
end) | ||
|
||
local picker = assert(client:picker()) | ||
picker:pick(picker_entries, { prompt_title = "Table of Contents" }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters