Skip to content

defunkt/mustache-syntax-highlighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mustache Syntax Highlighter

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">&quot;Hi world!&quot;</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">&quot;Hi Bobs!&quot;</span>
<span class="k">end</span>
</pre></div>

Note the Hi Bobs!

Available Lexers

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.

Dependencies

  • Pygments
  • Mustache 0.11.0

About

Syntax highlighting plugin for mustache.rb

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages