0.12.1 • Published 6 years ago

slate-auto-replace v0.12.1

Weekly downloads
5,625
License
MIT
Repository
github
Last release
6 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: /^(>)$/,
    change: (change, e, matches) => {
      return change.setBlocks({ 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.
changeFunctionA 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.
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 change 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 change function.
0.12.1

6 years ago

0.12.0

6 years ago

0.11.2

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.1

6 years ago

0.9.0

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

8 years ago