Browse Source

upd: markdown 0.0.2

richard1015 5 years ago
parent
commit
ce35c4ce50
2 changed files with 25 additions and 23 deletions
  1. 24 22
      lib/plugin/markdown-to-vue/mdToVue.js
  2. 1 1
      lib/plugin/markdown-to-vue/package.json

+ 24 - 22
lib/plugin/markdown-to-vue/mdToVue.js

@@ -14,7 +14,7 @@ class mdVue {
 		let defaultSetting = {
 			needCode: true,
 			isbuild: true,
-			hasMarkList: true,
+			hasMarkList: true
 		};
 		this.options = Object.assign(defaultSetting, options);
 		this.rendererMd = new marked.Renderer();
@@ -25,15 +25,15 @@ class mdVue {
 		this.needHandleFiles = null;
 		this.cachePath = path.join('./cache', options.entry.split(path.sep).pop() + '.cache');
 		this.codeHandle();
-		this.checkSelf().then((res) => {
+		this.checkSelf().then(res => {
 			// 检查要编译的文件
 			let ct = new contrast({
-				entry: this.options.entry,
+				entry: this.options.entry
 			})
 				.run()
-				.then((res) => {
+				.then(res => {
 					_that.needHandleFiles = res;
-					_that.ishasOutFile(_that.options.output).then((res) => {
+					_that.ishasOutFile(_that.options.output).then(res => {
 						_that.star();
 						_that.filelisten();
 					});
@@ -45,13 +45,13 @@ class mdVue {
 		return new Promise((resolve, reject) => {
 			new contrast({
 				entry: path.join(__dirname, 'mdToVue.js'),
-				include: ['*.js'],
+				include: ['*.js']
 			})
 				.run()
-				.then((res) => {
+				.then(res => {
 					if (JSON.stringify(res) != '{}') {
 						//有变动清除当前entry缓存,重新渲染
-						rimraf(_that.cachePath, (err) => {
+						rimraf(_that.cachePath, err => {
 							console.log(err);
 							resolve();
 						});
@@ -66,10 +66,10 @@ class mdVue {
 		let _that = this;
 		let watcher = Chokidar.watch(_that.options.entry, {
 			persistent: true,
-			usePolling: true,
+			usePolling: true
 		});
 		let log = console.dir.bind(console);
-		let watchAction = function ({ event, eventPath }) {
+		let watchAction = function({ event, eventPath }) {
 			// 这里进行文件更改后的操作
 			// fileReadStar(eventPath,(res)=>{
 			//     createdFile(param.output + res.mdName + '.vue', res.html, param.needCode)
@@ -91,17 +91,17 @@ class mdVue {
 			// })
 		};
 		watcher
-			.on('change', (path) => watchAction({ event: 'change', eventPath: path }))
-			.on('unlink', (path) => watchAction({ event: 'remove', eventPath: path }));
+			.on('change', path => watchAction({ event: 'change', eventPath: path }))
+			.on('unlink', path => watchAction({ event: 'remove', eventPath: path }));
 	}
 	star() {
 		let _that = this;
 		hashElement(_that.options.entry, {
 			folders: { exclude: ['.*', 'node_modules', 'test_coverage'] },
 			files: { include: ['*.md'] },
-			matchBasename: true,
-		}).then((hash) => {
-			nodeFilelist.read([_that.options.entry], { ext: 'md' }, (res) => {
+			matchBasename: true
+		}).then(hash => {
+			nodeFilelist.read([_that.options.entry], { ext: 'md' }, res => {
 				res.map((item, index) => {
 					_that.vueDesWrite(item.path);
 					// let fileSplits = item.path.split(path.sep);
@@ -158,7 +158,7 @@ class mdVue {
 			//     });
 			// })
 		}
-		_that.read(getpath).then((res) => {
+		_that.read(getpath).then(res => {
 			_that.headHandle();
 			_that.markHandle();
 			let html = _that.marked(res);
@@ -166,6 +166,7 @@ class mdVue {
 				outsrc: _that.options.output,
 				name: fileName + '.vue',
 				html: html,
+				vname: fileName
 			});
 		});
 	}
@@ -195,7 +196,8 @@ class mdVue {
                                 </div>
                             </template><script>import root from '../root.js';
             export default {
-                mixins:[root]
+                mixins:[root],
+                name:${param.vname}
             }</script>`;
 			_that.Articlehead = '';
 			_that.Articleheadcount = 0;
@@ -206,7 +208,7 @@ class mdVue {
 		return new Promise((resolve, reject) => {
 			fs.stat(outPath, (err, res) => {
 				if (err) {
-					fs.mkdir(outPath, (err) => {
+					fs.mkdir(outPath, err => {
 						if (err) {
 							reject(err);
 						} else {
@@ -222,7 +224,7 @@ class mdVue {
 	headHandle() {
 		let _that = this;
 		let options = _that.options;
-		_that.rendererMd.heading = function (text, level) {
+		_that.rendererMd.heading = function(text, level) {
 			let headcode = '<i class="qrcode"><a :href="demourl"><span>请使用手机扫码体验</span><img :src="codeurl" alt=""></a></i>';
 			let codeHead = `<h1>` + text + headcode + `</h1>`;
 			let normal = `<h` + level + `>` + text + `</h` + level + `>`;
@@ -275,7 +277,7 @@ class mdVue {
 	}
 	codeHandle() {
 		var that = this;
-		this.rendererMd.code = function (code, infostring, escaped) {
+		this.rendererMd.code = function(code, infostring, escaped) {
 			var lang = (infostring || '').match(/\S*/)[0];
 			if (this.options.highlight) {
 				var out = this.options.highlight(code, lang);
@@ -306,10 +308,10 @@ class mdVue {
 		let _that = this;
 		this.marked.setOptions({
 			renderer: _that.rendererMd,
-			highlight: function (code) {
+			highlight: function(code) {
 				return require('highlight.js').highlightAuto(code).value;
 			},
-			tables: true,
+			tables: true
 		});
 	}
 }

+ 1 - 1
lib/plugin/markdown-to-vue/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@nutui/markdown-to-vue",
-  "version": "0.0.1",
+  "version": "0.0.2",
   "description": "markdown-to-vue",
   "main": "mdToVue.js",
   "scripts": {