- Introduced a new system for defining slash commands using templates, allowing for easier command creation and management. - Added multiple slash command templates, including for functions, queries, and admonitions, with specific context handling. - Enhanced existing Lua command definitions to support new template-based commands and improved context filtering. - Updated the `template.fromPage` function to handle raw template text, enabling more flexible command definitions.
1.3 KiB
1.3 KiB
#meta
Some convenient slash commands for editing Markdown files.
-- priority: 10
local function headerSlashCommand(level)
local line = editor.getCurrentLine()
local cleanText = string.gsub(line.textWithCursor, "^#+%s*", "")
editor.replaceRange(line.from, line.to,
string.rep("#", level) .. " " .. cleanText, true)
end
slashcommand.define {
name = "h1",
run = function()
headerSlashCommand(1)
end
}
slashcommand.define {
name = "h2",
run = function()
headerSlashCommand(2)
end
}
slashcommand.define {
name = "h3",
run = function()
headerSlashCommand(3)
end
}
slashcommand.define {
name = "h4",
run = function()
headerSlashCommand(4)
end
}
slashcommand.define {
name = "frontmatter",
run = function()
editor.insertAtPos([==[---
|^|
---
]==], 0, true)
end
}
slashcommand.define {
name = "task",
run = function()
local line = editor.getCurrentLine()
local ws, prefix, rest = string.match(line.textWithCursor, "^(%s*)([%-%*]?)%s*(.+)$")
editor.replaceRange(line.from, line.to, ws .. "* [ ] " .. rest, true)
end
}
slashcommand.define {
name = "space-lua",
description = "Insert Space Lua script",
run = function()
editor.insertAtCursor([==[```space-lua
|^|
```]==], false, true)
end
}