Files
plainleaf/libraries/Library/Std/Infrastructure/Slash Templates.md
T
Zef Hemel 26d9d5bdf0 Restructure standard library and improve documentation
Refactor Library/Std into subfolders for APIs, Infrastructure, Editor,
Widgets, etc. Add more documentation and descriptions. Update references
throughout website and docs.
2025-10-01 11:22:31 +02:00

1.5 KiB
Raw Blame History

description, tags
description tags
Implements the infrastructure of Slash Templates. meta

Allows for quick definition of slash commands based on templates.

Creating slash templates

Create a page with the #meta/template/slash tag. The last component of the page name (after the / if any) will be used as the slash command’s name. The body of the page will be used as the text to be inserted, using Lua directives is supported.

Configuration

You can configure some specifics about your slash template in its template page’s frontmatter.

Optional keys:

  • description: The description of the slash command
  • priority: To prioritize the slash command higher in the list
  • onlyContexts (advanced): To only make the slash command appear in certain (AST node based) contexts
  • exceptContexts (advanced): To make the slash command appear everywhere except in these (AST node) contexts

Currently active slash templates

${template.each(query[[ from index.tag "meta/template/slash" where _.tag == "page" ]], templates.fullPageItem)}

Implementation

for st in query[[
    from index.tag "meta/template/slash"
    where _.tag == "page"
  ]] do
  local components = st.name:split("/")
  local name = components[#components]
  slashCommand.define {
    name = name,
    description = st.description,
    priority = st.priority,
    onlyContexts = st.onlyContexts,
    exceptContexts = st.exceptContexts,
    run = function()
      local tpl = template.fromPage(st.name, st.raw)
      editor.insertAtCursor(tpl(), false, true)
    end
  }
end