mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 22:34:26 -05:00
Again: Replace emoji-plugin regex
The Regex introduced in the last commit[1], was already working quite
good. But still resulted in false positives for all URL that contained a
second `:`.
To fix this once and for all, we craft a simple, but long regex based on
all emoji names and use this to match them.
We could probably optimize it, but that should also be something the
regex engine itself can and should do.
[1]: 7e45533c75
(in this source tree)
Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
parent
7e45533c75
commit
d188b3526a
1 changed files with 6 additions and 7 deletions
|
@ -1147,16 +1147,15 @@ const pdfPlugin = new Plugin(
|
||||||
|
|
||||||
const emojijsPlugin = new Plugin(
|
const emojijsPlugin = new Plugin(
|
||||||
// regexp to match emoji shortcodes :something:
|
// regexp to match emoji shortcodes :something:
|
||||||
/:([^\s:]+):/,
|
// We generate an universal regex that guaranteed only contains the
|
||||||
|
// emojies we have available. This should prevent all false-positives
|
||||||
|
new RegExp(':(' + window.emojify.emojiNames.map((item) => { return RegExp.escape(item) }).join('|') + '):', 'i'),
|
||||||
|
|
||||||
(match, utils) => {
|
(match, utils) => {
|
||||||
const emoji = match[1] ? match[1].toLowerCase() : undefined
|
const emoji = match[1].toLowerCase()
|
||||||
if (window.emojify.emojiNames.includes(emoji)) {
|
|
||||||
const div = $(`<img class="emoji" src="${serverurl}/build/emojify.js/dist/images/basic/${emoji}.png"></img>`)
|
const div = $(`<img class="emoji" src="${serverurl}/build/emojify.js/dist/images/basic/${emoji}.png"></img>`)
|
||||||
return div[0].outerHTML
|
return div[0].outerHTML
|
||||||
}
|
}
|
||||||
return match[0]
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// yaml meta, from https://github.com/eugeneware/remarkable-meta
|
// yaml meta, from https://github.com/eugeneware/remarkable-meta
|
||||||
|
|
Loading…
Reference in a new issue