class Middleman::Vegas::SyntaxExtension
Public Instance Methods
after_configuration()
click to toggle source
# File lib/middleman-vegas/extension.rb, line 14 def after_configuration Middleman::Vegas::Highlighter.options = options if app.config[:markdown_engine] == :redcarpet require 'middleman-core/renderers/redcarpet' Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, RedcarpetCodeRenderer end end
code(language=nil, options={}, &block)
click to toggle source
Output highlighted code. Use like:
<% code('ruby', :line_numbers => true, :start_line => 7) do %> my code <% end %>
To produce the following structure:
<pre class="highlight ruby"> <code>#{your code}</code> </pre>
If no language is provided, then the language name is `plaintext`.
@param [String] language that the Rouge lexer should use @param [Hash] Options to pass to the Rouge formatter & lexer, overriding global options set by :highlighter_options.
# File lib/middleman-vegas/extension.rb, line 39 def code(language=nil, options={}, &block) raise 'The code helper requires a block to be provided.' unless block_given? options[:lang] = language.to_s options[:marks] ||= [] # Save current buffer for later @_out_buf, _buf_was = "", @_out_buf begin content = capture_html(&block) ensure # Reset stored buffer @_out_buf = _buf_was end content = content.encode(Encoding::UTF_8) concat_content Highlighter.highlight(content, options).html_safe end