Sha256: 77e5c8a9161da8fe5c7b41e5710e970d434fd083ac067efa93277dd71db4c4f2

Contents?: true

Size: 884 Bytes

Versions: 10

Compression:

Stored size: 884 Bytes

Contents

module YARD
  module Templates
    module Helpers
      module HtmlSyntaxHighlightHelper
        def html_syntax_highlight_ruby(source)
          tokenlist = Parser::Ruby::RubyParser.parse(source, "(syntax_highlight)").tokens
          output = ""
          tokenlist.each do |s|
            output << "<span class='tstring'>" if [:tstring_beg, :regexp_beg].include?(s[0])
            case s.first
            when :nl, :ignored_nl, :sp
              output << h(s.last)
            when :ident
              output << "<span class='id #{h(s.last)}'>#{h(s.last)}</span>"
            else
              output << "<span class='#{s.first}'>#{h(s.last)}</span>"
            end
            output << "</span>" if [:tstring_end, :regexp_end].include?(s[0])
          end
          output
        rescue Parser::ParserSyntaxError
          h(source)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
yard-0.5.8 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.7 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.6 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.5 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.4 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.3 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.2 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.1p1 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.1 lib/yard/templates/helpers/html_syntax_highlight_helper.rb
yard-0.5.0 lib/yard/templates/helpers/html_syntax_highlight_helper.rb