forked from Kenshin/simpread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexclude.jsx
More file actions
82 lines (73 loc) · 2.32 KB
/
exclude.jsx
File metadata and controls
82 lines (73 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
console.log( "===== simpread option common: exclude =====" )
import { verifyHtml } from 'util';
import TextField from 'textfield';
export default class Exclude extends React.Component {
static defaultProps = {
flag: {},
}
static propType = {
flag : React.PropTypes.object,
}
state = {
error : ""
};
changeExclude( event ) {
const { good, bad } = getExclude( event.target.value );
this.props.changeExclude( good, bad.length > 0 ? -1 : 0 );
if ( bad.length > 0 ) {
this.setState({ error: `格式错误:${bad.join(", ")}` });
} else {
this.setState({ error: "" });
}
}
render() {
return (
<TextField
multi={ true }
rows={ this.props.rows }
placeholder="默认为空,每行一个,支持: Html标签, {}, '', //, [] 等,详细请看站点编辑器。"
floatingtext="隐藏列表"
value={ (this.props.exclude||[]).join( "\n" ) }
errortext={ this.state.error }
onChange={ evt=>this.changeExclude(evt) }
/>
)
}
}
/**
* Get exclude tags
*
* @param {string} input exclude html tag, e.g.:
<div class="article fmt article__content">
<h1>
<div class="col-xs-12 col-md-9 main ">
<img id="icon4weChat" style="height: 0;width: 0;">
<div class="wsx_fade" style="pointer-events: none;"></div>
sdasdfas
h1
*
* @return {object}
* good array: verify success htmls e.g.:
<div class="article fmt article__content">
<h1>
<div class="col-xs-12 col-md-9 main ">
<img id="icon4weChat" style="height: 0;width: 0;">
<div class="wsx_fade" style="pointer-events: none;"></div>
bad array: error htmls, e.g.:
sdasdfas
h1
*
*/
function getExclude( htmls ) {
let [ good, bad, obj ] = [[], [], null ];
if ( htmls.trim() == "" ) return { good, bad };
const arr = htmls.trim().split( "\n" );
for( let value of arr ) {
if ( verifyHtml( value.trim() )[0] > 0 ) {
good.push( value.trim() );
} else {
bad.push( value.trim() );
}
}
return { good, bad };
}