js使用highlight.js高亮你的代码(2)

var marked = require('marked'); var highlight = require('highlight.js'); marked.setOptions({ renderer: new marked.Renderer(), gfm: true, tables: true, breaks: false, pedantic: false, sanitize: false, smartLists: true, smartypants: false, highlight: function (code) { return highlight.highlightAuto(code).value; } });

返回的文档已经添加了对应的class。

<pre> <code> <span>var</span> math = (<span>'math'</span>) ; <span>export</span>.increment = <span><span>function</span>(<span>val</span>) </span>{ <span>return</span> math.add(val,<span>1</span>) } </code> </pre>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydzys.html