API / @aionbuilders/nabu/extend

InputRule

Type Stability: stable

A declarative text-replacement rule applied while typing: when the text before the caret matches pattern, handler runs (the markdown shortcuts and the typography substitutions are input rules).

Definition

TypeScript
import type { InputRule } from '@aionbuilders/nabu/extend';
TypeScript
interface InputRule {
  handler: (nabu: Nabu, block: Block, match: RegExpMatchArray, sel: {
      data: string;
      from: number;
      isCollapsed: boolean;
      to: number;
    }) => boolean | void;
  inputType?: string;
  pattern: RegExp;
}

Properties

Properties of InputRule
PropertyTypeDescription
handler(nabu: Nabu, block: Block, match: RegExpMatchArray, sel: { data: string; from: number; isCollapsed: boolean; to: number; }) => boolean | void

sel.data est le texte en cours d'insertion (event.data). - Retourne true pour BREAK. NE PAS appeler commit() dans le handler.

inputTypeoptionalstring

Défaut: "insertText"

patternRegExp

Testé sur le texte AVANT le curseur (avec l'inputType "insertText")

Source: src/lib/utils/extensions.js:122