Skip to content

Commit

Permalink
feat: allow to add component mixins and more
Browse files Browse the repository at this point in the history
- Added `componentMixins` option
- Allow plugin to extend markdown component via `extendMarkdownComponent` hook
  • Loading branch information
egoist committed Nov 18, 2018
1 parent 9c3850e commit d04adad
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ export default {
computed: {
MarkdownBody() {
return {
const {componentMixins} = this.$store.getters.config
const component = {
mixins: componentMixins || [],
name: 'MarkdownBody',
template: `<div class="markdown-body">${this.$store.state.html}</div>`
}
hooks.process('extendMarkdownComponent', component)
return component
}
},
Expand Down
9 changes: 5 additions & 4 deletions website/docs/guide/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ function debounce(func, wait, immediate) {

The languages we support by default:

- JavaScript
- CSS
- Markdown
- HTML
<ul>
<li v-for="lang in builtinLanguages" :key="lang">
{{ lang }}
</li>
</ul>

You can use [highlight](/options#highlight) option to add more languages.

Expand Down
6 changes: 6 additions & 0 deletions website/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ The source path to fetch markdown files from, by default we load them from the r

It can also be a full URL like: `https://some-website/path/to/markdown/files` so that you can load files from a different domain.

## componentMixins

- Type: `Array<Object>`

Basically an array of [Vue mixins](https://vuejs.org/v2/api/#mixins) that are applied to all markdown components.


## highlight

Expand Down
9 changes: 5 additions & 4 deletions website/docs/zh/guide/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ function debounce(func, wait, immediate) {

默认支持的语言:

- JavaScript
- CSS
- Markdown
- HTML
<ul>
<li v-for="lang in builtinLanguages" :key="lang">
{{ lang }}
</li>
</ul>

你可以查看[高亮](/zh/options#highlight)选项添加更多语言。

Expand Down
6 changes: 6 additions & 0 deletions website/docs/zh/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ interface ItemLink {
它也可以是完整的 URL,例如: `https://some-website/path/to/markdown/files`,以便于你可以从其他域名加载文件。


## componentMixins

- 类型: `Array<Object>`

一个包含 [Vue mixins](https://vuejs.org/v2/api/#mixins) 的数组,会被应用到所有的 Markdown 组件中。

## highlight

- 类型:`Array<string>`
Expand Down
10 changes: 10 additions & 0 deletions website/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import googleAnalytics from '@leptosia/docute-google-analytics'
import Docute from '../src'
import prismLanguages from '../src/utils/prismLanguages'

new Docute({
target: 'app',
Expand All @@ -10,6 +11,15 @@ new Docute({
].filter(Boolean),
editLinkBase: 'https://github.com/leptosia/docute/tree/master/website/docs',
editLinkText: 'Edit this page on GitHub',
componentMixins: [
{
data() {
return {
builtinLanguages: prismLanguages.builtin
}
}
}
],
versions: {
v4: {
link: '/'
Expand Down

0 comments on commit d04adad

Please sign in to comment.