Module: Middleman::Vegas::Highlighter
- Defined in:
- lib/middleman-vegas/highlighter.rb
Class Method Summary collapse
- .code_block_is_empty?(code) ⇒ Boolean
-
.highlight(code, metadata = {}) ⇒ Object
The highlight method is called when code fences are used in RedCarpet and when the code helper is used.
- .no_html ⇒ Object
-
.with_lang_aliases_considered(lang) ⇒ Object
When languages are provided they could be aliases for other languages or the way that they are presented.
Class Method Details
.code_block_is_empty?(code) ⇒ 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.
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_html ⇒ Object
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 |