Javascript 如何让标记和谷歌代码美化一起工作?
我正在使用将一些标记代码转换为html,其中包含一些代码块。所以我想用它来突出显示代码 Marked为代码提供了回调,如文档所示:Javascript 如何让标记和谷歌代码美化一起工作?,javascript,codehighlighter,Javascript,Codehighlighter,我正在使用将一些标记代码转换为html,其中包含一些代码块。所以我想用它来突出显示代码 Marked为代码提供了回调,如文档所示: marked.setOptions({ gfm: true, pedantic: false, sanitize: true, // callback for code highlighter highlight: function(code, lang) { if (lang === 'js') { return javas
marked.setOptions({
gfm: true,
pedantic: false,
sanitize: true,
// callback for code highlighter
highlight: function(code, lang) {
if (lang === 'js') {
return javascriptHighlighter(code);
}
return code;
}
});
但是我在google code prettify中找不到像
JavaScritighLighter(…)
这样的方法。如何让他们一起工作?我自己就是这么做的。您正在寻找的功能是:
/**
* @param sourceCodeHtml {string} The HTML to pretty print.
* @param opt_langExtension {string} The language name to use.
* Typically, a filename extension like 'cpp' or 'java'.
* @param opt_numberLines {number|boolean} True to number lines,
* or the 1-indexed number of the first line in sourceCodeHtml.
*/
function prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines)
因此,您将需要以下内容:
prettyPrintOne(code, 'js', false)