2017-04-15 38 views
0

我對使用Typescript和Angular 4很新穎,而且我無法將Google Code-Prettify與角度CLI設置集成。使用Google Code-Prettify與Typscript和Angular 4

我想弄清楚如何導入代碼美化與我的組件動態使用,但我不確定如何完成此操作。

我試着用NPM安裝並從軟件包中導入PR,但PR作爲空對象進來。

有沒有辦法完成我想要做的事情?

感謝

回答

1
you can change some code in prettify.js: 


             
  
//old code in here 
 
if (typeof define === "function" && define['amd']) { 
 
    define("google-code-prettify", [], function() { 
 
    \t return PR; 
 
    \t }); 
 
} 
 
//new code in here 
 
     
 
if(typeof module==="object"&&typeof module.exports==="object") { 
 
    module.exports = PR; 
 
} else if (typeof define === "function" && define['amd']) { 
 
    define("google-code-prettify", [], function() { 
 
    \t return PR; 
 
    }); 
 
}
use case like this:
let prettify = require('../../dep/prettify'); 
 
$("#doc-view").html(virtualDom); 
 
prettify.prettyPrint();
+0

我沒有機會尚未嘗試這個,但看起來完全像什麼,我一直在尋找。謝謝! – Mattador