2012-07-12 9 views
2

일부 markdown 코드를 html로 변환하려면 marked을 사용하고 있습니다. 일부 코드 블록이 있습니다. 그래서 google-code-prettify을 사용하여 코드를 강조하고 싶습니다. 문서화와 같은 코드에 대한 콜백을 제공하고 마크 된표시된 코드와 Google 코드가 가장 잘 어울리는 방법은 무엇입니까?

:

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(..) 같은 방법을 찾을 수 없습니다. 함께 일하게하는 방법?

답변

6

그냥 직접 해보았습니다. 당신이 찾고있는 기능은 다음과 같습니다

prettyPrintOne(code, 'js', false) 
:

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

그래서 당신이 뭔가를 할 것입니다