Note kit command

text.findReplace

Find and replace

Replaces matches of `find` in the note's body with `replace` (matches in the front matter are not counted: change properties with `property.set`): the first by default, the n-th with `occurrence`, or every one with `occurrence: "all"`; `regex` and `caseSensitive` as in `text.find`. Answers how many were replaced.

Kit
Note 0.3.0 (Markdown (.md))
Changes the document
yes

Parameters

Parameters of text.findReplace
NameTypeRequiredDescription
caseSensitivebooleannoMatch case.
findstringyesThe text, or a regular expression with regex.
occurrenceanynoWhich match to replace: a number from 1, or "all"; 1 by default.
regexbooleannoRead find as a regular expression (Rust syntax).
replacestringyesThe replacement; with regex, $1 names a group.

Call through note_run

text
note_run {
  "path": "<file>.md",
  "steps": [{ "command": "text.findReplace", "params": { "find": <string>, "replace": <string> } }]
}

The required parameters, with placeholders for their types: not a tested example. Optional: caseSensitive, occurrence, regex. note_run answers the step’s result in completed[i].result.

Result

Result of text.findReplace
NameTypeRequiredDescription
changedbooleanyesWhether the note's text changed.
replacedintegeryesHow many matches were replaced.
Result JSON Schema
json
{
  "additionalProperties": false,
  "properties": {
    "changed": {
      "description": "Whether the note's text changed.",
      "type": "boolean"
    },
    "replaced": {
      "description": "How many matches were replaced.",
      "type": "integer"
    }
  },
  "required": [
    "changed",
    "replaced"
  ],
  "type": "object"
}

Parameter schema

json
{
  "additionalProperties": false,
  "properties": {
    "caseSensitive": {
      "default": true,
      "description": "Match case.",
      "type": "boolean"
    },
    "find": {
      "description": "The text, or a regular expression with regex.",
      "type": "string"
    },
    "occurrence": {
      "description": "Which match to replace: a number from 1, or \"all\"; 1 by default."
    },
    "regex": {
      "description": "Read find as a regular expression (Rust syntax).",
      "type": "boolean"
    },
    "replace": {
      "description": "The replacement; with regex, $1 names a group.",
      "type": "string"
    }
  },
  "required": [
    "find",
    "replace"
  ],
  "type": "object"
}

Generated from kition-sdk packages/script/kits/note.ts and the kit itself (kition-note@69e14d9). As data: commands.jsonl.