我正在使用marked将一些标记代码转换为html,其中包含一些代码块。所以我想使用google-code-prettify来突出显示代码。
Marked为代码提供了回调,如文档所示:
marked.setOptions({
gfm: true,
pedantic: false,
sanitize: true,
// callback for code highlighter
highlight: function(code, lang) {
if (lang === 'js') {
return javascriptHighlighter(code);
}
return code;
}
});但我没有从谷歌代码美化中找到像javascritHighlighter(..)这样的方法。如何让它们协同工作?
发布于 2012-10-06 11:14:06
这是我自己做的。您要查找的函数是:
/**
* @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)https://stackoverflow.com/questions/11449837
复制相似问题