Commits

John Guidry committed fc954fa

Change nanoc to use pygments.rb instead of albino as this will be merged into the next version of nanoc.
Add external stylesheet for syntax coloring.
Style code blocks and remove unnecessary vertical rhythm adjustments.

  • Participants
  • Parent commits 7c766fc

Comments (0)

Files changed (8)

 
 # Dependencies for syntax colorizing filter
 gem 'nokogiri'
-gem 'pygmentize'
-gem 'albino'
+
+# Some issues seem to exist with latest pygments.rb
+# https://github.com/tmm1/pygments.rb/issues/10
+gem 'rubypython', '= 0.5.1'
+gem 'pygments.rb', '= 0.2.3'
 
 # 960gs plugin for Compass
 gem 'compass'
   specs:
     adsf (1.0.1)
       rack (>= 1.0.0)
-    albino (1.3.3)
-      posix-spawn (>= 0.3.6)
+    blankslate (2.1.2.4)
     chunky_png (1.2.5)
     compass (0.11.5)
       chunky_png (~> 1.2)
     compass-960-plugin (0.10.4)
       compass (>= 0.10.0)
     cri (2.0.2)
+    ffi (1.0.11)
     fssm (0.2.7)
     haml (3.1.4)
     mime-types (1.17.2)
     nanoc3 (3.2.3)
       cri (~> 2.0)
     nokogiri (1.5.0)
-    posix-spawn (0.3.6)
-    pygmentize (0.0.3)
+    pygments.rb (0.2.3)
+      rubypython (>= 0.5.1)
     rack (1.3.5)
+    rubypython (0.5.1)
+      blankslate (>= 2.1.2.3)
+      ffi (~> 1.0.7)
     sass (3.1.12)
 
 PLATFORMS
 
 DEPENDENCIES
   adsf
-  albino
   compass
   compass-960-plugin
   haml
   mime-types
   nanoc
   nokogiri
-  pygmentize
+  pygments.rb (= 0.2.3)
+  rubypython (= 0.5.1)

content/assets/css/monokai.css

