0.9.8 • Published 2 years ago

slate-auto-replace-legacy v0.9.8

Weekly downloads
4
License
MIT
Repository
github
Last release
2 years ago

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: /^(>)$/,
    transform: (transform, e, matches) => {
      return transform.setBlock({ type: 'quote' })
    }
  })
]

// And later pass it into the Slate editor...
<Editor
  ...
  plugins={plugins}
/>
OptionTypeDescription
triggerString RegExp FunctionThe trigger to match the inputed character against—either a character like a or a key name like enter or tab.
transformFunctionA function to apply the desired transform. It will be called with transform, e, matches, editor from the event handler. The matching (before and after) text is deleted but are accessible inside matches.before and matches.after.
afterRegExpAn 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 transform function.
beforeRegExpAn 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 transform function.
ignoreInFunction Array StringAn optional block matcher to ignore triggers inside. If passed an array or string it will match by node.type.
onlyInFunction Array StringAn optional block matcher to only replace triggers inside. If passed an array or string it will match by node.type.
0.9.8

2 years ago

0.9.7

2 years ago

0.9.5

3 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago