mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 15:33:43 +08:00
f3156a6478
The reasoning here is that we want to make a unique bundle for this folder and the default approach is to include everything in `addon`.
41 lines
959 B
JavaScript
41 lines
959 B
JavaScript
import { censorFn } from "pretty-text/censored-words";
|
|
|
|
function recurse(tokens, apply) {
|
|
let i;
|
|
for (i = 0; i < tokens.length; i++) {
|
|
apply(tokens[i]);
|
|
if (tokens[i].children) {
|
|
recurse(tokens[i].children, apply);
|
|
}
|
|
}
|
|
}
|
|
|
|
function censorTree(state, censor) {
|
|
if (!state.tokens) {
|
|
return;
|
|
}
|
|
|
|
recurse(state.tokens, (token) => {
|
|
if (token.content) {
|
|
token.content = censor(token.content);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function setup(helper) {
|
|
helper.registerOptions((opts, siteSettings) => {
|
|
opts.watchedWordsRegularExpressions =
|
|
siteSettings.watched_words_regular_expressions;
|
|
});
|
|
|
|
helper.registerPlugin((md) => {
|
|
const censoredRegexp = md.options.discourse.censoredRegexp;
|
|
|
|
if (censoredRegexp) {
|
|
const replacement = String.fromCharCode(9632);
|
|
const censor = censorFn(censoredRegexp, replacement);
|
|
md.core.ruler.push("censored", (state) => censorTree(state, censor));
|
|
}
|
|
});
|
|
}
|