patleeman / quill-markdown-shortcuts

Quill.js module that converts markdown to rich text formatting while typing.
https://patleeman.github.io/quill-markdown-shortcuts/
139 stars 49 forks source link

Make the trigger keys extendable with an option #31

Open petemcfarlane opened 4 years ago

petemcfarlane commented 4 years ago

I've got some pesky non-breaking white space characters interfering with the default regex which detects if a space key has been pressed. I can solve it locally by extending the MarkdownShortcuts module, but thought it'd be a nice option if you could configure the regex.

e.g. my current solution

MyMarkdownShortcuts extends MarkdownShortcuts {
  constructor(quill, options) {
    super(quill, options);
    this.quill.on('text-change', (delta) => {
      delta.ops.forEach (op => {
        if (Object.prototype.hasOwnProperty.call(op, 'insert')) {
          if (/\u00A0/.test(op.insert)) {
            this.onSpace();
          }
        }
      });
    });
  }
}

suggestion, in quill config:

{
  // ...
  markdownShortcuts: {
    onSpaceTrigger: /\u00A0|\ / // custom regex here
  }
}