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 << "" if [:tstring_beg, :regexp_beg].include?(s[0]) case s.first when :nl, :ignored_nl, :sp output << h(s.last) when :ident output << "#{h(s.last)}" else output << "#{h(s.last)}" end output << "" if [:tstring_end, :regexp_end].include?(s[0]) end output rescue Parser::ParserSyntaxError h(source) end end end end end