4.1.3 • Published 4 years ago

@gitbook/slate-auto-replace v4.1.3

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

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.

npm.io


Install

npm install --save slate-auto-replace

You will need to have installed slate as a dependency already.


Usage

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

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

// And later pass it into the Slate editor...
<Editor
  ...
  plugins={plugins}
/>
OptionTypeDescription
triggerString RegExpThe 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 passed a Slate Transform object and the data object from the matching event handler.
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.
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.
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.

Development

Clone the repository and then run:

npm install
npm run watch

And open the example page in your browser:

http://localhost:8888/

License

Copyright © 2016, Ian Storm Taylor

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

4.1.3

4 years ago

4.1.2

4 years ago

4.1.0

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.2.8

5 years ago

3.2.7

5 years ago

3.2.6

5 years ago

3.2.5

5 years ago

3.2.4

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.0

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-alpha.8

5 years ago

3.0.0-alpha.7

5 years ago

3.0.0-alpha.6

5 years ago

3.0.0-alpha.5

5 years ago

3.0.0-alpha.4

5 years ago

3.0.0-alpha.3

5 years ago

3.0.0-alpha.2

5 years ago

3.0.0-alpha.1

5 years ago

3.0.0-alpha.0

5 years ago

2.0.0

5 years ago

0.9.1

6 years ago