<h2>Code</h2> <p>Inline <code>code</code></p> <p>Indented code</p> <pre><code>// Some comments line 1 of code line 2 of code line 3 of code </code></pre> <p>Block code “fences”</p> <preclass="hljs"><code>Sample text here... </code></pre> <p>Syntax highlighting</p> <preclass="hljs language-js"><code><spanclass="hljs-keyword">var</span> foo = <spanclass="hljs-function"><spanclass="hljs-keyword">function</span> (<spanclass="hljs-params">bar</span>) </span>{ <spanclass="hljs-keyword">return</span> bar++; };
functionhighlightUtil(str, options) { if (typeof str !== 'string') thrownewTypeError('str must be a string!'); options = options || {};
var gutter = options.hasOwnProperty('gutter') ? options.gutter : true; var wrap = options.hasOwnProperty('wrap') ? options.wrap : true; var firstLine = options.hasOwnProperty('firstLine') ? +options.firstLine : 1; var caption = options.caption; var mark = options.hasOwnProperty('mark') ? options.mark : []; var tab = options.tab; var data = highlight(str, options);
if (!wrap) return data.value;
var lines = data.value.split('\n'); var numbers = ''; var content = ''; var result = ''; var line;
for (var i = 0, len = lines.length; i < len; i++) { line = lines[i]; if (tab) line = replaceTabs(line, tab); numbers += '<div class="line">' + (firstLine + i) + '</div>'; content += '<div class="line'; content += (mark.indexOf(firstLine + i) !== -1) ? ' marked' : ''; content += '">' + line + '</div>'; }
functionbacktickCodeBlock(data) { var config = this.config.highlight || {}; if (!config.enable) return;
data.content = data.content.replace(rBacktick, function() { var start = arguments[1]; var end = arguments[5]; var args = arguments[3]; var content = arguments[4];