How to let marked and google-code-prettify work together?

I'm using marked to convert some markdown code to html, which has some code blocks. So I want to use google-code-prettify to highlight the code.

Marked has provided a callback for code, as documented:

  gfm: true,
  pedantic: false,
  sanitize: true,
  // callback for code highlighter
  highlight: function(code, lang) {
    if (lang === 'js') {
      return javascriptHighlighter(code);
    return code;

But I don't find a method like javascritHighlighter(..) from google-code-prettify. How to let them work together?


Just did this myself. The function you're looking for is:

 * @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)

So you'll want something like:

prettyPrintOne(code, 'js', false)

Need Your Help

How to enable text selection in PDF.js

javascript node.js pdf.js pdfjs

I'm trying to use pdf.js to display pdfs. I already can display a pdf, but text selection isn't enabled. Can somebody give a small example on how to enable text selection in pdf.js?

Relocatable symbols in ELF format (assembly language)

assembly gnu elf

We are developing a port of the GNU Assembler for a client architecture.