@@ -9,29 +9,38 @@ export default (text, doLinkify) => {
9
9
10
10
const result = [ ] . concat . apply ( [ ] , flatten )
11
11
12
+ markdownResult ( result )
13
+
12
14
if ( doLinkify ) linkifyResult ( result )
13
15
14
16
return result
15
17
}
16
18
19
+ const type_markdown = {
20
+ bold : '*' ,
21
+ italic : '_' ,
22
+ strike : '~' ,
23
+ underline : '°'
24
+ }
25
+
17
26
const pseudo_markdown = {
18
- '*' : {
19
- end : '\\*' ,
27
+ [ type_markdown . bold ] : {
28
+ end : '\\' + [ type_markdown . bold ] ,
20
29
allowed_chars : '.' ,
21
30
type : 'bold'
22
31
} ,
23
- _ : {
24
- end : '_' ,
32
+ [ type_markdown . italic ] : {
33
+ end : [ type_markdown . italic ] ,
25
34
allowed_chars : '.' ,
26
35
type : 'italic'
27
36
} ,
28
- '~' : {
29
- end : '~' ,
37
+ [ type_markdown . strike ] : {
38
+ end : [ type_markdown . strike ] ,
30
39
allowed_chars : '.' ,
31
40
type : 'strike'
32
41
} ,
33
- '°' : {
34
- end : '°' ,
42
+ [ type_markdown . underline ] : {
43
+ end : [ type_markdown . underline ] ,
35
44
allowed_chars : '.' ,
36
45
type : 'underline'
37
46
} ,
@@ -182,6 +191,36 @@ function flattenResult(array, types = []) {
182
191
return result
183
192
}
184
193
194
+ function markdownResult ( array ) {
195
+ for ( let i = 0 ; i < array . length ; i ) {
196
+ if ( array [ i - 1 ] ) {
197
+ const isInline =
198
+ array [ i ] . types . indexOf ( 'inline-code' ) !== - 1 &&
199
+ array [ i - 1 ] . types . indexOf ( 'inline-code' ) !== - 1
200
+
201
+ const isMultiline =
202
+ array [ i ] . types . indexOf ( 'multiline-code' ) !== - 1 &&
203
+ array [ i - 1 ] . types . indexOf ( 'multiline-code' ) !== - 1
204
+
205
+ if ( isInline || isMultiline ) {
206
+ let value = array [ i ] . value
207
+ array [ i ] . types . forEach ( type => {
208
+ const markdown = type_markdown [ type ] || ''
209
+ value = markdown + value + markdown
210
+ } )
211
+
212
+ array [ i - 1 ] . value = array [ i - 1 ] . value + value
213
+
214
+ array . splice ( i , 1 )
215
+ } else {
216
+ i ++
217
+ }
218
+ } else {
219
+ i ++
220
+ }
221
+ }
222
+ }
223
+
185
224
function linkifyResult ( array ) {
186
225
const result = [ ]
187
226
0 commit comments