Skip to content

Templates, Snippets, Formats and Keys ​

These four contributions use the same formats as the user's own templates, snippets and custom formats. An extension just ships them.

Templates ​

json
"contributes": { "templates": "templates" }

templates names a folder inside your extension. Every .md, .markdown or .txt file in it (up to 200) becomes a template. Sub-folders become groups.

markdown
---
typora-template:
  description: Agenda, notes and action items
  filename: "{{date}} Meeting"
title: "{{title}}"
tags: [meeting]
---

# {{title}}

**Date:** {{date:dddd, MMMM D}}

## Agenda

{{cursor}}

The typora-template key is removed when the template is used. All other front matter is copied into the new document. See variables.

Templates appear under File ▸ New from Template, in the file tree's New from Template menu, and in the / menu of an empty document — grouped under your extension's name.

Snippets ​

json
"contributes": { "snippets": "snippets" }

Same rules as templates: one file per snippet, sub-folders are groups. Metadata goes under typora-snippet:

markdown
---
typora-snippet:
  description: A chart fence with sample data
  prefix: [chart]
---
```chart
type: bar
title: {{1:Quarterly Revenue}}
Q1, 120
Q2, 180
```

prefix is the trigger word (a string or a list). Users insert snippets by typing the trigger (; by default) and the prefix, from the / menu, from Edit ▸ Insert Snippet, or from the command palette.

Custom formats ​

json
"contributes": {
  "customFormats": [
    { "name": "Teal Text", "open": "<span style=\"color:teal\">", "close": "</span>", "shortcut": "Mod+Alt+Shift+T" }
  ]
}
FieldRequiredDescription
nameyesShown in Format ▸ Custom Formats and the command palette (Custom Format: name).
openyesText inserted before the selection.
closeyesText inserted after the selection.
shortcutDefault key binding.

Applying a format again removes it. A format of the same family (same tag and first style property, e.g. two span colours) replaces the existing wrapper instead of nesting.

Key bindings ​

json
"contributes": {
  "keyBindings": [
    { "command": "paragraph.insertTable", "key": "Mod+Alt+T" },
    { "command": "spacing", "key": "Mod+Alt+Shift+S" }
  ]
}
FieldDescription
commandOne of your own command ids, or a Typora command id such as format.strong or paragraph.insertTable.
keyModifiers and a key joined with +. Mod (or CmdOrCtrl) is ⌘ on macOS and Ctrl elsewhere. Other modifiers: Ctrl, Cmd / Meta, Alt / Option, Shift. The last part is the key, e.g. T, F5, Enter.

Extension key bindings don't fire while focus is in Settings.

Theme adapted from Nimbus (MIT).