diff --git a/src/Common.js b/src/Common.js index 2075cec4..828407ae 100644 --- a/src/Common.js +++ b/src/Common.js @@ -68,52 +68,7 @@ function normalize_url(url) { return /^https?:\/\//.test(url) ? url : 'http://' + url; } -/* -export class HighlightedText extends PureComponent { - render() { - return ( -
- {this.props.parts.map((part, idx) => {
- let [rule, p] = part;
- return (
-
- {rule === 'url_pid' ? (
-
- /##
-
- ) : rule === 'url' ? (
-
- {p}
-
- ) : rule === 'pid' ? (
- {
- e.preventDefault();
- this.props.show_pid(p.substring(1));
- }}
- >
- {p}
-
- ) : rule === 'nickname' ? (
-
- {p}
-
- ) : rule === 'search' ? (
- {p}
- ) : (
- p
- )}
-
- );
- })}
-
- );
- }
-}
-*/
-
-// props: text, show_pid, color_picker
+// props: text, show_pid, color_picker, search_param
export class HighlightedMarkdown extends Component {
render() {
const props = this.props;
@@ -169,13 +124,21 @@ export class HighlightedMarkdown extends Component {
},
processNode(node, children, index) {
const originalText = node.data;
- const splitted = split_text(originalText, [
+ let rules = [
['url_pid', URL_PID_RE],
['url', URL_RE],
['pid', PID_RE],
['nickname', NICKNAME_RE],
- ['tag', TAG_RE],
- ]);
+ ['tag', TAG_RE]
+ ];
+ if (props.search_param) {
+ let search_kws = props.search_param.split(' ').filter(s => !!s);
+ rules.push([
+ 'search',
+ new RegExp(`(${search_kws.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join("|")})`, "g")
+ ]);
+ }
+ const splitted = split_text(originalText, rules);
return (
- {img_clickable ? (
-
- {
- if (e.target.src === IMAGE_BASE + info.url) {
- e.target.src = IMAGE_BAK_BASE + info.url;
- }
- }}
- alt={IMAGE_BASE + info.url}
- />
-
- ) : (
-
{
- if (e.target.src === IMAGE_BASE + info.url) {
- e.target.src = IMAGE_BAK_BASE + info.url;
- }
- }}
- alt={IMAGE_BASE + info.url}
- />
- )}
-