A plugin for mustache.rb that lets you syntax highlight blocks of code using sections.
Essentially a demo of Mustache's "Higher Order Sections" functionality.
For example, this template:
I wrote some great code!
{{# highlight_ruby}}
def hello
puts "Hi world!"
end
{{/ highlight_ruby}}
Sweet. It works.
Will produce this text:
I wrote some great code!
<div class="highlight"><pre><span class="k">def</span> <span class="nf">hello</span>
<span class="nb">puts</span> <span class="s2">"Hi world!"</span>
<span class="k">end</span>
</pre></div>
Sweet. It works.
Just include the Pygments css file and you're ready to roll.
If you want to use this in a Mustache
view you can include it in
your subclass:
class BlogPost < Mustache
include Mustache::Plugins::SyntaxHighlighter
def name
"Bobs"
end
end
The code you want to highlight will be rendered before being passed to the highlighter.
So this:
{{# highlight_ruby}}
def hello
puts "Hi {{name}}!"
end
{{/ highlight_ruby}}
Becomes this:
<div class="highlight"><pre><span class="k">def</span> <span class="nf">hello</span>
<span class="nb">puts</span> <span class="s2">"Hi Bobs!"</span>
<span class="k">end</span>
</pre></div>
Note the Hi Bobs!
This is currently only a demo, so we've hardcoded a small number of lexers:
- ruby
- js
- python
- scheme
Use {{# highlight_scheme}} code {{/ highlight_scheme}}
, for example,
to activate one of the lexers.
To get a complete list run rake lexers
in the root of this project.
- Pygments
- Mustache 0.11.0