Module: MiniSyntax::Highlighter::Bash
- Defined in:
- lib/minisyntax/highlighter/bash.rb
Class Method Summary collapse
Class Method Details
.highlight(code) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/minisyntax/highlighter/bash.rb', line 4 def self.highlight(code) code.gsub! /\$[a-z\-_]+/, "<var>\\0</var>" code.gsub! /("(.*?)"|'.*?')/ do |text| %Q(<q>#{text}</q>) end code.gsub! %r((\#.*?)$) do |comment| if comment.gsub(%r(<q>(.*?)</q>), "\\1") =~ %r(</q>) comment else comment.gsub! %r(</?(b|i|em|var|code)>), "" %Q(<i>#{comment}</i>) end end code end |