如图
以下是代码。
import Loading from '~/components/Loading.vue';
import marked from "marked";
import hljs from "highlight.js";
// import 'highlight.js/styles/googlecode.css';
import 'highlight.js/styles/atom-one-dark.css';
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code) {
return hljs.highlightAuto(code).value;
},
pedantic: false,
gfm: true,
tables: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
}
);
article.content = marked(article.content);
<div v-html="article.content" ></div>
具体原因是
pre
标签没有hljs
这个class,加上就可以(代码高亮样式都是给hljs
class加上的背景色),这算是一种解决方法,但是不优雅