【问题标题】:How to let marked and google-code-prettify work together?如何让标记和 google-code-prettify 一起工作?
【发布时间】:2012-07-12 10:23:39
【问题描述】:

我正在使用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;
  }
});

但我在 google-code-prettify 中找不到像 javascritHighlighter(..) 这样的方法。如何让他们一起工作?

【问题讨论】:

    标签: javascript codehighlighter


    【解决方案1】:

    这是我自己做的。您正在寻找的功能是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      相关资源
      最近更新 更多