1
1
/**
2
- * vue-markdown v2.0 .1
2
+ * vue-markdown v2.1 .1
3
3
* https://github.com/miaolz123/vue-markdown
4
4
* MIT License
5
5
*/
@@ -112,54 +112,18 @@ return /******/ (function(modules) { // webpackBootstrap
112
112
113
113
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
114
114
115
- var md = new _markdownIt2 . default ( ) ;
116
-
117
- var rende = function rende ( root ) {
118
- md = new _markdownIt2 . default ( ) . use ( _markdownItSub2 . default ) . use ( _markdownItSup2 . default ) . use ( _markdownItFootnote2 . default ) . use ( _markdownItDeflist2 . default ) . use ( _markdownItAbbr2 . default ) . use ( _markdownItIns2 . default ) . use ( _markdownItMark2 . default ) ;
119
- if ( root . emoji ) md . use ( _markdownItEmoji2 . default ) ;
120
- md . set ( {
121
- html : root . html ,
122
- xhtmlOut : root . xhtmlOut ,
123
- breaks : root . breaks ,
124
- linkify : root . linkify ,
125
- typographer : root . typographer ,
126
- langPrefix : root . langPrefix ,
127
- quotes : root . quotes
128
- } ) ;
129
- md . renderer . rules . table_open = function ( ) {
130
- return '<table class="' + root . tableClass + '">\n' ;
131
- } ;
132
- if ( root . toc ) {
133
- md . use ( _markdownItTocAndAnchor2 . default , {
134
- tocClassName : root . tocClass ,
135
- tocFirstLevel : root . tocFirstLevel ,
136
- tocLastLevel : root . tocLastLevelComputed ,
137
- anchorLink : root . tocAnchorLink ,
138
- anchorLinkSymbol : root . tocAnchorLinkSymbol ,
139
- anchorLinkSpace : root . tocAnchorLinkSpace ,
140
- anchorClassName : root . tocAnchorClass ,
141
- anchorLinkSymbolClassName : root . tocAnchorLinkClass ,
142
- tocCallback : function tocCallback ( tocMarkdown , tocArray , tocHtml ) {
143
- if ( tocHtml ) {
144
- if ( root . tocId && document . getElementById ( root . tocId ) ) document . getElementById ( root . tocId ) . innerHTML = tocHtml ;
145
- root . $emit ( 'toc-rendered' , tocHtml ) ;
146
- }
147
- }
148
- } ) ;
149
- } else if ( root . tocId && document . getElementById ( root . tocId ) ) document . getElementById ( root . tocId ) . innerHTML = '' ;
150
- var outHtml = root . show ? md . render ( root . sourceOut ) : '' ;
151
- root . $el . innerHTML = outHtml ;
152
- root . $emit ( 'rendered' , outHtml ) ;
153
- } ;
154
-
155
115
exports . default = {
116
+ md : new _markdownIt2 . default ( ) ,
117
+
156
118
template : '<div><slot></slot></div>' ,
119
+
157
120
data : function data ( ) {
158
121
return {
159
- sourceOut : ''
122
+ sourceData : this . source
160
123
} ;
161
124
} ,
162
125
126
+
163
127
props : {
164
128
watches : {
165
129
type : Array ,
@@ -250,26 +214,80 @@ return /******/ (function(modules) { // webpackBootstrap
250
214
default : 'toc-anchor-link'
251
215
}
252
216
} ,
217
+
253
218
computed : {
254
219
tocLastLevelComputed : function tocLastLevelComputed ( ) {
255
- return ! this . tockLastLevel ? this . tocFirstLevel + 1 : this . tocLastLevel ;
220
+ return this . tocLastLevel > this . tocFirstLevel ? this . tocLastLevel : this . tocFirstLevel + 1 ;
256
221
}
257
222
} ,
258
- mounted : function mounted ( ) {
223
+
224
+ render : function render ( createElement ) {
259
225
var _this = this ;
260
226
261
- if ( this . $el . childNodes . length > 0 ) {
262
- this . source = '' ;
227
+ this . md = new _markdownIt2 . default ( ) . use ( _markdownItSub2 . default ) . use ( _markdownItSup2 . default ) . use ( _markdownItFootnote2 . default ) . use ( _markdownItDeflist2 . default ) . use ( _markdownItAbbr2 . default ) . use ( _markdownItIns2 . default ) . use ( _markdownItMark2 . default ) ;
228
+
229
+ if ( this . emoji ) {
230
+ this . md . use ( _markdownItEmoji2 . default ) ;
231
+ }
232
+
233
+ this . md . set ( {
234
+ html : this . html ,
235
+ xhtmlOut : this . xhtmlOut ,
236
+ breaks : this . breaks ,
237
+ linkify : this . linkify ,
238
+ typographer : this . typographer ,
239
+ langPrefix : this . langPrefix ,
240
+ quotes : this . quotes
241
+ } ) ;
242
+ this . md . renderer . rules . table_open = function ( ) {
243
+ return '<table class="' + _this . tableClass + '">\n' ;
244
+ } ;
245
+
246
+ if ( this . toc ) {
247
+ this . md . use ( _markdownItTocAndAnchor2 . default , {
248
+ tocClassName : this . tocClass ,
249
+ tocFirstLevel : this . tocFirstLevel ,
250
+ tocLastLevel : this . tocLastLevelComputed ,
251
+ anchorLink : this . tocAnchorLink ,
252
+ anchorLinkSymbol : this . tocAnchorLinkSymbol ,
253
+ anchorLinkSpace : this . tocAnchorLinkSpace ,
254
+ anchorClassName : this . tocAnchorClass ,
255
+ anchorLinkSymbolClassName : this . tocAnchorLinkClass ,
256
+ tocCallback : function tocCallback ( tocMarkdown , tocArray , tocHtml ) {
257
+ if ( tocHtml ) {
258
+ if ( _this . tocId && document . getElementById ( _this . tocId ) ) {
259
+ document . getElementById ( _this . tocId ) . innerHTML = tocHtml ;
260
+ }
261
+
262
+ _this . $emit ( 'toc-rendered' , tocHtml ) ;
263
+ }
264
+ }
265
+ } ) ;
266
+ }
267
+
268
+ var outHtml = this . show ? this . md . render ( this . sourceData ) : '' ;
269
+
270
+ this . $emit ( 'rendered' , outHtml ) ;
271
+ return createElement ( 'div' , {
272
+ domProps : {
273
+ innerHTML : outHtml
274
+ }
275
+ } ) ;
276
+ } ,
277
+ beforeMount : function beforeMount ( ) {
278
+ var _this2 = this ;
279
+
280
+ if ( this . $slots . default ) {
281
+ this . sourceData = '' ;
263
282
var _iteratorNormalCompletion = true ;
264
283
var _didIteratorError = false ;
265
284
var _iteratorError = undefined ;
266
285
267
286
try {
268
- for ( var _iterator = ( 0 , _getIterator3 . default ) ( this . $el . childNodes ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
269
- var el = _step . value ;
287
+ for ( var _iterator = ( 0 , _getIterator3 . default ) ( this . $slots . default ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
288
+ var slot = _step . value ;
270
289
271
- var ext = el . outerHTML ? el . outerHTML : el . textContent ;
272
- this . sourceOut += ext ;
290
+ this . sourceData += slot . text ;
273
291
}
274
292
} catch ( err ) {
275
293
_didIteratorError = true ;
@@ -286,13 +304,14 @@ return /******/ (function(modules) { // webpackBootstrap
286
304
}
287
305
}
288
306
}
289
- rende ( this ) ;
307
+
290
308
this . $watch ( 'source' , function ( ) {
291
- rende ( _this ) ;
309
+ _this2 . rende ( ) ;
292
310
} ) ;
311
+
293
312
this . watches . forEach ( function ( v ) {
294
- _this . $watch ( v , function ( ) {
295
- rende ( _this ) ;
313
+ _this2 . $watch ( v , function ( ) {
314
+ _this2 . rende ( ) ;
296
315
} ) ;
297
316
} ) ;
298
317
}
0 commit comments