From 3e7d6ab26ceb5b96fd1f1a3123c5c71ad8d5bca2 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 18 Feb 2017 23:04:52 +0800 Subject: [PATCH] docs: add executeScript demo --- docs/configuration.md | 22 ++++++++++++++++++++ docs/themes.md | 34 +++++++++++++++++++++++++++++++ docs/zh-cn/configuration.md | 22 ++++++++++++++++++++ docs/zh-cn/themes.md | 40 ++++++++++++++++++++++++++++++++++++- src/core/config.js | 1 + src/core/render/index.js | 10 +++++++--- 6 files changed, 125 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 487df25e..4b05476e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -267,3 +267,25 @@ window.$docsify = { autoHeader: true } ``` + +## execute-script + +- type: `Boolean` + +Execute the script on the page. Only parse the first script tag([demo](themes)). If Vue is present, it is turned on by default. + +```js +window.$docsify = { + executeScript: true +} +``` + +```markdown +## This is test + + + +``` + diff --git a/docs/themes.md b/docs/themes.md index 67b9a5d9..ed5ae40a 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -12,3 +12,37 @@ There are currently three themes available. Copy [Vue](//vuejs.org) and [buble]( !> This compressed files in `/lib/themes/`. If you have any ideas or would like to develop new theme, welcome submit [PR](https://github.com/QingWei-Li/docsify/pulls). + +#### Click to preview + + +
+ vue.css + buble.css + dark.css +
+ + + + + diff --git a/docs/zh-cn/configuration.md b/docs/zh-cn/configuration.md index 8ab81573..685de3c1 100644 --- a/docs/zh-cn/configuration.md +++ b/docs/zh-cn/configuration.md @@ -265,3 +265,25 @@ window.$docsify = { autoHeader: true } ``` + +## execute-script + +- 类型:`Boolean` + +执行文档里的 script 标签里的脚本,只执行第一个 script ([demo](zh-cn/themes))。 如果 Vue 存在,则自动开启。 + +```js +window.$docsify = { + executeScript: true +} +``` + +```markdown +## This is test + + + +``` + diff --git a/docs/zh-cn/themes.md b/docs/zh-cn/themes.md index b728d7ab..28596e2a 100644 --- a/docs/zh-cn/themes.md +++ b/docs/zh-cn/themes.md @@ -8,6 +8,44 @@ ``` +vue.css +buble.css +dark.css + !> CSS 的压缩文件位于 `/lib/themes/` -如果你有其他想法或者想开发别的主题,欢迎提 [PR](https://github.com/QingWei-Li/docsify/pulls)。 \ No newline at end of file +如果你有其他想法或者想开发别的主题,欢迎提 [PR](https://github.com/QingWei-Li/docsify/pulls)。 + +#### 点击切换主题 + + +
+ vue.css + buble.css + dark.css +
+ + + + + diff --git a/src/core/config.js b/src/core/config.js index 230348a2..f218e6de 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -15,6 +15,7 @@ const config = merge({ themeColor: '', nameLink: window.location.pathname, autoHeader: false, + executeScript: false, ga: '' }, window.$docsify) diff --git a/src/core/render/index.js b/src/core/render/index.js index 746fdf70..370a5701 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -14,7 +14,9 @@ function executeScript () { const code = script.innerText.trim() if (!code) return false - window.__EXECUTE_RESULT__ = new Function('return ' + code)() + setTimeout(_ => { + window.__EXECUTE_RESULT__ = new Function(code)() + }, 0) } function renderMain (html) { @@ -31,11 +33,13 @@ function renderMain (html) { if (!this.config.executeScript && typeof window.Vue !== 'undefined' && !executeScript()) { - window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main') + setTimeout(_ => { + window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main') + }, 0) } if (this.config.auto2top) { - setTimeout(() => scroll2Top(this.config.auto2top), 0) + scroll2Top(this.config.auto2top) } }