Skip to content

Commit

Permalink
fix(suggester): extract replacer from toHtml to avoid regex error in …
Browse files Browse the repository at this point in the history
…safari
  • Loading branch information
jiawei686 authored and humyfred committed Jan 5, 2022
1 parent 879a523 commit 760449e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/core/hooks/Suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,19 @@ export default class Suggester extends SyntaxBase {
return replaceLookbehind(str, this.RULE.reg, this.toHtml.bind(this), true, 1);
}

toHtml(str) {
return str.replace(this.RULE.reg, (wholeMatch, keyword, text) => {
if (text && text !== 'undefined') {
return (
this.suggester[keyword]?.echo?.call(this, text) || `<span class="cherry-suggestion">${keyword}${text}</span>`
);
}
if (this.suggester[keyword]?.echo === false) {
return '';
}
if (!this.suggester[keyword]) {
return text;
}
return text === 'undefined' || text === null ? '' : text;
});
toHtml(wholeMatch, leadingChar, keyword, text) {
if (text) {
return (
this.suggester[keyword]?.echo?.call(this, text) || `<span class="cherry-suggestion">${keyword}${text}</span>`
);
}
if (this.suggester[keyword]?.echo === false) {
return '';
}
if (!this.suggester[keyword]) {
return text;
}
return text ?? '';
}

rule() {
Expand Down

0 comments on commit 760449e

Please sign in to comment.