From 88677e9b40dd4ffdf59d3245170eab3687429600 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Wed, 23 Mar 2022 23:41:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0=E6=90=9C=E7=B4=A2=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common.js | 61 ++++++++-------------------------------- src/Flows.js | 77 ++++++++++++++------------------------------------- 2 files changed, 33 insertions(+), 105 deletions(-) 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 ( diff --git a/src/Flows.js b/src/Flows.js index 4e654fbb..2856dda3 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -98,7 +98,7 @@ class Reply extends PureComponent { render() { const { info, color_picker, show_pid, do_filter_name, do_delete, - do_report, do_block + do_report, do_block, search_param } = this.props; const author = info.name, replyText = info.text; @@ -173,6 +173,7 @@ class Reply extends PureComponent { text={replyText} color_picker={color_picker} show_pid={show_pid} + search_param={search_param} /> @@ -227,7 +228,7 @@ class FlowItem extends PureComponent { const { info, is_quote, cached, attention, can_del, do_filter_name, do_delete, do_edit_cw, do_edit_score, timestamp, img_clickable, color_picker, - show_pid, do_vote, do_block + show_pid, do_vote, do_block, search_param } = this.props; const { cw, hot_score } = this.state; return ( @@ -358,39 +359,8 @@ class FlowItem extends PureComponent { text={info.text} color_picker={color_picker} show_pid={show_pid} + search_param={search_param} /> - {info.type === 'image' && ( -

- {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} - /> - )} -

- )} - {/*{info.type==='audio' && }*/} { info.poll && (
@@ -726,6 +696,7 @@ class FlowSidebar extends PureComponent { img_clickable={true} color_picker={this.color_picker} show_pid={show_pid} + search_param={this.props.search_param} replies={this.state.replies} set_variant={(variant) => { this.set_variant(null, variant); @@ -846,6 +817,7 @@ class FlowSidebar extends PureComponent { info={reply} color_picker={this.color_picker} show_pid={show_pid} + search_param={this.props.search_param} set_variant={(variant) => { this.set_variant(reply.cid, variant); }} @@ -967,6 +939,7 @@ class FlowItemRow extends PureComponent { 0 ? content.substring(1) : content; if ( mode === 'pid' && QUOTE_BLACKLIST.indexOf(content) === -1 && parseInt(content) < parseInt(this.state.info.pid) - ) - if (quote_id === null) quote_id = parseInt(content); - else { - quote_id = null; - break; - } + ) { + if (quote_id === null) + quote_id = parseInt(content); + else { + quote_id = null; + break; + } + } } let res = (
{ if (!CLICKABLE_TAGS[event.target.tagName.toLowerCase()]) @@ -1030,7 +994,6 @@ class FlowItemRow extends PureComponent { }} >
{this.state.reply_status === 'loading' && ( @@ -1064,6 +1028,7 @@ class FlowItemRow extends PureComponent { info={reply} color_picker={this.color_picker} show_pid={show_pid} + search_param={search_param} /> ))} {this.state.replies.length > PREVIEW_REPLY_COUNT && (