@10yun/cv-mobile-ui 0.5.9 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extend/permission.js +1 -2
- package/package.json +1 -1
- package/plugins/uni-richText.js +1 -1
- package/plugins/uni-socket.js +6 -8
- package/ui-cv/cv-geo-local/cv-geo-local.vue +0 -1
- package/ui-cv/cv-layout-topbar/cv-layout-topbar.vue +238 -0
- package/ui-cv/cv-markdown-show/lib/highlight/uni-highlight.min.js +9001 -5133
- package/ui-sdks/sdk-app-update/img/logo.png +0 -0
- package/ui-sdks/sdk-app-update/img/update_bg.png +0 -0
- package/ui-sdks/sdk-app-update/img/update_bg_top.png +0 -0
- package/{ui-cv/cv-update-app/cv-update-app.vue → ui-sdks/sdk-app-update/sdk-app-update.vue} +2 -2
- package/ui-sdks/sdk-app-update/xxxx +62 -0
- package/ui-sdks/sdk-privacy-policy/sdk-privacy-policy.vue +113 -0
- package/ui-sdks/sdk-u-charts/app-echarts.min.js +23 -0
- package/ui-sdks/sdk-u-charts/config-echarts.js +420 -0
- package/ui-sdks/sdk-u-charts/config-ucharts.js +630 -0
- package/ui-sdks/sdk-u-charts/h5-echarts.min.js +23 -0
- package/ui-sdks/sdk-u-charts/u-charts.js +7398 -0
- package/ui-sdks/sdk-u-charts/u-charts.min.js +1 -0
- package/ui-sdks/sdk-webview-main/WebViewMain.vue +1 -0
- package/ui-sdks/sdk-webview-main/main.js +0 -0
- package/ui-sdks/sdk-webview-main/mixin.js +0 -0
- package/ui-uni/uParse/src/components/wxParseAudio.vue +26 -0
- package/ui-uni/uParse/src/components/wxParseImg.vue +94 -0
- package/ui-uni/uParse/src/components/wxParseTable.vue +55 -0
- package/ui-uni/uParse/src/components/wxParseTemplate0.vue +103 -0
- package/ui-uni/uParse/src/components/wxParseTemplate1.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate10.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate11.vue +86 -0
- package/ui-uni/uParse/src/components/wxParseTemplate2.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate3.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate4.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate5.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate6.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate7.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate8.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseTemplate9.vue +88 -0
- package/ui-uni/uParse/src/components/wxParseVideo.vue +15 -0
- package/ui-uni/uParse/src/editor.css +495 -0
- package/ui-uni/uParse/src/libs/html2json.js +261 -0
- package/ui-uni/uParse/src/libs/htmlparser.js +156 -0
- package/ui-uni/uParse/src/libs/wxDiscode.js +195 -0
- package/ui-uni/uParse/src/wxParse.css +270 -0
- package/ui-uni/uParse/src/wxParse.vue +206 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* html2Json 改造来自: https://github.com/Jxck/html2json
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* author: Di (微信小程序开发工程师)
|
|
6
|
+
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
|
|
7
|
+
* 垂直微信小程序开发交流社区
|
|
8
|
+
*
|
|
9
|
+
* github地址: https://github.com/icindy/wxParse
|
|
10
|
+
*
|
|
11
|
+
* for: 微信小程序富文本解析
|
|
12
|
+
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import wxDiscode from './wxDiscode';
|
|
16
|
+
import HTMLParser from './htmlparser';
|
|
17
|
+
|
|
18
|
+
function makeMap(str) {
|
|
19
|
+
const obj = {};
|
|
20
|
+
const items = str.split(',');
|
|
21
|
+
for (let i = 0; i < items.length; i += 1) obj[items[i]] = true;
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Block Elements - HTML 5
|
|
26
|
+
const block = makeMap('br,code,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video');
|
|
27
|
+
|
|
28
|
+
// Inline Elements - HTML 5
|
|
29
|
+
const inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var');
|
|
30
|
+
|
|
31
|
+
// Elements that you can, intentionally, leave open
|
|
32
|
+
// (and which close themselves)
|
|
33
|
+
const closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
|
|
34
|
+
|
|
35
|
+
function removeDOCTYPE(html) {
|
|
36
|
+
const isDocument = /<body.*>([^]*)<\/body>/.test(html);
|
|
37
|
+
return isDocument ? RegExp.$1 : html;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function trimHtml(html) {
|
|
41
|
+
return html
|
|
42
|
+
.replace(/<!--.*?-->/gi, '')
|
|
43
|
+
.replace(/\/\*.*?\*\//gi, '')
|
|
44
|
+
.replace(/[ ]+</gi, '<')
|
|
45
|
+
.replace(/<script[^]*<\/script>/gi, '')
|
|
46
|
+
.replace(/<style[^]*<\/style>/gi, '');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getScreenInfo() {
|
|
50
|
+
const screen = {};
|
|
51
|
+
wx.getSystemInfo({
|
|
52
|
+
success: (res) => {
|
|
53
|
+
screen.width = res.windowWidth;
|
|
54
|
+
screen.height = res.windowHeight;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return screen;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function html2json(html, customHandler, imageProp, host) {
|
|
61
|
+
// 处理字符串
|
|
62
|
+
html = removeDOCTYPE(html);
|
|
63
|
+
html = trimHtml(html);
|
|
64
|
+
html = wxDiscode.strDiscode(html);
|
|
65
|
+
// 生成node节点
|
|
66
|
+
const bufArray = [];
|
|
67
|
+
const results = {
|
|
68
|
+
nodes: [],
|
|
69
|
+
imageUrls: [],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const screen = getScreenInfo();
|
|
73
|
+
function Node(tag) {
|
|
74
|
+
this.node = 'element';
|
|
75
|
+
this.tag = tag;
|
|
76
|
+
|
|
77
|
+
this.$screen = screen;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
HTMLParser(html, {
|
|
81
|
+
start(tag, attrs, unary) {
|
|
82
|
+
// node for this element
|
|
83
|
+
const node = new Node(tag);
|
|
84
|
+
|
|
85
|
+
if (bufArray.length !== 0) {
|
|
86
|
+
const parent = bufArray[0];
|
|
87
|
+
if (parent.nodes === undefined) {
|
|
88
|
+
parent.nodes = [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (block[tag]) {
|
|
93
|
+
node.tagType = 'block';
|
|
94
|
+
} else if (inline[tag]) {
|
|
95
|
+
node.tagType = 'inline';
|
|
96
|
+
} else if (closeSelf[tag]) {
|
|
97
|
+
node.tagType = 'closeSelf';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
node.attr = attrs.reduce((pre, attr) => {
|
|
101
|
+
const { name } = attr;
|
|
102
|
+
let { value } = attr;
|
|
103
|
+
if (name === 'class') {
|
|
104
|
+
node.classStr = value;
|
|
105
|
+
}
|
|
106
|
+
// has multi attibutes
|
|
107
|
+
// make it array of attribute
|
|
108
|
+
if (name === 'style') {
|
|
109
|
+
node.styleStr = value;
|
|
110
|
+
}
|
|
111
|
+
if (value.match(/ /)) {
|
|
112
|
+
value = value.split(' ');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// if attr already exists
|
|
116
|
+
// merge it
|
|
117
|
+
if (pre[name]) {
|
|
118
|
+
if (Array.isArray(pre[name])) {
|
|
119
|
+
// already array, push to last
|
|
120
|
+
pre[name].push(value);
|
|
121
|
+
} else {
|
|
122
|
+
// single value, make it array
|
|
123
|
+
pre[name] = [pre[name], value];
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
// not exist, put it
|
|
127
|
+
pre[name] = value;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return pre;
|
|
131
|
+
}, {});
|
|
132
|
+
|
|
133
|
+
// 优化样式相关属性
|
|
134
|
+
if (node.classStr) {
|
|
135
|
+
node.classStr += ` ${node.tag}`;
|
|
136
|
+
} else {
|
|
137
|
+
node.classStr = node.tag;
|
|
138
|
+
}
|
|
139
|
+
if (node.tagType === 'inline') {
|
|
140
|
+
node.classStr += ' inline';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 对img添加额外数据
|
|
144
|
+
if (node.tag === 'img') {
|
|
145
|
+
let imgUrl = node.attr.src;
|
|
146
|
+
imgUrl = wxDiscode.urlToHttpUrl(imgUrl, imageProp.domain);
|
|
147
|
+
Object.assign(node.attr, imageProp, {
|
|
148
|
+
src: imgUrl || '',
|
|
149
|
+
});
|
|
150
|
+
if (imgUrl) {
|
|
151
|
+
results.imageUrls.push(imgUrl);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 处理a标签属性
|
|
156
|
+
if (node.tag === 'a') {
|
|
157
|
+
node.attr.href = node.attr.href || '';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 处理font标签样式属性
|
|
161
|
+
if (node.tag === 'font') {
|
|
162
|
+
const fontSize = [
|
|
163
|
+
'x-small',
|
|
164
|
+
'small',
|
|
165
|
+
'medium',
|
|
166
|
+
'large',
|
|
167
|
+
'x-large',
|
|
168
|
+
'xx-large',
|
|
169
|
+
'-webkit-xxx-large',
|
|
170
|
+
];
|
|
171
|
+
const styleAttrs = {
|
|
172
|
+
color: 'color',
|
|
173
|
+
face: 'font-family',
|
|
174
|
+
size: 'font-size',
|
|
175
|
+
};
|
|
176
|
+
if (!node.styleStr) node.styleStr = '';
|
|
177
|
+
Object.keys(styleAttrs).forEach((key) => {
|
|
178
|
+
if (node.attr[key]) {
|
|
179
|
+
const value = key === 'size' ? fontSize[node.attr[key] - 1] : node.attr[key];
|
|
180
|
+
node.styleStr += `${styleAttrs[key]}: ${value};`;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 临时记录source资源
|
|
186
|
+
if (node.tag === 'source') {
|
|
187
|
+
results.source = node.attr.src;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (customHandler.start) {
|
|
191
|
+
customHandler.start(node, results);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (unary) {
|
|
195
|
+
// if this tag doesn't have end tag
|
|
196
|
+
// like <img src="hoge.png"/>
|
|
197
|
+
// add to parents
|
|
198
|
+
const parent = bufArray[0] || results;
|
|
199
|
+
if (parent.nodes === undefined) {
|
|
200
|
+
parent.nodes = [];
|
|
201
|
+
}
|
|
202
|
+
parent.nodes.push(node);
|
|
203
|
+
} else {
|
|
204
|
+
bufArray.unshift(node);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
end(tag) {
|
|
208
|
+
// merge into parent tag
|
|
209
|
+
const node = bufArray.shift();
|
|
210
|
+
if (node.tag !== tag) {
|
|
211
|
+
console.error('invalid state: mismatch end tag');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 当有缓存source资源时于于video补上src资源
|
|
215
|
+
if (node.tag === 'video' && results.source) {
|
|
216
|
+
node.attr.src = results.source;
|
|
217
|
+
delete results.source;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (customHandler.end) {
|
|
221
|
+
customHandler.end(node, results);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (bufArray.length === 0) {
|
|
225
|
+
results.nodes.push(node);
|
|
226
|
+
} else {
|
|
227
|
+
const parent = bufArray[0];
|
|
228
|
+
if (!parent.nodes) {
|
|
229
|
+
parent.nodes = [];
|
|
230
|
+
}
|
|
231
|
+
parent.nodes.push(node);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
chars(text) {
|
|
235
|
+
if (!text.trim()) return;
|
|
236
|
+
|
|
237
|
+
const node = {
|
|
238
|
+
node: 'text',
|
|
239
|
+
text,
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
if (customHandler.chars) {
|
|
243
|
+
customHandler.chars(node, results);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (bufArray.length === 0) {
|
|
247
|
+
results.nodes.push(node);
|
|
248
|
+
} else {
|
|
249
|
+
const parent = bufArray[0];
|
|
250
|
+
if (parent.nodes === undefined) {
|
|
251
|
+
parent.nodes = [];
|
|
252
|
+
}
|
|
253
|
+
parent.nodes.push(node);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return results;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export default html2json;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* htmlParser改造自: https://github.com/blowsie/Pure-JavaScript-HTML5-Parser
|
|
4
|
+
*
|
|
5
|
+
* author: Di (微信小程序开发工程师)
|
|
6
|
+
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
|
|
7
|
+
* 垂直微信小程序开发交流社区
|
|
8
|
+
*
|
|
9
|
+
* github地址: https://github.com/icindy/wxParse
|
|
10
|
+
*
|
|
11
|
+
* for: 微信小程序富文本解析
|
|
12
|
+
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
|
|
13
|
+
*/
|
|
14
|
+
// Regular Expressions for parsing tags and attributes
|
|
15
|
+
|
|
16
|
+
const startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z0-9_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
|
|
17
|
+
const endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/;
|
|
18
|
+
const attr = /([a-zA-Z0-9_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
|
|
19
|
+
|
|
20
|
+
function makeMap(str) {
|
|
21
|
+
const obj = {};
|
|
22
|
+
const items = str.split(',');
|
|
23
|
+
for (let i = 0; i < items.length; i += 1) obj[items[i]] = true;
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Empty Elements - HTML 5
|
|
28
|
+
const empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr');
|
|
29
|
+
|
|
30
|
+
// Block Elements - HTML 5
|
|
31
|
+
const block = makeMap('address,code,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video');
|
|
32
|
+
|
|
33
|
+
// Inline Elements - HTML 5
|
|
34
|
+
const inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var');
|
|
35
|
+
|
|
36
|
+
// Elements that you can, intentionally, leave open
|
|
37
|
+
// (and which close themselves)
|
|
38
|
+
const closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
|
|
39
|
+
|
|
40
|
+
// Attributes that have their values filled in disabled="disabled"
|
|
41
|
+
const fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected');
|
|
42
|
+
|
|
43
|
+
function HTMLParser(html, handler) {
|
|
44
|
+
let index;
|
|
45
|
+
let chars;
|
|
46
|
+
let match;
|
|
47
|
+
let last = html;
|
|
48
|
+
const stack = [];
|
|
49
|
+
|
|
50
|
+
stack.last = () => stack[stack.length - 1];
|
|
51
|
+
|
|
52
|
+
function parseEndTag(tag, tagName) {
|
|
53
|
+
// If no tag name is provided, clean shop
|
|
54
|
+
let pos;
|
|
55
|
+
if (!tagName) {
|
|
56
|
+
pos = 0;
|
|
57
|
+
} else {
|
|
58
|
+
// Find the closest opened tag of the same type
|
|
59
|
+
tagName = tagName.toLowerCase();
|
|
60
|
+
for (pos = stack.length - 1; pos >= 0; pos -= 1) {
|
|
61
|
+
if (stack[pos] === tagName) break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (pos >= 0) {
|
|
65
|
+
// Close all the open elements, up the stack
|
|
66
|
+
for (let i = stack.length - 1; i >= pos; i -= 1) {
|
|
67
|
+
if (handler.end) handler.end(stack[i]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Remove the open elements from the stack
|
|
71
|
+
stack.length = pos;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parseStartTag(tag, tagName, rest, unary) {
|
|
76
|
+
tagName = tagName.toLowerCase();
|
|
77
|
+
|
|
78
|
+
if (block[tagName]) {
|
|
79
|
+
while (stack.last() && inline[stack.last()]) {
|
|
80
|
+
parseEndTag('', stack.last());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (closeSelf[tagName] && stack.last() === tagName) {
|
|
85
|
+
parseEndTag('', tagName);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
unary = empty[tagName] || !!unary;
|
|
89
|
+
|
|
90
|
+
if (!unary) stack.push(tagName);
|
|
91
|
+
|
|
92
|
+
if (handler.start) {
|
|
93
|
+
const attrs = [];
|
|
94
|
+
|
|
95
|
+
rest.replace(attr, function genAttr(matches, name) {
|
|
96
|
+
const value = arguments[2] || arguments[3] || arguments[4] || (fillAttrs[name] ? name : '');
|
|
97
|
+
|
|
98
|
+
attrs.push({
|
|
99
|
+
name,
|
|
100
|
+
value,
|
|
101
|
+
escaped: value.replace(/(^|[^\\])"/g, '$1\\"'), // "
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (handler.start) {
|
|
106
|
+
handler.start(tagName, attrs, unary);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
while (html) {
|
|
112
|
+
chars = true;
|
|
113
|
+
|
|
114
|
+
if (html.indexOf('</') === 0) {
|
|
115
|
+
match = html.match(endTag);
|
|
116
|
+
|
|
117
|
+
if (match) {
|
|
118
|
+
html = html.substring(match[0].length);
|
|
119
|
+
match[0].replace(endTag, parseEndTag);
|
|
120
|
+
chars = false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// start tag
|
|
124
|
+
} else if (html.indexOf('<') === 0) {
|
|
125
|
+
match = html.match(startTag);
|
|
126
|
+
|
|
127
|
+
if (match) {
|
|
128
|
+
html = html.substring(match[0].length);
|
|
129
|
+
match[0].replace(startTag, parseStartTag);
|
|
130
|
+
chars = false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (chars) {
|
|
135
|
+
index = html.indexOf('<');
|
|
136
|
+
let text = '';
|
|
137
|
+
while (index === 0) {
|
|
138
|
+
text += '<';
|
|
139
|
+
html = html.substring(1);
|
|
140
|
+
index = html.indexOf('<');
|
|
141
|
+
}
|
|
142
|
+
text += index < 0 ? html : html.substring(0, index);
|
|
143
|
+
html = index < 0 ? '' : html.substring(index);
|
|
144
|
+
|
|
145
|
+
if (handler.chars) handler.chars(text);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (html === last) throw new Error(`Parse Error: ${html}`);
|
|
149
|
+
last = html;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Clean up any remaining tags
|
|
153
|
+
parseEndTag();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default HTMLParser;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// HTML 支持的数学符号
|
|
2
|
+
function strNumDiscode(str) {
|
|
3
|
+
str = str.replace(/∀/g, '∀');
|
|
4
|
+
str = str.replace(/∂/g, '∂');
|
|
5
|
+
str = str.replace(/∃/g, '∃');
|
|
6
|
+
str = str.replace(/∅/g, '∅');
|
|
7
|
+
str = str.replace(/∇/g, '∇');
|
|
8
|
+
str = str.replace(/∈/g, '∈');
|
|
9
|
+
str = str.replace(/∉/g, '∉');
|
|
10
|
+
str = str.replace(/∋/g, '∋');
|
|
11
|
+
str = str.replace(/∏/g, '∏');
|
|
12
|
+
str = str.replace(/∑/g, '∑');
|
|
13
|
+
str = str.replace(/−/g, '−');
|
|
14
|
+
str = str.replace(/∗/g, '∗');
|
|
15
|
+
str = str.replace(/√/g, '√');
|
|
16
|
+
str = str.replace(/∝/g, '∝');
|
|
17
|
+
str = str.replace(/∞/g, '∞');
|
|
18
|
+
str = str.replace(/∠/g, '∠');
|
|
19
|
+
str = str.replace(/∧/g, '∧');
|
|
20
|
+
str = str.replace(/∨/g, '∨');
|
|
21
|
+
str = str.replace(/∩/g, '∩');
|
|
22
|
+
str = str.replace(/∪/g, '∪');
|
|
23
|
+
str = str.replace(/∫/g, '∫');
|
|
24
|
+
str = str.replace(/∴/g, '∴');
|
|
25
|
+
str = str.replace(/∼/g, '∼');
|
|
26
|
+
str = str.replace(/≅/g, '≅');
|
|
27
|
+
str = str.replace(/≈/g, '≈');
|
|
28
|
+
str = str.replace(/≠/g, '≠');
|
|
29
|
+
str = str.replace(/≤/g, '≤');
|
|
30
|
+
str = str.replace(/≥/g, '≥');
|
|
31
|
+
str = str.replace(/⊂/g, '⊂');
|
|
32
|
+
str = str.replace(/⊃/g, '⊃');
|
|
33
|
+
str = str.replace(/⊄/g, '⊄');
|
|
34
|
+
str = str.replace(/⊆/g, '⊆');
|
|
35
|
+
str = str.replace(/⊇/g, '⊇');
|
|
36
|
+
str = str.replace(/⊕/g, '⊕');
|
|
37
|
+
str = str.replace(/⊗/g, '⊗');
|
|
38
|
+
str = str.replace(/⊥/g, '⊥');
|
|
39
|
+
str = str.replace(/⋅/g, '⋅');
|
|
40
|
+
return str;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// HTML 支持的希腊字母
|
|
44
|
+
function strGreeceDiscode(str) {
|
|
45
|
+
str = str.replace(/Α/g, 'Α');
|
|
46
|
+
str = str.replace(/Β/g, 'Β');
|
|
47
|
+
str = str.replace(/Γ/g, 'Γ');
|
|
48
|
+
str = str.replace(/Δ/g, 'Δ');
|
|
49
|
+
str = str.replace(/Ε/g, 'Ε');
|
|
50
|
+
str = str.replace(/Ζ/g, 'Ζ');
|
|
51
|
+
str = str.replace(/Η/g, 'Η');
|
|
52
|
+
str = str.replace(/Θ/g, 'Θ');
|
|
53
|
+
str = str.replace(/Ι/g, 'Ι');
|
|
54
|
+
str = str.replace(/Κ/g, 'Κ');
|
|
55
|
+
str = str.replace(/Λ/g, 'Λ');
|
|
56
|
+
str = str.replace(/Μ/g, 'Μ');
|
|
57
|
+
str = str.replace(/Ν/g, 'Ν');
|
|
58
|
+
str = str.replace(/Ξ/g, 'Ν');
|
|
59
|
+
str = str.replace(/Ο/g, 'Ο');
|
|
60
|
+
str = str.replace(/Π/g, 'Π');
|
|
61
|
+
str = str.replace(/Ρ/g, 'Ρ');
|
|
62
|
+
str = str.replace(/Σ/g, 'Σ');
|
|
63
|
+
str = str.replace(/Τ/g, 'Τ');
|
|
64
|
+
str = str.replace(/Υ/g, 'Υ');
|
|
65
|
+
str = str.replace(/Φ/g, 'Φ');
|
|
66
|
+
str = str.replace(/Χ/g, 'Χ');
|
|
67
|
+
str = str.replace(/Ψ/g, 'Ψ');
|
|
68
|
+
str = str.replace(/Ω/g, 'Ω');
|
|
69
|
+
|
|
70
|
+
str = str.replace(/α/g, 'α');
|
|
71
|
+
str = str.replace(/β/g, 'β');
|
|
72
|
+
str = str.replace(/γ/g, 'γ');
|
|
73
|
+
str = str.replace(/δ/g, 'δ');
|
|
74
|
+
str = str.replace(/ε/g, 'ε');
|
|
75
|
+
str = str.replace(/ζ/g, 'ζ');
|
|
76
|
+
str = str.replace(/η/g, 'η');
|
|
77
|
+
str = str.replace(/θ/g, 'θ');
|
|
78
|
+
str = str.replace(/ι/g, 'ι');
|
|
79
|
+
str = str.replace(/κ/g, 'κ');
|
|
80
|
+
str = str.replace(/λ/g, 'λ');
|
|
81
|
+
str = str.replace(/μ/g, 'μ');
|
|
82
|
+
str = str.replace(/ν/g, 'ν');
|
|
83
|
+
str = str.replace(/ξ/g, 'ξ');
|
|
84
|
+
str = str.replace(/ο/g, 'ο');
|
|
85
|
+
str = str.replace(/π/g, 'π');
|
|
86
|
+
str = str.replace(/ρ/g, 'ρ');
|
|
87
|
+
str = str.replace(/ς/g, 'ς');
|
|
88
|
+
str = str.replace(/σ/g, 'σ');
|
|
89
|
+
str = str.replace(/τ/g, 'τ');
|
|
90
|
+
str = str.replace(/υ/g, 'υ');
|
|
91
|
+
str = str.replace(/φ/g, 'φ');
|
|
92
|
+
str = str.replace(/χ/g, 'χ');
|
|
93
|
+
str = str.replace(/ψ/g, 'ψ');
|
|
94
|
+
str = str.replace(/ω/g, 'ω');
|
|
95
|
+
str = str.replace(/ϑ/g, 'ϑ');
|
|
96
|
+
str = str.replace(/ϒ/g, 'ϒ');
|
|
97
|
+
str = str.replace(/ϖ/g, 'ϖ');
|
|
98
|
+
str = str.replace(/·/g, '·');
|
|
99
|
+
return str;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function strcharacterDiscode(str) {
|
|
103
|
+
// 加入常用解析
|
|
104
|
+
str = str.replace(/ /g, ' ');
|
|
105
|
+
str = str.replace(/ /g, ' ');
|
|
106
|
+
str = str.replace(/ /g, ' ');
|
|
107
|
+
str = str.replace(/"/g, "'");
|
|
108
|
+
str = str.replace(/&/g, '&');
|
|
109
|
+
str = str.replace(/</g, '<');
|
|
110
|
+
str = str.replace(/>/g, '>');
|
|
111
|
+
str = str.replace(/•/g, '•');
|
|
112
|
+
|
|
113
|
+
return str;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// HTML 支持的其他实体
|
|
117
|
+
function strOtherDiscode(str) {
|
|
118
|
+
str = str.replace(/Œ/g, 'Œ');
|
|
119
|
+
str = str.replace(/œ/g, 'œ');
|
|
120
|
+
str = str.replace(/Š/g, 'Š');
|
|
121
|
+
str = str.replace(/š/g, 'š');
|
|
122
|
+
str = str.replace(/Ÿ/g, 'Ÿ');
|
|
123
|
+
str = str.replace(/ƒ/g, 'ƒ');
|
|
124
|
+
str = str.replace(/ˆ/g, 'ˆ');
|
|
125
|
+
str = str.replace(/˜/g, '˜');
|
|
126
|
+
str = str.replace(/ /g, '');
|
|
127
|
+
str = str.replace(/ /g, '');
|
|
128
|
+
str = str.replace(/ /g, '');
|
|
129
|
+
str = str.replace(/‌/g, '');
|
|
130
|
+
str = str.replace(/‍/g, '');
|
|
131
|
+
str = str.replace(/‎/g, '');
|
|
132
|
+
str = str.replace(/‏/g, '');
|
|
133
|
+
str = str.replace(/–/g, '–');
|
|
134
|
+
str = str.replace(/—/g, '—');
|
|
135
|
+
str = str.replace(/‘/g, '‘');
|
|
136
|
+
str = str.replace(/’/g, '’');
|
|
137
|
+
str = str.replace(/‚/g, '‚');
|
|
138
|
+
str = str.replace(/“/g, '“');
|
|
139
|
+
str = str.replace(/”/g, '”');
|
|
140
|
+
str = str.replace(/„/g, '„');
|
|
141
|
+
str = str.replace(/†/g, '†');
|
|
142
|
+
str = str.replace(/‡/g, '‡');
|
|
143
|
+
str = str.replace(/•/g, '•');
|
|
144
|
+
str = str.replace(/…/g, '…');
|
|
145
|
+
str = str.replace(/‰/g, '‰');
|
|
146
|
+
str = str.replace(/′/g, '′');
|
|
147
|
+
str = str.replace(/″/g, '″');
|
|
148
|
+
str = str.replace(/‹/g, '‹');
|
|
149
|
+
str = str.replace(/›/g, '›');
|
|
150
|
+
str = str.replace(/‾/g, '‾');
|
|
151
|
+
str = str.replace(/€/g, '€');
|
|
152
|
+
str = str.replace(/™/g, '™');
|
|
153
|
+
|
|
154
|
+
str = str.replace(/←/g, '←');
|
|
155
|
+
str = str.replace(/↑/g, '↑');
|
|
156
|
+
str = str.replace(/→/g, '→');
|
|
157
|
+
str = str.replace(/↓/g, '↓');
|
|
158
|
+
str = str.replace(/↔/g, '↔');
|
|
159
|
+
str = str.replace(/↵/g, '↵');
|
|
160
|
+
str = str.replace(/⌈/g, '⌈');
|
|
161
|
+
str = str.replace(/⌉/g, '⌉');
|
|
162
|
+
|
|
163
|
+
str = str.replace(/⌊/g, '⌊');
|
|
164
|
+
str = str.replace(/⌋/g, '⌋');
|
|
165
|
+
str = str.replace(/◊/g, '◊');
|
|
166
|
+
str = str.replace(/♠/g, '♠');
|
|
167
|
+
str = str.replace(/♣/g, '♣');
|
|
168
|
+
str = str.replace(/♥/g, '♥');
|
|
169
|
+
|
|
170
|
+
str = str.replace(/♦/g, '♦');
|
|
171
|
+
str = str.replace(/'/g, "'");
|
|
172
|
+
return str;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function strDiscode(str) {
|
|
176
|
+
str = strNumDiscode(str);
|
|
177
|
+
str = strGreeceDiscode(str);
|
|
178
|
+
str = strcharacterDiscode(str);
|
|
179
|
+
str = strOtherDiscode(str);
|
|
180
|
+
return str;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function urlToHttpUrl(url, domain) {
|
|
184
|
+
if (/^\/\//.test(url)) {
|
|
185
|
+
return `https:${url}`;
|
|
186
|
+
} else if (/^\//.test(url)) {
|
|
187
|
+
return `https://${domain}${url}`;
|
|
188
|
+
}
|
|
189
|
+
return url;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export default {
|
|
193
|
+
strDiscode,
|
|
194
|
+
urlToHttpUrl,
|
|
195
|
+
};
|