Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 2acb6d9

Browse files
committed
new version 2.1.1 & fix miaolz123#9
1 parent fe986fe commit 2acb6d9

6 files changed

+234
-168
lines changed

.eslintrc.jss .eslintrc.js

File renamed without changes.

dist/vue-markdown.common.js

+73-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-markdown v2.0.1
2+
* vue-markdown v2.1.1
33
* https://github.com/miaolz123/vue-markdown
44
* MIT License
55
*/
@@ -112,54 +112,18 @@ return /******/ (function(modules) { // webpackBootstrap
112112

113113
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
114114

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-
155115
exports.default = {
116+
md: new _markdownIt2.default(),
117+
156118
template: '<div><slot></slot></div>',
119+
157120
data: function data() {
158121
return {
159-
sourceOut: ''
122+
sourceData: this.source
160123
};
161124
},
162125

126+
163127
props: {
164128
watches: {
165129
type: Array,
@@ -250,26 +214,80 @@ return /******/ (function(modules) { // webpackBootstrap
250214
default: 'toc-anchor-link'
251215
}
252216
},
217+
253218
computed: {
254219
tocLastLevelComputed: function tocLastLevelComputed() {
255-
return !this.tockLastLevel ? this.tocFirstLevel + 1 : this.tocLastLevel;
220+
return this.tocLastLevel > this.tocFirstLevel ? this.tocLastLevel : this.tocFirstLevel + 1;
256221
}
257222
},
258-
mounted: function mounted() {
223+
224+
render: function render(createElement) {
259225
var _this = this;
260226

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 = '';
263282
var _iteratorNormalCompletion = true;
264283
var _didIteratorError = false;
265284
var _iteratorError = undefined;
266285

267286
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;
270289

271-
var ext = el.outerHTML ? el.outerHTML : el.textContent;
272-
this.sourceOut += ext;
290+
this.sourceData += slot.text;
273291
}
274292
} catch (err) {
275293
_didIteratorError = true;
@@ -286,13 +304,14 @@ return /******/ (function(modules) { // webpackBootstrap
286304
}
287305
}
288306
}
289-
rende(this);
307+
290308
this.$watch('source', function () {
291-
rende(_this);
309+
_this2.rende();
292310
});
311+
293312
this.watches.forEach(function (v) {
294-
_this.$watch(v, function () {
295-
rende(_this);
313+
_this2.$watch(v, function () {
314+
_this2.rende();
296315
});
297316
});
298317
}

dist/vue-markdown.js

+73-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-markdown v2.0.1
2+
* vue-markdown v2.1.1
33
* https://github.com/miaolz123/vue-markdown
44
* MIT License
55
*/
@@ -133,54 +133,18 @@ return /******/ (function(modules) { // webpackBootstrap
133133

134134
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
135135

136-
var md = new _markdownIt2.default();
137-
138-
var rende = function rende(root) {
139-
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);
140-
if (root.emoji) md.use(_markdownItEmoji2.default);
141-
md.set({
142-
html: root.html,
143-
xhtmlOut: root.xhtmlOut,
144-
breaks: root.breaks,
145-
linkify: root.linkify,
146-
typographer: root.typographer,
147-
langPrefix: root.langPrefix,
148-
quotes: root.quotes
149-
});
150-
md.renderer.rules.table_open = function () {
151-
return '<table class="' + root.tableClass + '">\n';
152-
};
153-
if (root.toc) {
154-
md.use(_markdownItTocAndAnchor2.default, {
155-
tocClassName: root.tocClass,
156-
tocFirstLevel: root.tocFirstLevel,
157-
tocLastLevel: root.tocLastLevelComputed,
158-
anchorLink: root.tocAnchorLink,
159-
anchorLinkSymbol: root.tocAnchorLinkSymbol,
160-
anchorLinkSpace: root.tocAnchorLinkSpace,
161-
anchorClassName: root.tocAnchorClass,
162-
anchorLinkSymbolClassName: root.tocAnchorLinkClass,
163-
tocCallback: function tocCallback(tocMarkdown, tocArray, tocHtml) {
164-
if (tocHtml) {
165-
if (root.tocId && document.getElementById(root.tocId)) document.getElementById(root.tocId).innerHTML = tocHtml;
166-
root.$emit('toc-rendered', tocHtml);
167-
}
168-
}
169-
});
170-
} else if (root.tocId && document.getElementById(root.tocId)) document.getElementById(root.tocId).innerHTML = '';
171-
var outHtml = root.show ? md.render(root.sourceOut) : '';
172-
root.$el.innerHTML = outHtml;
173-
root.$emit('rendered', outHtml);
174-
};
175-
176136
exports.default = {
137+
md: new _markdownIt2.default(),
138+
177139
template: '<div><slot></slot></div>',
140+
178141
data: function data() {
179142
return {
180-
sourceOut: ''
143+
sourceData: this.source
181144
};
182145
},
183146

147+
184148
props: {
185149
watches: {
186150
type: Array,
@@ -271,26 +235,80 @@ return /******/ (function(modules) { // webpackBootstrap
271235
default: 'toc-anchor-link'
272236
}
273237
},
238+
274239
computed: {
275240
tocLastLevelComputed: function tocLastLevelComputed() {
276-
return !this.tockLastLevel ? this.tocFirstLevel + 1 : this.tocLastLevel;
241+
return this.tocLastLevel > this.tocFirstLevel ? this.tocLastLevel : this.tocFirstLevel + 1;
277242
}
278243
},
279-
mounted: function mounted() {
244+
245+
render: function render(createElement) {
280246
var _this = this;
281247

282-
if (this.$el.childNodes.length > 0) {
283-
this.source = '';
248+
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);
249+
250+
if (this.emoji) {
251+
this.md.use(_markdownItEmoji2.default);
252+
}
253+
254+
this.md.set({
255+
html: this.html,
256+
xhtmlOut: this.xhtmlOut,
257+
breaks: this.breaks,
258+
linkify: this.linkify,
259+
typographer: this.typographer,
260+
langPrefix: this.langPrefix,
261+
quotes: this.quotes
262+
});
263+
this.md.renderer.rules.table_open = function () {
264+
return '<table class="' + _this.tableClass + '">\n';
265+
};
266+
267+
if (this.toc) {
268+
this.md.use(_markdownItTocAndAnchor2.default, {
269+
tocClassName: this.tocClass,
270+
tocFirstLevel: this.tocFirstLevel,
271+
tocLastLevel: this.tocLastLevelComputed,
272+
anchorLink: this.tocAnchorLink,
273+
anchorLinkSymbol: this.tocAnchorLinkSymbol,
274+
anchorLinkSpace: this.tocAnchorLinkSpace,
275+
anchorClassName: this.tocAnchorClass,
276+
anchorLinkSymbolClassName: this.tocAnchorLinkClass,
277+
tocCallback: function tocCallback(tocMarkdown, tocArray, tocHtml) {
278+
if (tocHtml) {
279+
if (_this.tocId && document.getElementById(_this.tocId)) {
280+
document.getElementById(_this.tocId).innerHTML = tocHtml;
281+
}
282+
283+
_this.$emit('toc-rendered', tocHtml);
284+
}
285+
}
286+
});
287+
}
288+
289+
var outHtml = this.show ? this.md.render(this.sourceData) : '';
290+
291+
this.$emit('rendered', outHtml);
292+
return createElement('div', {
293+
domProps: {
294+
innerHTML: outHtml
295+
}
296+
});
297+
},
298+
beforeMount: function beforeMount() {
299+
var _this2 = this;
300+
301+
if (this.$slots.default) {
302+
this.sourceData = '';
284303
var _iteratorNormalCompletion = true;
285304
var _didIteratorError = false;
286305
var _iteratorError = undefined;
287306

288307
try {
289-
for (var _iterator = (0, _getIterator3.default)(this.$el.childNodes), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
290-
var el = _step.value;
308+
for (var _iterator = (0, _getIterator3.default)(this.$slots.default), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
309+
var slot = _step.value;
291310

292-
var ext = el.outerHTML ? el.outerHTML : el.textContent;
293-
this.sourceOut += ext;
311+
this.sourceData += slot.text;
294312
}
295313
} catch (err) {
296314
_didIteratorError = true;
@@ -307,13 +325,14 @@ return /******/ (function(modules) { // webpackBootstrap
307325
}
308326
}
309327
}
310-
rende(this);
328+
311329
this.$watch('source', function () {
312-
rende(_this);
330+
_this2.rende();
313331
});
332+
314333
this.watches.forEach(function (v) {
315-
_this.$watch(v, function () {
316-
rende(_this);
334+
_this2.$watch(v, function () {
335+
_this2.rende();
317336
});
318337
});
319338
}

dist/vue-markdown.min.js

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-markdown",
3-
"version": "2.0.1",
3+
"version": "2.1.1",
44
"description": "A Powerful and Highspeed Markdown Parser for Vue",
55
"main": "dist/vue-markdown.common.js",
66
"files": [

0 commit comments

Comments
 (0)