Skip to content

Commit

Permalink
doc: update maekdown.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsongc committed Dec 16, 2021
1 parent e48e75e commit 00a3534
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 70 deletions.
41 changes: 6 additions & 35 deletions doc/cn/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

#### 方法1 通过全局引入的mavonEditor获取
```javascript
import mavonEditor from 'mavon-editor'
Vue.use(mavonEditor)
import MavonEditor from 'mavon-editor'
Vue.use(MavonEditor)
...
mavonEditor.markdownIt
const markdownIt = MavonEditor.mavonEditor.getMarkdownIt()
```

#### 方法2 通过局部引入的mavonEditor获取
```javascript
import {mavonEditor} from 'mavon-editor'
mavonEditor.getMarkdownIt()
import { mavonEditor } from 'mavon-editor'
const markdownIt = mavonEditor.getMarkdownIt()
```

#### 方法3 通过mavonEditor的实例获取
```javascript
<mavonEditor ref=md></mavonEditor>
...
this.refs.md.markdownIt
const markdownIt = this.refs.md.getMarkdownIt()
```

### 使用markdown-it对象
Expand All @@ -33,32 +33,3 @@
```

> [更多设置参考markdown-it...](https://github.com/markdown-it/markdown-it)
### 简单示例
仅使用mavonEditor的markdown渲染功能。

> 注意:`class="markdown-body"` 是必要的,否则CSS样式会于预览的不一样
```html
<template>
<div>
<span class="markdown-body" v-html="rawHtml"></span>
</div>
</template>

<script>
import { mavonEditor } from 'mavon-editor';
import 'mavon-editor/dist/css/index.css';
export default {
name: 'Example',
props: {
markdown: String,
},
computed: {
rawHtml: function() {
return mavonEditor.getMarkdownIt().render(this.markdown);
}
},
};
</script>
```
39 changes: 5 additions & 34 deletions doc/en/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

#### method 1: Global Registration
```javascript
import mavonEditor from 'mavon-editor'
Vue.use(mavonEditor)
import MavonEditor from 'mavon-editor'
Vue.use(MavonEditor)
...
mavonEditor.markdownIt
const markdownIt = MavonEditor.mavonEditor.getMarkdownIt()
```

#### method 2: Local Registration
```javascript
import {mavonEditor} from 'mavon-editor'
mavonEditor.getMarkdownIt()
const markdownIt = mavonEditor.getMarkdownIt()
```

#### method 3: Use mavonEditor ref
```javascript
<mavonEditor ref=md></mavonEditor>
...
this.refs.md.markdownIt
const markdownIt = this.refs.md.getMarkdownIt()
```

### Use markdown-it object
Expand All @@ -33,32 +33,3 @@
```

> [markdown-it API](https://github.com/markdown-it/markdown-it)
### Simple example
Only use the markdown rendering function of mavonEditor.

> Notice:`class="markdown-body"` is necessary, or the CSS style will be different from the preview
```html
<template>
<div>
<span class="markdown-body" v-html="rawHtml"></span>
</div>
</template>

<script>
import { mavonEditor } from 'mavon-editor';
import 'mavon-editor/dist/css/index.css';
export default {
name: 'Example',
props: {
markdown: String,
},
computed: {
rawHtml: function() {
return mavonEditor.getMarkdownIt().render(this.markdown);
}
},
};
</script>
```
6 changes: 5 additions & 1 deletion src/dev/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
<div class="navigate">
<span @click="viewIndex = 1">Full demo</span>
<span @click="viewIndex = 2">Simple demo</span>
<span @click="viewIndex = 3">Markdown Render</span>
</div>
<div>
<App v-if="viewIndex == 1"></App>
<Editor v-else-if="viewIndex == 2"></Editor>
<MarkdownRender v-else-if="viewIndex == 3"></MarkdownRender>
</div>
</div>
</template>

<script>
import app from './app.vue';
import editor from './editor.vue';
import markdownRender from './markdown-it.vue';
export default {
name: 'demo',
components: {
App: app,
Editor: editor
Editor: editor,
MarkdownRender: markdownRender
},
data() {
return {
Expand Down
36 changes: 36 additions & 0 deletions src/dev/markdown-it.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<div class="markdown">
<span class="markdown-body" v-html="rawHtml"></span>
</div>
</template>

<script>
import { mavonEditor } from '../index';
import '../../dist/css/index.css';
import { CONFIG } from '../lib/config.js';
export default {
name: 'Example',
data() {
return {
d_language: 'zh-CN',
markdown: ''
};
},
computed: {
rawHtml: function () {
const markdownIt = mavonEditor.getMarkdownIt();
this.markdown = CONFIG[`help_${this.d_language}`];
markdownIt.set({ breaks: false });
return markdownIt.render(this.markdown);
// return mavonEditor.getMarkdownIt().render(this.markdown);
}
}
};
</script>
<style>
.markdown {
margin: auto;
width: 80%;
}
</style>

0 comments on commit 00a3534

Please sign in to comment.