2017-07-13 06:10:51 +08:00
|
|
|
import { censor } from 'pretty-text/censored-words';
|
|
|
|
import { registerOption } from 'pretty-text/pretty-text';
|
2016-06-15 02:31:51 +08:00
|
|
|
|
2017-07-13 06:10:51 +08:00
|
|
|
registerOption((siteSettings, opts) => {
|
|
|
|
opts.features.censored = true;
|
|
|
|
opts.censoredWords = siteSettings.censored_words;
|
|
|
|
opts.censoredPattern = siteSettings.censored_pattern;
|
|
|
|
});
|
2016-06-15 02:31:51 +08:00
|
|
|
|
|
|
|
export function setup(helper) {
|
2017-06-09 06:02:30 +08:00
|
|
|
|
2017-07-13 06:10:51 +08:00
|
|
|
if (helper.markdownIt) { return; }
|
2017-06-09 06:02:30 +08:00
|
|
|
|
2017-07-13 06:10:51 +08:00
|
|
|
helper.addPreProcessor(text => {
|
|
|
|
const options = helper.getOptions();
|
|
|
|
return censor(text, options.censoredWords, options.censoredPattern);
|
2016-06-15 02:31:51 +08:00
|
|
|
});
|
|
|
|
}
|