mirror of
https://github.com/wassname/talk.git
synced 2026-07-07 21:18:57 +08:00
25 lines
524 B
JavaScript
25 lines
524 B
JavaScript
import React from 'react';
|
|
import Highlighter from 'react-highlight-words';
|
|
import Linkify from 'react-linkify';
|
|
const linkify = new Linkify();
|
|
|
|
export default ({suspectWords, bannedWords, body, ...rest}) => {
|
|
|
|
const links = linkify.getMatches(body);
|
|
const linkText = links ? links.map((link) => link.raw) : [];
|
|
|
|
const searchWords = [
|
|
...suspectWords,
|
|
...bannedWords,
|
|
...linkText
|
|
];
|
|
|
|
return (
|
|
<Highlighter
|
|
{...rest}
|
|
searchWords={searchWords}
|
|
textToHighlight={body}
|
|
/>
|
|
);
|
|
};
|