+.syntax .hll { background-color: #49483e }
+.syntax .c { color: #75715e } /* Comment */
+.syntax .err { color: #960050; background-color: #1e0010 } /* Error */
+.syntax .k { color: #66d9ef } /* Keyword */
+.syntax .l { color: #ae81ff } /* Literal */
+.syntax .n { color: #f8f8f2 } /* Name */
+.syntax .o { color: #f92672 } /* Operator */
+.syntax .p { color: #f8f8f2 } /* Punctuation */
+.syntax .cm { color: #75715e } /* Comment.Multiline */
+.syntax .cp { color: #75715e } /* Comment.Preproc */
+.syntax .c1 { color: #75715e } /* Comment.Single */
+.syntax .cs { color: #75715e } /* Comment.Special */
+.syntax .ge { font-style: italic } /* Generic.Emph */
+.syntax .gs { font-weight: bold } /* Generic.Strong */
+.syntax .kc { color: #66d9ef } /* Keyword.Constant */
+.syntax .kd { color: #66d9ef } /* Keyword.Declaration */
+.syntax .kn { color: #f92672 } /* Keyword.Namespace */
+.syntax .kp { color: #66d9ef } /* Keyword.Pseudo */
+.syntax .kr { color: #66d9ef } /* Keyword.Reserved */
+.syntax .kt { color: #66d9ef } /* Keyword.Type */
+.syntax .ld { color: #e6db74 } /* Literal.Date */
+.syntax .m { color: #ae81ff } /* Literal.Number */
+.syntax .s { color: #e6db74 } /* Literal.String */
+.syntax .na { color: #a6e22e } /* Name.Attribute */
+.syntax .nb { color: #f8f8f2 } /* Name.Builtin */
+.syntax .nc { color: #a6e22e } /* Name.Class */
+.syntax .no { color: #66d9ef } /* Name.Constant */
+.syntax .nd { color: #a6e22e } /* Name.Decorator */
+.syntax .ni { color: #f8f8f2 } /* Name.Entity */
+.syntax .ne { color: #a6e22e } /* Name.Exception */
+.syntax .nf { color: #a6e22e } /* Name.Function */
+.syntax .nl { color: #f8f8f2 } /* Name.Label */
+.syntax .nn { color: #f8f8f2 } /* Name.Namespace */
+.syntax .nx { color: #a6e22e } /* Name.Other */
+.syntax .py { color: #f8f8f2 } /* Name.Property */
+.syntax .nt { color: #f92672 } /* Name.Tag */
+.syntax .nv { color: #f8f8f2 } /* Name.Variable */
+.syntax .ow { color: #f92672 } /* Operator.Word */
+.syntax .w { color: #f8f8f2 } /* Text.Whitespace */
+.syntax .mf { color: #ae81ff } /* Literal.Number.Float */
+.syntax .mh { color: #ae81ff } /* Literal.Number.Hex */
+.syntax .mi { color: #ae81ff } /* Literal.Number.Integer */
+.syntax .mo { color: #ae81ff } /* Literal.Number.Oct */
+.syntax .sb { color: #e6db74 } /* Literal.String.Backtick */
+.syntax .sc { color: #e6db74 } /* Literal.String.Char */
+.syntax .sd { color: #e6db74 } /* Literal.String.Doc */
+.syntax .s2 { color: #e6db74 } /* Literal.String.Double */
+.syntax .se { color: #ae81ff } /* Literal.String.Escape */
+.syntax .sh { color: #e6db74 } /* Literal.String.Heredoc */
+.syntax .si { color: #e6db74 } /* Literal.String.Interpol */
+.syntax .sx { color: #e6db74 } /* Literal.String.Other */
+.syntax .sr { color: #e6db74 } /* Literal.String.Regex */
+.syntax .s1 { color: #e6db74 } /* Literal.String.Single */
+.syntax .ss { color: #e6db74 } /* Literal.String.Symbol */
+.syntax .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
+.syntax .vc { color: #f8f8f2 } /* Name.Variable.Class */
+.syntax .vg { color: #f8f8f2 } /* Name.Variable.Global */
+.syntax .vi { color: #f8f8f2 } /* Name.Variable.Instance */
+.syntax .il { color: #ae81ff } /* Literal.Number.Integer.Long */

content/assets/css/stylesheet.scss

   @include grid-container;
 }
 
+.syntax {
+  @include rhythm(0.5,0,0,0.5);
+  @include rhythm-borders(1px, 0.5, 13px, dotted);
+  background: $bg-color;
+  color: #f8f8f2;
+  border-color: #f8f8f2;
+}
+.syntax code {
+  @include adjust-font-size-to(13px);
+  font-family: 'Inconsolata', sans-serif;
+}
+
 .entry {
   @include clearfix;
   @include rhythm(1,0,0,1);
 
 .post-title {
   @include adjust-font-size-to(20px);
-  @include rhythm;
   font-weight: 600;
   font-style: italic;
   text-align: right;
 }
 .post-details {
   @include adjust-font-size-to(12px);
-  @include rhythm;
   text-align: right;
 }
 
 
   p {  
     @include grid(8); 
-    @include rhythm;
     @include adjust-font-size-to(14px);
   }
   
   ul {
     @include grid(7);
     @include grid-push(1);
-    @include rhythm;
     @include adjust-font-size-to(14px);
   }
 
-  pre {
+  .syntax {
     @include grid(4);
     @include grid-push(2);
-    @include rhythm;
-  }
-
-  code {
-    @include adjust-font-size-to(13px);
-    font-family: 'Inconsolata', sans-serif;
   }
 }
 
   @include grid(8);
   @include grid-push(2);
   @include adjust-font-size-to(32px);
-  @include rhythm;
   font-weight: 600;
   font-style: italic;
   text-align: center; 
   @include grid(6);
   @include grid-push(3);
   @include adjust-font-size-to(14px);
-  @include rhythm;
   text-align: center; 
 }
 
 
   p { 
     @include grid(12);
-    @include rhythm;
     @include adjust-font-size-to(14px);
   }
   
   ul {
     @include grid(8);
     @include grid-push(2);
-    @include rhythm;
     @include adjust-font-size-to(14px);
   }
 
-  pre {
+  .syntax {
     @include grid(6);
     @include grid-push(3);
-    @include rhythm;
-  }
-
-  code {
-    @include adjust-font-size-to(13px);
-    font-family: 'Inconsolata', sans-serif;
   }
 }
 

content/posts/first_pot.haml

 %p
   Hi, I'm the very first post generated by Nanoc.
 
-%pre
+%pre.syntax
   %code{:class => 'language-ruby'}
     :preserve
       def foo
 %p
   Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
 
-%pre
+%pre.syntax
   %code{:class => 'language-bash'}
     :preserve
       cd ~/

layouts/default.haml

     %title a novel spin 
     %link{:rel =>'stylesheet', 
           :type =>'text/css', 
+          :href => '/assets/css/monokai.css',
+          :media => 'screen'}
+    %link{:rel =>'stylesheet', 
+          :type =>'text/css', 
           :href => '/assets/css/stylesheet.css',
           :media => 'screen'}
     %link{:rel => 'stylesheet',

lib/albino.rb

-module Nanoc3::Filters
-  class ColorizeSyntax
-    def highlight(code, language, params={})
-      require 'albino'
-      @syntaxer = Albino.new(code, language)
-      highlighted_code = @syntaxer.colorize({:O=>"noclasses=true"})
-            
-      doc = Nokogiri::HTML.fragment(highlighted_code)
-      return doc.xpath('./div[@class="highlight"]/pre').inner_html
-    end
-  end
-end
+module Nanoc3::Filters
+  class ColorizeSyntax
+    def highlight(code, language, params={})
+      require 'pygments'
+
+      # Pygments.rb is the future, not Albino
+      # https://github.com/ddfreyne/nanoc/issues/76 
+      # However there are still odd problems
+      # https://github.com/tmm1/pygments.rb/issues/10
+      RubyPython.configure :python_exe => 'python2.7'
+      highlighted_code = Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'})
+            
+      doc = Nokogiri::HTML.fragment(highlighted_code)
+      doc.xpath('./div[@class="highlight"]/pre').inner_html
+    end
+  end
+end