Skip to content

Commit e9d37a9

Browse files
committed
add markdown to html
1 parent 9607d07 commit e9d37a9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"mockjs": "1.0.1-beta3",
2626
"normalize.css": "3.0.2",
2727
"nprogress": "0.2.0",
28+
"showdown": "1.7.1",
2829
"simplemde": "1.11.2",
2930
"sortablejs": "1.5.1",
3031
"vue": "2.3.3",

src/views/components/markdown.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<div class="editor-container">
55
<MdEditor id='contentEditor' ref="contentEditor" v-model='content' :height="300" :zIndex='20'></MdEditor>
66
</div>
7+
<el-button @click='markdown2Html' style="margin-top:80px;" type="primary">转为HTML<i class="el-icon-document el-icon--right"></i></el-button>
8+
<div v-html="html"></div>
79
</div>
810
</template>
911
<script>
@@ -13,7 +15,16 @@
1315
components: { MdEditor },
1416
data() {
1517
return {
16-
content: 'Simplemde'
18+
content: 'Simplemde',
19+
html: ''
20+
}
21+
},
22+
methods: {
23+
markdown2Html() {
24+
import('showdown').then(showdown => {
25+
const converter = new showdown.Converter();
26+
this.html = converter.makeHtml(this.content)
27+
})
1728
}
1829
}
1930
};

0 commit comments

Comments
 (0)