@@ -9,29 +9,38 @@ export default (text, doLinkify) => {
99
1010 const result = [ ] . concat . apply ( [ ] , flatten )
1111
12+ markdownResult ( result )
13+
1214 if ( doLinkify ) linkifyResult ( result )
1315
1416 return result
1517}
1618
19+ const type_markdown = {
20+ bold : '*' ,
21+ italic : '_' ,
22+ strike : '~' ,
23+ underline : '°'
24+ }
25+
1726const pseudo_markdown = {
18- '*' : {
19- end : '\\*' ,
27+ [ type_markdown . bold ] : {
28+ end : '\\' + [ type_markdown . bold ] ,
2029 allowed_chars : '.' ,
2130 type : 'bold'
2231 } ,
23- _ : {
24- end : '_' ,
32+ [ type_markdown . italic ] : {
33+ end : [ type_markdown . italic ] ,
2534 allowed_chars : '.' ,
2635 type : 'italic'
2736 } ,
28- '~' : {
29- end : '~' ,
37+ [ type_markdown . strike ] : {
38+ end : [ type_markdown . strike ] ,
3039 allowed_chars : '.' ,
3140 type : 'strike'
3241 } ,
33- '°' : {
34- end : '°' ,
42+ [ type_markdown . underline ] : {
43+ end : [ type_markdown . underline ] ,
3544 allowed_chars : '.' ,
3645 type : 'underline'
3746 } ,
@@ -182,6 +191,36 @@ function flattenResult(array, types = []) {
182191 return result
183192}
184193
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+
185224function linkifyResult ( array ) {
186225 const result = [ ]
187226
0 commit comments