Source: Guide & Download and Getting Started
This method will automatically load the CSS Skin file. See below the script inclusion:
<script type="text/javascript" src="/MyPath/prettify/loader/run_prettify.js?skin=sons-of-obsidian" ></script>
Or ... if you want you can alternatively use the CDN:
<script type="text/javascript" src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=sons-of-obsidian" > </script>
In order by to load CSS Skin file, firt time include the lib script:
<script type="text/javascript" src="/MyPath/prettify/loader/prettify.js" > </script>
Or via CDN:
<script type="text/javascript" src="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.js" > </script>
And after inclusion you have to use custom JS script, see below:
<script type="text/javascript" > //--------------------------- function getThemeName() { var theme = "sons-of-obsidian"; // You can pick this value from nn attribute, or some other moethod, etc. return theme ? theme : 'default'; } //--------------------------- function loadTheme(theme) { var base = "MyPath/prettify/loader"; var defaultTheme = base +"/prettify.css"; var setTheme = base +"/skins/"+ theme +".css"; var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = theme === 'default' ? defaultTheme : setTheme; document.getElementsByTagName('head')[0].appendChild(link); } //--------------------------- $( document ).ready(function() { PR.prettyPrint(); // Launch when "prettify.js" is loaded }); //--------------------------- (function () { loadTheme( getThemeName() ); // Load the selected stylesheet })(); </script>
In the following example you can see how to use Prettify, the wrapper to use and some other feature.
<pre>
tag.
<pre class="prettyprint linenums prettify-fix-1" > //----------------------------------- // API - CLASSIC METHOD // GET ROW CONTENT var p = { 'tag': $itemDiv, //'bypassRowSearch': true } var rowData = api.rowData( p ); // log( rowData ); STOP //----------------------------------- // MODIFICATION rowData = {}; rowData.item = $itemDiv[0].innerText; rowData.category = "CHANGED!"; //----------------------------------- // SET ROW CONTENT var p = { 'tag': $itemDiv, 'rowData': rowData, 'updateGUI': true, // [ "ord_item" ], 'bypassRowSearch': false, } var ret = api.rowData( p ); if( !p.updateGUI ) $itemDiv[0].innerText = itemDivRestoreText; if( !ret ) { alert("Error in Modification!"); return; } </pre>
Note:
If you like to have a number on every line then add this CSS rule in <head> section:
<style> /* Prettify: use this CSS to number every line */ li.L0, li.L1, li.L2, li.L3, li.L5, li.L6, li.L7, li.L8 { list-style-type: decimal !important; } </style>