Module: YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- Defined in:
- lib/yard-go/extensions.rb
Constant Summary collapse
- MATCHES =
{ "hljs-keyword" => %r{\b(?:break|default|func|interface|select|case|defer|go|map|struct|chan|else|goto|package|switch|const|fallthrough|if|range|type|continue|for|import|return|var)\b}, "hljs-constant" => %r{\b(nil|false|true|error|string|int64|int|int32|float|float32|float64|bool)\b}, "hljs-string" => %r{"(?:[^\\"]|\\.)*"|`.+?`}, "hljs-comment" => %r{\/\/.+}, }
Instance Method Summary collapse
Instance Method Details
#html_syntax_highlight_go(source) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yard-go/extensions.rb', line 47 def html_syntax_highlight_go(source) s = StringScanner.new(source, true) highlighted = "" until s.eos? found = false MATCHES.each do |klass, re| if s.scan(re) found = true highlighted << "<span class=\"#{klass}\">#{s[0]}</span>" end end highlighted << s.getch unless found end '<div class="hljs">' + highlighted + '</div>' end |