🐛 N°4834 - Fix mentions working only with latin alphabet (no dash, no cyrillic, no asian, ...) (#274)

* 🐛 Add the 'pattern' parameter with the unicode Cyrillic block regex to the CKEditor mentions config.

* Revert "🐛 Add the 'pattern' parameter with the unicode Cyrillic block regex to the CKEditor mentions config."

This reverts commit 1f5ac000b6.

* 🐛 Rewrite the CKEditor Mentions plugin regexp to make it suitable for all Unicode alphabets.
This commit is contained in:
Vladimir Kunin
2022-05-16 21:06:30 +03:00
committed by GitHub
parent ff58fb8617
commit f3e601e340

View File

@@ -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);
});
});
}