lib/yard/templates/helpers/html_helper.rb in yard-0.5.3 vs lib/yard/templates/helpers/html_helper.rb in yard-0.5.4

- old
+ new

@@ -21,10 +21,29 @@ # @param [String] text the URL # @return [String] the escaped URL def urlencode(text) CGI.escape(text.to_s) end + + # Returns the current character set. The default value can be overridden + # by setting the +LANG+ environment variable or by overriding this + # method. In Ruby 1.9 you can also modify this value by setting + # +Encoding.default_external+. + # + # @return [String] the current character set + def charset + return 'utf-8' unless RUBY19 || lang = ENV['LANG'] + if RUBY19 + lang = Encoding.default_external.name.downcase + else + lang = lang.downcase.split('.').last + end + case lang + when "ascii-8bit", "us-ascii", "ascii-7bit"; 'iso-8859-1' + else; lang + end + end # Turns text into HTML using +markup+ style formatting. # # @param [String] text the text to format # @param [Symbol] markup examples are +:markdown+, +:textile+, +:rdoc+. @@ -63,22 +82,22 @@ html end # @return [String] HTMLified text as a single line (paragraphs removed) def htmlify_line(*args) - htmlify(*args).gsub(/<\/?p>/, '') + "<div class='inline'>" + htmlify(*args) + "</div>" end # Fixes RDoc behaviour with ++ only supporting alphanumeric text. # # @todo Refactor into own SimpleMarkup subclass def fix_typewriter(text) text.gsub(/\+(?! )([^\n\+]{1,900})(?! )\+/) do type_text, pre_text, no_match = $1, $`, $& pre_match = pre_text.scan(%r(</?(?:pre|tt|code).*?>)) if pre_match.last.nil? || pre_match.last.include?('/') - '<tt>' + type_text + '</tt>' + '<tt>' + h(type_text) + '</tt>' else no_match end end end @@ -285,11 +304,11 @@ def signature(meth, link = true, show_extras = true, full_attr_name = true) meth = convert_method_to_overload(meth) type = signature_types(meth, link) scope = meth.scope == :class ? "+" : "-" - name = full_attr_name ? meth.name : meth.name.to_s.gsub(/=$/, '') + name = full_attr_name ? meth.name : meth.name.to_s.gsub(/^(\w+)=$/, '\1') blk = format_block(meth) args = !full_attr_name && meth.writer? ? "" : format_args(meth) extras = [] extras_text = '' if show_extras @@ -314,13 +333,13 @@ end end def html_syntax_highlight(source, type = :ruby) return "" unless source - return source if options[:no_highlight] + return h(source) if options[:no_highlight] # handle !!!LANG prefix to send to html_syntax_highlight_LANG - if source =~ /\A[ \t]*!!!(\w+)[ \t]*\r?\n/ + if source =~ /\A[ \t]*!!!([\w.+-]+)[ \t]*\r?\n/ type, source = $1, $' source = $' end meth = "html_syntax_highlight_#{type}"