diff options
Diffstat (limited to '')
-rw-r--r-- | source/javascripts/syntax-helper.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/javascripts/syntax-helper.js b/source/javascripts/syntax-helper.js new file mode 100644 index 00000000..e1a6889b --- /dev/null +++ b/source/javascripts/syntax-helper.js @@ -0,0 +1,30 @@ +function addDivLines(){ + $('div.highlight pre code').each(function(el){ + var content = bonzo(el).html(); + var lines = content.split('\n'); + var count = lines.length; + bonzo(lines).each(function(line, index){ + if(line == '') line = ' '; + lines[index] = '<div class="line">' + line + '</div>'; + }); + $(el).html(lines.join('')); + }); +} +function preToTable(){ + $('div.highlight').each(function(code){ + var tableStart = '<table cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter">'; + var lineNumbers = '<pre class="line-numbers">'; + var tableMiddle = '</pre></td><td class="code" width="100%">'; + var tableEnd = '</td></tr></tbody></table>'; + var count = $('div.line', code).length; + for (i=1;i<=count; i++){ + lineNumbers += '<span class="line">'+i+'</span>\n'; + } + table = tableStart + lineNumbers + tableMiddle + '<pre>'+$('pre', code).html()+'</pre>' + tableEnd; + $(code).html(table); + }); +} +$.domReady(function () { + addDivLines(); + preToTable(); +}); |