module MiniSyntax::Highlighter::CommandLine

Public Class Methods

highlight(code) click to toggle source
# File lib/minisyntax/highlighter/command_line.rb, line 4
def self.highlight(code)
  code = '<kbd>' + code.gsub(/\n/, %Q(</kbd>\n<kbd>)) + '</kbd>'
  code.gsub! %r((\#.*?)$) do |comment|
    if comment =~ %r(</q>)
      comment
    else
      comment.gsub! %r(</?(b|i|em|var|code|kbd)>), ""
      %Q(<i>#{comment}</i>)
    end
  end
  code.gsub! %r(<kbd><i>), "<i>"
  code
end