I saw the docs for slash commands mention "AST node contexts", which seemed cool, but I couldn't figure out what the valid inputs would be for this!
The good news is, I was able to make a slash command to insert the current AST context into my doc so that I can see what some good candidates for this would be.
slashCommand.define {
name = "dbg-ast-context",
description = "Debug: insert AST parent context at cursor",
priority = -99,
run = function()
local pos = editor.getCursor()
local chain = {}
local function walk(node)
if not node.type or pos < node.from or pos >= node.to then return end
local lbl = node.type
if lbl == "FencedCode" then
for _, c in ipairs(node.children or {}) do
if c.type == "CodeInfo" then
lbl = "FencedCode:" .. c.children[1].text
break
end
end
end
table.insert(chain, lbl)
for _, child in ipairs(node.children or {}) do walk(child) end
end
walk(markdown.parseMarkdown(editor.getText()))
editor.insertAtCursor(table.concat(chain, " > "))
end
}
P.S. The bad news is, it seems like the context value isn't ideal for things like tasks. I was going to add a /deadline command to insert [deadline: <value>], but it appears the context here is just "Document" when triggered at the end of the task. Opened an issue here