Files
Yi.Admin/Yi.BBS.Vue3/src/components/ArticleContentInfo.vue

41 lines
1004 B
Vue
Raw Normal View History

2023-03-11 17:00:36 +08:00
<template>
<div>
2023-03-12 01:50:11 +08:00
<div class="markdown-body" v-html="outputHtml"></div>
2023-03-11 17:00:36 +08:00
</div>
</template>
<script setup>
import { marked } from 'marked';
import hljs from "highlight.js";
2023-03-12 01:50:11 +08:00
//可以设置加载样式切换主题
import 'highlight.js/styles/atom-one-dark.css'
import '@/assets/github-markdown.css'
import { ref,watch } from 'vue';
2023-03-11 17:00:36 +08:00
2023-03-12 01:50:11 +08:00
const outputHtml=ref("")
const props = defineProps(['code'])
watch(props,(n,o)=>{
2023-03-11 17:00:36 +08:00
marked.setOptions({
renderer: new marked.Renderer(),
2023-03-12 01:50:11 +08:00
highlight: function(code) {
return hljs.highlightAuto(code).value;
},
2023-03-11 17:00:36 +08:00
pedantic: false,
2023-03-12 01:50:11 +08:00
gfm: true,//允许 Git Hub标准的markdown
tables: true,//支持表格
2023-03-11 17:00:36 +08:00
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
2023-03-12 01:50:11 +08:00
xhtml: false,
smartLists: true,
2023-03-11 17:00:36 +08:00
}
);
2023-03-12 01:50:11 +08:00
//需要注意代码块样式
outputHtml.value = marked(n.code).replace(/<pre>/g, "<pre class='hljs'>")
2023-03-11 17:00:36 +08:00
})
</script>
2023-03-12 01:50:11 +08:00