├── README.md
├── components
├── marked
│ ├── index.js
│ └── lib
│ │ └── marked.js
├── mpvue-wxparse
│ └── src
│ │ ├── components
│ │ ├── wxParseVideo.vue
│ │ ├── wxParseAudio.vue
│ │ ├── wxParseTemplate11.vue
│ │ ├── wxParseImg.vue
│ │ ├── wxParseTemplate1.vue
│ │ ├── wxParseTemplate10.vue
│ │ ├── wxParseTemplate2.vue
│ │ ├── wxParseTemplate3.vue
│ │ ├── wxParseTemplate4.vue
│ │ ├── wxParseTemplate5.vue
│ │ ├── wxParseTemplate6.vue
│ │ ├── wxParseTemplate7.vue
│ │ ├── wxParseTemplate8.vue
│ │ ├── wxParseTemplate9.vue
│ │ └── wxParseTemplate0.vue
│ │ ├── wxParse.vue
│ │ ├── wxParse.css
│ │ └── libs
│ │ ├── htmlparser.js
│ │ ├── wxDiscode.js
│ │ └── html2json.js
└── ly-markdown.vue
├── main.js
├── pages.json
├── App.vue
├── pages
└── index
│ └── index.vue
├── manifest.json
└── static
└── markdown.css
/README.md:
--------------------------------------------------------------------------------
1 | # uniapp-markdown
2 | uniapp的markdown编辑器插件
3 |
--------------------------------------------------------------------------------
/components/marked/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib/marked');
2 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App'
3 |
4 | Vue.config.productionTip = false
5 |
6 | App.mpType = 'app'
7 |
8 | const app = new Vue({
9 | ...App
10 | })
11 | app.$mount()
12 |
--------------------------------------------------------------------------------
/pages.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [ //pages数组中第一项表示应用启动页
3 | {
4 | "path": "pages/index/index",
5 | "style": {
6 | "navigationBarTitleText": "uni-app"
7 | }
8 | }
9 | ],
10 | "globalStyle": {
11 | "navigationBarTextStyle": "black",
12 | "navigationBarTitleText": "uni-app",
13 | "navigationBarBackgroundColor": "#F8F8F8",
14 | "backgroundColor": "#F8F8F8"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseVideo.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
16 |
--------------------------------------------------------------------------------
/App.vue:
--------------------------------------------------------------------------------
1 |
14 |
15 |
26 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseAudio.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
15 |
28 |
--------------------------------------------------------------------------------
/pages/index/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
25 |
26 |
74 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate11.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
13 | {{node.text}}
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | {{node.text}}
36 |
37 |
38 |
39 |
40 |
41 | \n
42 |
43 |
44 |
45 |
46 |
47 | {{node.text}}
48 |
49 |
50 |
51 |
52 |
53 | {{node.text}}
54 |
55 |
56 |
80 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseImg.vue:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
79 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate1.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate10.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | {{node.text}}
62 |
63 |
64 |
90 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate2.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate3.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate4.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate5.vue:
--------------------------------------------------------------------------------
1 | s
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate6.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate7.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate8.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate9.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {{node.text}}
63 |
64 |
65 |
91 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name" : "uni-markdown",
3 | "appid" : "__UNI__4AC9661",
4 | "description": "",
5 | "versionName": "1.0.0",
6 | "versionCode": "100",
7 | "app-plus": { /* 5+App特有相关 */
8 | "modules": { /* 模块配置 */
9 |
10 | },
11 | "distribute": { /* 应用发布信息 */
12 | "android": { /* android打包配置 */
13 | "permissions": ["",
14 | "",
15 | "",
16 | "",
17 | "",
18 | "",
19 | "",
20 | "",
21 | "",
22 | "",
23 | "",
24 | "",
25 | "",
26 | "",
27 | "",
28 | "",
29 | "",
30 | "",
31 | "",
32 | "",
33 | "",
34 | ""
35 | ]
36 | },
37 | "ios": { /* ios打包配置 */
38 |
39 | },
40 | "sdkConfigs": { /* SDK配置 */
41 |
42 | }
43 | }
44 | },
45 | "quickapp": { /* 快应用特有相关 */
46 |
47 | },
48 | "mp-weixin": { /* 小程序特有相关 */
49 | "appid": ""
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/wxParse.vue:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
118 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/components/wxParseTemplate0.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 | \n
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | {{node.text}}
72 |
73 |
74 |
100 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/wxParse.css:
--------------------------------------------------------------------------------
1 | /**
2 | * author: Di (微信小程序开发工程师)
3 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
4 | * 垂直微信小程序开发交流社区
5 | *
6 | * github地址: https://github.com/icindy/wxParse
7 | *
8 | * for: 微信小程序富文本解析
9 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
10 | */
11 |
12 | .wxParse {
13 | width: 100%;
14 | font-family: Helvetica, sans-serif;
15 | font-size: 30px;
16 | color: #666;
17 | line-height: 1.8;
18 | }
19 |
20 | .wxParse view {
21 | word-break: hyphenate;
22 | }
23 |
24 | .wxParse .inline {
25 | display: inline;
26 | margin: 0;
27 | padding: 0;
28 | }
29 |
30 | .wxParse .div {
31 | margin: 0;
32 | padding: 0;
33 | }
34 |
35 | .wxParse .h1 {
36 | font-size: 2em;
37 | margin: 0.67em 0;
38 | }
39 | .wxParse .h2 {
40 | font-size: 1.5em;
41 | margin: 0.83em 0;
42 | }
43 | .wxParse .h3 {
44 | font-size: 1.17em;
45 | margin: 1em 0;
46 | }
47 | .wxParse .h4 {
48 | margin: 1.33em 0;
49 | }
50 | .wxParse .h5 {
51 | font-size: 0.83em;
52 | margin: 1.67em 0;
53 | }
54 | .wxParse .h6 {
55 | font-size: 0.67em;
56 | margin: 2.33em 0;
57 | }
58 |
59 | .wxParse .h1,
60 | .wxParse .h2,
61 | .wxParse .h3,
62 | .wxParse .h4,
63 | .wxParse .h5,
64 | .wxParse .h6,
65 | .wxParse .b,
66 | .wxParse .strong {
67 | font-weight: bolder;
68 | }
69 |
70 | .wxParse .p {
71 | margin: 1em 0;
72 | }
73 |
74 | .wxParse .i,
75 | .wxParse .cite,
76 | .wxParse .em,
77 | .wxParse .var,
78 | .wxParse .address {
79 | font-style: italic;
80 | }
81 |
82 | .wxParse .pre,
83 | .wxParse .tt,
84 | .wxParse .code,
85 | .wxParse .kbd,
86 | .wxParse .samp {
87 | font-family: monospace;
88 | }
89 | .wxParse .pre {
90 | overflow: auto;
91 | background: #f5f5f5;
92 | padding: 16px;
93 | white-space: pre;
94 | margin: 1em 0px;
95 | }
96 | .wxParse .code {
97 | display: inline;
98 | background: #f5f5f5;
99 | }
100 |
101 | .wxParse .big {
102 | font-size: 1.17em;
103 | }
104 |
105 | .wxParse .small,
106 | .wxParse .sub,
107 | .wxParse .sup {
108 | font-size: 0.83em;
109 | }
110 |
111 | .wxParse .sub {
112 | vertical-align: sub;
113 | }
114 | .wxParse .sup {
115 | vertical-align: super;
116 | }
117 |
118 | .wxParse .s,
119 | .wxParse .strike,
120 | .wxParse .del {
121 | text-decoration: line-through;
122 | }
123 |
124 | .wxParse .strong,
125 | .wxParse .s {
126 | display: inline;
127 | }
128 |
129 | .wxParse .a {
130 | color: deepskyblue;
131 | }
132 |
133 | .wxParse .video {
134 | text-align: center;
135 | margin: 22px 0;
136 | }
137 |
138 | .wxParse .video-video {
139 | width: 100%;
140 | }
141 |
142 | .wxParse .img {
143 | display: inline-block;
144 | width: 0;
145 | height: 0;
146 | max-width: 100%;
147 | overflow: hidden;
148 | }
149 |
150 | .wxParse .blockquote {
151 | margin: 10px 0;
152 | padding: 22px 0 22px 22px;
153 | font-family: Courier, Calibri, "宋体";
154 | background: #f5f5f5;
155 | border-left: 6px solid #dbdbdb;
156 | }
157 | .wxParse .blockquote .p {
158 | margin: 0;
159 | }
160 |
161 | .wxParse .ul, .wxParse .ol {
162 | display: block;
163 | margin: 1em 0;
164 | padding-left: 33px;
165 | }
166 | .wxParse .ol {
167 | list-style-type: disc;
168 | }
169 | .wxParse .ol {
170 | list-style-type: decimal;
171 | }
172 | .wxParse .li {
173 | display: list-item;
174 | align-items: baseline;
175 | text-align: match-parent;
176 | }
177 | .wxParse .ul .ul, .wxParse .ol .ul {
178 | list-style-type: circle;
179 | }
180 | .wxParse .ol .ol .ul, .wxParse .ol .ul .ul, .wxParse .ul .ol .ul, .wxParse .ul .ul .ul {
181 | list-style-type: square;
182 | }
183 |
184 | .wxParse .u {
185 | text-decoration: underline;
186 | }
187 | .wxParse .hide {
188 | display: none;
189 | }
190 | .wxParse .del {
191 | display: inline;
192 | }
193 | .wxParse .figure {
194 | overflow: hidden;
195 | }
196 |
197 | .wxParse .table {
198 | width: 100%;
199 | }
200 | .wxParse .thead, .wxParse .tfoot, .wxParse .tr {
201 | display: flex;
202 | flex-direction: row;
203 | }
204 | .wxParse .tr {
205 | width:100%;
206 | display: flex;
207 | border-right: 2px solid #e0e0e0;
208 | border-bottom: 2px solid #e0e0e0;
209 | }
210 | .wxParse .th,
211 | .wxParse .td {
212 | display: flex;
213 | width: 1276px;
214 | overflow: auto;
215 | flex: 1;
216 | padding: 11px;
217 | border-left: 2px solid #e0e0e0;
218 | }
219 | .wxParse .td:last {
220 | border-top: 2px solid #e0e0e0;
221 | }
222 | .wxParse .th {
223 | background: #f0f0f0;
224 | border-top: 2px solid #e0e0e0;
225 | }
226 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/libs/htmlparser.js:
--------------------------------------------------------------------------------
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;
157 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/libs/wxDiscode.js:
--------------------------------------------------------------------------------
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 | };
196 |
--------------------------------------------------------------------------------
/components/ly-markdown.vue:
--------------------------------------------------------------------------------
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 |
193 |
194 |
242 |
--------------------------------------------------------------------------------
/components/mpvue-wxparse/src/libs/html2json.js:
--------------------------------------------------------------------------------
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>/.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, '')
46 | .replace(/