diff --git a/js/ckeditor.on-init.js b/js/ckeditor.on-init.js index d485099938..25131cdcd3 100644 --- a/js/ckeditor.on-init.js +++ b/js/ckeditor.on-init.js @@ -21,3 +21,24 @@ if ((CKEDITOR !== undefined) && (CKEDITOR.plugins.registered['disabler'] === und }); } + +// Rewrite the CKEditor Mentions plugin regexp to make it suitable for all Unicode alphabets. +if (CKEDITOR !== undefined && CKEDITOR.plugins.registered['mentions']) { + // from https://github.com/ckeditor/ckeditor4/blob/a3786007fb979d7d7bff3d10c34a2d422935baed/plugins/mentions/plugin.js#L147 + function createPattern(marker, minChars) { + let pattern = marker + '[\\p{L}\\p{N}_-]'; + if ( minChars ) { + pattern += '{' + minChars + ',}'; + } else { + pattern += '*'; + } + pattern += '$'; + return new RegExp(pattern, 'u'); + } + + CKEDITOR.on('instanceLoaded', event => { + event.editor.config.mentions.forEach(config => { + config.pattern = createPattern(config.marker, config.minChars); + }); + }); +}