Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

slate-auto-replace

ianstormtaylor11.9kMIT0.12.1

A Slate plugin to automatically transform certain input.

slate

readme

slate-auto-replace

A Slate plugin to automatically replace text and apply transforms when the user types certain strings. Useful for implementing "auto-markdown" or other hotkey-based replacement behaviors.

View Demo ⬈

import AutoReplace from 'slate-auto-replace'
import { Editor } from 'slate-react'

// Add the plugin to your set of plugins...
const plugins = [
  AutoReplace({
    trigger: 'space',
    before: /^(>)$/,
    change: (change, e, matches) => {
      return change.setBlocks({ type: 'quote' })
    }
  })
]

// And later pass it into the Slate editor...
<Editor
  ...
  plugins={plugins}
/>
Option Type Description
trigger String RegExp Function The trigger to match the inputed character against—either a character like a or a key name like enter or tab.
change Function A function to apply the desired change. It will be called with change, e, matches, editor from the event handler. The matching (before and after) text is deleted but are accessible inside matches.before and matches.after.
after RegExp An optional regexp that must match the text after the trigger for the replacement to occur. Any capturing groups in the regexp will be deleted from the text content, but is accessible in matches parameter in the change function.
before RegExp An optional regexp that must match the text before the trigger for the replacement to occur. Any capturing groups in the regexp will be deleted from the text content, but is accessible in matches parameter in the change function.

changelog

Changelog

This document maintains a list of changes. Until 1.0.0 is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly.


0.12.0 — October 10, 2018


0.11.0 — August 7, 2018

  • Remove options.onlyIn and options.ignoreIn.

0.10.0 — August 6, 2018

  • Update for `slate@0.37.0`.
  • Rename options.transform to options.change for consistency.

0.9.0 — October 28, 2017


0.8.0 — October 17, 2017


0.7.0 — October 16, 2017

  • Update for `slate-react@0.5.0`.
  • Change all triggers to be onKeyDown instead of onBeforeInput.

0.6.0 — September 6, 2017


0.5.0 — April 24, 2017

  • Fix deprecated calls to selection.moveToOffsets().

0.4.0 — February 27, 2017


0.3.0 — January 27, 2017

  • Add support for options.trigger functions.

0.2.0 — Nobember 30, 2016


0.1.0 — August 10, 2016

:tada: