File tree Expand file tree Collapse file tree
.themes/classic/source/javascripts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,8 +48,7 @@ function testFeatures() {
4848
4949function addCodeLineNumbers ( ) {
5050 if ( navigator . appName == 'Microsoft Internet Explorer' ) { return }
51- $ ( 'div.highlight pre code' ) . each ( function ( el ) { addDivLines ( el ) ; } ) ;
52- $ ( 'div.highlight, div.gist-highlight' ) . each ( function ( code ) {
51+ $ ( 'div.gist-highlight' ) . each ( function ( code ) {
5352 var tableStart = '<table cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter">' ;
5453 var lineNumbers = '<pre class="line-numbers">' ;
5554 var tableMiddle = '</pre></td><td class="code" width="100%">' ;
@@ -62,16 +61,6 @@ function addCodeLineNumbers(){
6261 $ ( code ) . html ( table ) ;
6362 } ) ;
6463}
65- function addDivLines ( el ) {
66- var content = $ ( el ) . html ( ) ;
67- var lines = content . replace ( / \s * $ / g, '' ) . split ( / \n / ) ;
68- var count = lines . length ;
69- $ ( lines ) . each ( function ( line , index ) {
70- if ( line == '' ) line = ' ' ;
71- lines [ index ] = '<div class="line">' + line + '</div>' ;
72- } ) ;
73- $ ( el ) . html ( lines . join ( '' ) ) ;
74- }
7564
7665function flashVideoFallback ( ) {
7766 var flashplayerlocation = "/assets/jwplayer/player.swf" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ gem 'rake'
44gem 'rack'
55gem 'jekyll'
66gem 'rdiscount'
7+ gem 'pygments.rb'
78gem 'RedCloth'
89gem 'haml' , '>= 3.1'
910gem 'compass' , '>= 0.11'
Original file line number Diff line number Diff line change 44 RedCloth (4.2.7 )
55 albino (1.3.3 )
66 posix-spawn (>= 0.3.6 )
7+ blankslate (2.1.2.4 )
78 chunky_png (1.2.0 )
89 classifier (1.3.3 )
910 fast-stemmer (>= 1.0.0 )
1314 sass (~> 3.1 )
1415 directory_watcher (1.4.0 )
1516 fast-stemmer (1.0.0 )
17+ ffi (1.0.9 )
1618 fssm (0.2.7 )
1719 haml (3.1.2 )
1820 jekyll (0.11.0 )
2729 maruku (0.6.0 )
2830 syntax (>= 1.0.0 )
2931 posix-spawn (0.3.6 )
30- rack (1.3.1 )
32+ pygments.rb (0.1.2 )
33+ rubypython (>= 0.5.1 )
34+ rack (1.3.2 )
3135 rake (0.9.2 )
3236 rb-fsevent (0.4.1 )
3337 rdiscount (1.6.8 )
3438 rubypants (0.2.0 )
35- sass (3.1.4 )
39+ rubypython (0.5.1 )
40+ blankslate (>= 2.1.2.3 )
41+ ffi (~> 1.0.7 )
42+ sass (3.1.5 )
3643 syntax (1.0.0 )
3744
3845PLATFORMS
@@ -43,6 +50,7 @@ DEPENDENCIES
4350 compass (>= 0.11 )
4451 haml (>= 3.1 )
4552 jekyll
53+ pygments.rb
4654 rack
4755 rake
4856 rb-fsevent
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ plugins: plugins
2828code_dir : downloads/code
2929category_dir : blog/categories
3030markdown : rdiscount
31- pygments : true
31+ pygments : false
3232
3333paginate : 10 # Posts per page on the blog index
3434recent_posts : 5 # Posts in the sidebar Recent Posts section
Original file line number Diff line number Diff line change 4141# <pre><code><sarcasm> Ooooh, sarcasm... How original!</sarcasm></code></pre>
4242# </figure>
4343#
44+ require './plugins/pygments_code'
45+
4446module Jekyll
4547
4648 class CodeBlock < Liquid ::Block
49+ include HighlightCode
4750 CaptionUrlTitle = /(\S [\S \s ]*)\s +(https?:\/ \/ )(\S +)\s +(.+)/i
4851 CaptionUrl = /(\S [\S \s ]*)\s +(https?:\/ \/ )(\S +)/i
4952 Caption = /(\S [\S \s ]*)/
@@ -75,7 +78,7 @@ def render(context)
7578 if @filetype
7679 @filetype = 'objc' if @filetype == 'm'
7780 @filetype = 'perl' if @filetype == 'pl'
78- source += "{% highlight #{ @filetype } %} \n " + code + " \n {% endhighlight % }</figure></div>"
81+ source += " #{ highlight ( code , @filetype ) } </figure></div>"
7982 else
8083 source += "<pre><code>" + code . lstrip . rstrip . gsub ( /</ , '<' ) + "</code></pre></figure></div>"
8184 end
Original file line number Diff line number Diff line change 2020# will output a figcaption with the title: Example 2 (test.js)
2121#
2222
23+ require './plugins/pygments_code'
2324require 'pathname'
2425
2526module Jekyll
2627
2728 class IncludeCodeTag < Liquid ::Tag
29+ include HighlightCode
2830 def initialize ( tag_name , markup , tokens )
2931 @title = nil
3032 @file = nil
@@ -50,13 +52,13 @@ def render(context)
5052
5153 Dir . chdir ( code_path ) do
5254 code = file . read
53- @filetype = file . extname
55+ @filetype = file . extname . sub ( '.' , '' )
5456 @filetype = 'objc' if @filetype == 'm'
5557 @filetype = 'perl' if @filetype == 'pl'
5658 title = @title ? "#{ @title } (#{ file . basename } )" : file . basename
5759 url = "#{ context . registers [ :site ] . config [ 'url' ] } /#{ code_dir } /#{ @file } "
5860 source = "<div><figure role=code><figcaption><span>#{ title } </span> <a href='#{ url } '>download</a></figcaption>\n "
59- source += "{% highlight #{ @filetype } %} \n " + code + " \n {% endhighlight % }</figure></div>"
61+ source += " #{ highlight ( code , @filetype ) } </figure></div>"
6062 partial = Liquid ::Template . parse ( source )
6163 context . stack do
6264 partial . render ( context )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ require 'pygments'
2+ require 'fileutils'
3+ require 'digest/md5'
4+
5+ PYGMENTS_CACHE_DIR = File . expand_path ( '../../_code_cache' , __FILE__ )
6+ FileUtils . mkdir_p ( PYGMENTS_CACHE_DIR )
7+
8+ module HighlightCode
9+ def highlight ( str , lang )
10+ str = pygments ( str , lang ) . match ( /<pre>(.+)<\/ pre>/m ) [ 1 ] . to_s . gsub ( /\s *$/ , '' ) #strip out divs <div class="highlight">
11+ table = '<div class="highlight"><table cellpadding="0" cellspacing="0"><tr><td class="gutter"><pre class="line-numbers">'
12+ code = ''
13+ str . lines . each_with_index do |line , index |
14+ table += "<span class='line'>#{ index +1 } </span>\n "
15+ code += "<div class='line'>#{ line } </div>"
16+ end
17+ table += "</pre></td><td class='code' width='100%'><pre><code class='#{ lang } '>#{ code } </code></pre></td></tr></table></div>"
18+ end
19+
20+ def pygments ( code , lang )
21+ if defined? ( PYGMENTS_CACHE_DIR )
22+ path = File . join ( PYGMENTS_CACHE_DIR , "#{ lang } -#{ Digest ::MD5 . hexdigest ( code ) } .html" )
23+ if File . exist? ( path )
24+ highlighted_code = File . read ( path )
25+ else
26+ highlighted_code = Pygments . highlight ( code , :lexer => lang , :formatter => 'html' )
27+ File . open ( path , 'w' ) { |f | f . print ( highlighted_code ) }
28+ end
29+ else
30+ highlighted_code = Pygments . highlight ( code , :lexer => lang , :formatter => 'html' )
31+ end
32+ highlighted_code
33+ end
34+ end
You can’t perform that action at this time.
0 commit comments