format

On this page

Description:
Appears in:
└── Snippet
    └── params
        └── *
            ├── Argument List Parser Configuration
            │   └── options
            │       └── format
            ├── Argument Parser Configuration
            │   └── options
            │       └── format
            └── Key Value List Parser Configuration
                └── options
                    └── format
Types:

This key defines formatting options for parsing snippet parameters.

The value is an object that can contain various options controlling how snippet parameters are parsed, including boundaries, delimiters, allowed value types, and string formatting options.

Appears in: format, Snippet Definition Value.

Show examplesHide examples

A common option to configure for the argument parser is the string_boundary:

Copied to clipboard
_snippets:
  video:
    snippet: <<video [[video_arg]]>>
    params:
      video_arg:
        parser: argument
        options:
          model:
            editor_key: video_id
          format:
            string_boundary:
              - '"'
              - '`'
{
  "_snippets": {
    "video": {
      "snippet": "<<video [[video_arg]]>>",
      "params": {
        "video_arg": {
          "parser": "argument",
          "options": {
            "model": {
              "editor_key": "video_id"
            },
            "format": {
              "string_boundary": [
                "\"",
                "`"
              ]
            }
          }
        }
      }
    }
  }
}

This would make our snippet match <<video "CZcNgDN81Sw">> or <<video `CZcNgDN81Sw`>> but not <<video 'CZcNgDN81Sw'>> or <<video CZcNgDN81Sw>>.

Another common requirement is specifying forbidden_tokens, especially when defining an argument with no string boundary.

Copied to clipboard
_snippets:
  video:
    snippet: <<video [[video_arg]]>>
    params:
      video_arg:
        parser: argument
        options:
          model:
            editor_key: video_id
          format:
            forbidden_tokens:
              - '>'
            string_boundary:
              - ''
{
  "_snippets": {
    "video": {
      "snippet": "<<video [[video_arg]]>>",
      "params": {
        "video_arg": {
          "parser": "argument",
          "options": {
            "model": {
              "editor_key": "video_id"
            },
            "format": {
              "forbidden_tokens": [
                ">"
              ],
              "string_boundary": [
                ""
              ]
            }
          }
        }
      }
    }
  }
}

References a reusable value defined in _snippets_definitions by key, resolved at runtime.

Appears in: format.

Examples:
Open in a new tab