diff --git a/CHANGELOG.md b/CHANGELOG.md index 1991e5df..32a88395 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +### Bug fixes +- Destroys the vue instance when the route is changed + +### Features +- Add `!>` and `?>` doc helper. + +### Break change +- Remove `!` doc helper. + ## 1.8.0 ### Bug fixes - Using `v-pre` skip compilation. diff --git a/docs/README.md b/docs/README.md index 56cdff77..e28164f6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -160,10 +160,10 @@ window.$docsify = { ### Doc Helpers #### p.tip -'! ' add your content will rendered as `
content
` +`!> ` add your content will rendered as `content
` ```markdown -! Important **information** +!> Important **information** ``` It will be rendered @@ -174,9 +174,48 @@ It will be rendered e.g. -! Important **information** +!> Important **information** +#### p.warn + +```markdown +?> todo info +``` + +?> todo info + +### Combining Vue +We can write the Vue syntax directly in the markdown file, when the Vue library is loaded into `index.html`. Default will automatically initialize a Vue instance, of course, we can also manually. + +index.html +```html + + +``` + +```markdown +Hello, {{ msg }}
+Hello, {{ msg }}
+${text.replace(TIP_RE, '')}
` : `${text}
` + if (/^!>/.test(text)) { + return tpl.helper('tip', text) + } else if (/^\?>/.test(text)) { + return tpl.helper('warn', text) + } + return `${text}
` } if (typeof OPTIONS.markdown === 'function') { @@ -100,12 +103,13 @@ export function renderArticle (content) { if (content && typeof Vue !== 'undefined') { const script = content.match('') - script && document.body.querySelector('article script').remove() - const vm = script + script && document.body.querySelector('article script').remove() + CACHE.vm && CACHE.vm.$destroy() + CACHE.vm = script ? new Function(`return ${script[1].trim()}`)() : new Vue({ el: 'main' }) // eslint-disable-line - vm && vm.$nextTick(_ => event.scrollActiveSidebar()) + CACHE.vm && CACHE.vm.$nextTick(_ => event.scrollActiveSidebar()) } if (OPTIONS.auto2top) setTimeout(() => event.scroll2Top(OPTIONS.auto2top), 0) } diff --git a/src/themes/basic/_layout.css b/src/themes/basic/_layout.css index b02891d7..cde49f67 100644 --- a/src/themes/basic/_layout.css +++ b/src/themes/basic/_layout.css @@ -354,6 +354,12 @@ body.sticky { } } +.markdown-section p.warn { + padding: 1em; + background: rgba($color-primary, 0.1); + border-radius: 2px; +} + body.close { .sidebar { transform: translateX(-$sidebar-width); diff --git a/src/tpl.js b/src/tpl.js index 6a35f681..db832586 100644 --- a/src/tpl.js +++ b/src/tpl.js @@ -72,3 +72,6 @@ export function tree (toc, tpl = '') { return tpl } +export function helper (className, content) { + return `${content.slice(5).trim()}
` +}