From fe6b1bee2db942f7adfc5901e7585328b122e773 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 7 Dec 2018 21:05:10 +0300 Subject: [PATCH] Escape Suggestion trigger char --- packages/tiptap-extensions/src/plugins/Suggestions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/tiptap-extensions/src/plugins/Suggestions.js b/packages/tiptap-extensions/src/plugins/Suggestions.js index 7ab6af28..63b40ba3 100644 --- a/packages/tiptap-extensions/src/plugins/Suggestions.js +++ b/packages/tiptap-extensions/src/plugins/Suggestions.js @@ -11,11 +11,12 @@ function triggerCharacter({ return $position => { // Matching expressions used for later - const suffix = new RegExp(`\\s${char}$`) + const escapedChar = `\\${char}` + const suffix = new RegExp(`\\s${escapedChar}$`) const prefix = startOfLine ? '^' : '' const regexp = allowSpaces - ? new RegExp(`${prefix}${char}.*?(?=\\s${char}|$)`, 'gm') - : new RegExp(`${prefix}(?:^)?${char}[^\\s${char}]*`, 'gm') + ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm') + : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm') // Lookup the boundaries of the current node const textFrom = $position.before()