module Middleman::Vegas::Highlighter

Public Class Methods

code_block_is_empty?(code) click to toggle source
# File lib/middleman-vegas/highlighter.rb, line 23
def self.code_block_is_empty?(code)
  code == "" || code == "</div>"
end
highlight(code, metadata={}) click to toggle source

The highlight method is called when code fences are used in RedCarpet and when the code helper is used.

@param code [String] the content found within the code block @param options [Hash] contains any additional rendering options provided

to the code helper methods, as code fences don't have a way to
provide additional parameters.

@return the HTML that will be rendered to the page

# File lib/middleman-vegas/highlighter.rb, line 17
def self.highlight(code, metadata={})
  return no_html if code_block_is_empty?(code.strip)
  metadata[:lang] = with_lang_aliases_considered(metadata[:lang])
  TableFormatter.new.render(code, metadata)
end
no_html() click to toggle source
# File lib/middleman-vegas/highlighter.rb, line 27
def self.no_html
  ""
end
with_lang_aliases_considered(lang) click to toggle source

When languages are provided they could be aliases for other languages or the way that they are presented. With a few languages we want to make sure that they are presented within the context of a console.

# File lib/middleman-vegas/highlighter.rb, line 34
def self.with_lang_aliases_considered(lang)
  case lang
  when 'cmd'
    'console?lang=powershell'
  when 'posh', 'powershell', 'shell', 'studio'
    "console?lang=#{lang}"
  when 'ps1'
    'powershell'
  else
    lang
  end
end