mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 09:45:13 +08:00
967010e545
This feature will allow sites to define which emoji are not allowed. Emoji in this list should be excluded from the set we show in the core emoji picker used in the composer for posts when emoji are enabled. And they should not be allowed to be chosen to be added to messages or as reactions in chat. This feature prevents denied emoji from appearing in the following scenarios: - topic title and page title - private messages (topic title and body) - inserting emojis into a chat - reacting to chat messages - using the emoji picker (composer, user status etc) - using search within emoji picker It also takes into account the various ways that emojis can be accessed, such as: - emoji autocomplete suggestions - emoji favourites (auto populates when adding to emoji deny list for example) - emoji inline translations - emoji skintones (ie. for certain hand gestures)
134 lines
2.9 KiB
JavaScript
134 lines
2.9 KiB
JavaScript
import {
|
|
cook as cookIt,
|
|
setup as setupIt,
|
|
} from "pretty-text/engines/discourse-markdown-it";
|
|
import { deepMerge } from "discourse-common/lib/object";
|
|
import deprecated from "discourse-common/lib/deprecated";
|
|
|
|
export function registerOption() {
|
|
deprecated(
|
|
"`registerOption() from `pretty-text` is deprecated. Use `helper.registerOptions()` instead.",
|
|
{
|
|
since: "2.8.0.beta9",
|
|
dropFrom: "2.9.0.beta1",
|
|
id: "discourse.pretty-text.registerOption",
|
|
}
|
|
);
|
|
}
|
|
|
|
// see also: __optInput in PrettyText#cook and PrettyText#markdown,
|
|
// the options are passed here and must be explicitly allowed with
|
|
// the const options & state below
|
|
export function buildOptions(state) {
|
|
const {
|
|
siteSettings,
|
|
getURL,
|
|
lookupAvatar,
|
|
lookupPrimaryUserGroup,
|
|
getTopicInfo,
|
|
topicId,
|
|
forceQuoteLink,
|
|
categoryHashtagLookup,
|
|
userId,
|
|
getCurrentUser,
|
|
currentUser,
|
|
lookupAvatarByPostNumber,
|
|
lookupPrimaryUserGroupByPostNumber,
|
|
formatUsername,
|
|
emojiUnicodeReplacer,
|
|
lookupUploadUrls,
|
|
previewing,
|
|
censoredRegexp,
|
|
disableEmojis,
|
|
customEmojiTranslation,
|
|
watchedWordsReplace,
|
|
watchedWordsLink,
|
|
emojiDenyList,
|
|
featuresOverride,
|
|
markdownItRules,
|
|
additionalOptions,
|
|
hashtagTypesInPriorityOrder,
|
|
hashtagIcons,
|
|
hashtagLookup,
|
|
} = state;
|
|
|
|
let features = {};
|
|
|
|
if (state.features) {
|
|
features = deepMerge(features, state.features);
|
|
}
|
|
|
|
const options = {
|
|
sanitize: true,
|
|
getURL,
|
|
features,
|
|
lookupAvatar,
|
|
lookupPrimaryUserGroup,
|
|
getTopicInfo,
|
|
topicId,
|
|
forceQuoteLink,
|
|
categoryHashtagLookup,
|
|
userId,
|
|
getCurrentUser,
|
|
currentUser,
|
|
lookupAvatarByPostNumber,
|
|
lookupPrimaryUserGroupByPostNumber,
|
|
formatUsername,
|
|
emojiUnicodeReplacer,
|
|
lookupUploadUrls,
|
|
censoredRegexp,
|
|
customEmojiTranslation,
|
|
allowedHrefSchemes: siteSettings.allowed_href_schemes
|
|
? siteSettings.allowed_href_schemes.split("|")
|
|
: null,
|
|
allowedIframes: siteSettings.allowed_iframes
|
|
? siteSettings.allowed_iframes.split("|")
|
|
: [],
|
|
markdownIt: true,
|
|
previewing,
|
|
disableEmojis,
|
|
watchedWordsReplace,
|
|
watchedWordsLink,
|
|
emojiDenyList,
|
|
featuresOverride,
|
|
markdownItRules,
|
|
additionalOptions,
|
|
hashtagTypesInPriorityOrder,
|
|
hashtagIcons,
|
|
hashtagLookup,
|
|
};
|
|
|
|
// note, this will mutate options due to the way the API is designed
|
|
// may need a refactor
|
|
setupIt(options, siteSettings, state);
|
|
|
|
return options;
|
|
}
|
|
|
|
export default class {
|
|
constructor(opts) {
|
|
if (!opts) {
|
|
opts = buildOptions({ siteSettings: {} });
|
|
}
|
|
this.opts = opts;
|
|
}
|
|
|
|
disableSanitizer() {
|
|
this.opts.sanitizer = this.opts.discourse.sanitizer = (ident) => ident;
|
|
}
|
|
|
|
cook(raw) {
|
|
if (!raw || raw.length === 0) {
|
|
return "";
|
|
}
|
|
|
|
let result;
|
|
result = cookIt(raw, this.opts);
|
|
return result ? result : "";
|
|
}
|
|
|
|
sanitize(html) {
|
|
return this.opts.sanitizer(html).trim();
|
|
}
|
|
}
|