Module: Middleman::Vegas::Highlighter

Defined in:
lib/middleman-vegas/highlighter.rb

Class Method Summary collapse

Class Method Details

.code_block_is_empty?(code) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/middleman-vegas/highlighter.rb', line 23

def self.code_block_is_empty?(code)
  code == "" || code == "</div>"
end

.highlight(code, metadata = {}) ⇒ Object

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

Parameters:

  • code (String)

    the content found within the code block

  • 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.

Returns:

  • the HTML that will be rendered to the page



17
18
19
20
21
# File 'lib/middleman-vegas/highlighter.rb', line 17

def self.highlight(code, ={})
  return no_html if code_block_is_empty?(code.strip)
  [:lang] = with_lang_aliases_considered([:lang])
  TableFormatter.new.render(code, )
end

.no_htmlObject



27
28
29
# File 'lib/middleman-vegas/highlighter.rb', line 27

def self.no_html
  ""
end

.with_lang_aliases_considered(lang) ⇒ Object

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.



34
35
36
37
38
39
40
41
42
43
44
45
# 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