diff options
-rw-r--r-- | Changes.textile | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/html.rb | 38 | ||||
-rw-r--r-- | lib/coderay/encoders/html/css.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/html/numbering.rb | 10 | ||||
-rwxr-xr-x | lib/coderay/token_kinds.rb | 12 |
5 files changed, 25 insertions, 39 deletions
diff --git a/Changes.textile b/Changes.textile index c1de27f..8a53546 100644 --- a/Changes.textile +++ b/Changes.textile @@ -44,6 +44,8 @@ See "#122":http://redmine.rubychan.de/issues/122. * *REMOVED* token kinds @:attribute_name_fat@, @:attribute_value_fat@, @:operator_fat@, @:tag_fat@, @:xml_text@, @:open@, and @:close@. * *ADDED* token kinds @:filename@, @:namespace@, and @:eyecatcher@. * *CHANGED*: Don't raise error for unknown token kinds unless in @$CODERAY_DEBUG@ mode. +* *CHANGED* the value for a token kind that is not highlighted from + @:NO_HIGHLIGHT@ to @false@. h3. @Encoders::CommentFilter@ diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 9d1671d..bd48a72 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -185,45 +185,29 @@ module Encoders raise ArgumentError, "Unknown value %p for :hint; \ expected :info, :debug, false, or nil." % hint end - + + css_classes = Tokens::AbbreviationForKind case options[:css] when :class @css_style = Hash.new do |h, k| kind = k.is_a?(Symbol) ? k : k.first - c = Tokens::AbbreviationForKind[kind] h[k.is_a?(Symbol) ? k : k.dup] = - if c != :NO_HIGHLIGHT or (hint && kind != :space) - if hint - title = HTML.token_path_to_hint hint, k - end - if c == :NO_HIGHLIGHT - '<span%s>' % [title] - else - '<span%s class="%s">' % [title, c] - end + if kind != :space && (hint || css_classes[kind]) + title = HTML.token_path_to_hint hint, k if hint + css_class = css_classes[k] + "<span#{title}#{" class=\"#{css_class}\"" if css_class}>" end end when :style @css_style = Hash.new do |h, k| - if k.is_a?(Symbol) - kind = k - ks = [kind] - else - kind = k.first - ks = k - end - classes = ks.map { |c| Tokens::AbbreviationForKind[c] } + kind = k.is_a?(Symbol) ? k : k.first h[k.is_a?(Symbol) ? k : k.dup] = - if classes.first != :NO_HIGHLIGHT or (hint && kind != :space) - if hint - title = HTML.token_path_to_hint hint, k - end - style = @css[*classes] - if style - '<span%s style="%s">' % [title, style] - end + if kind != :space && (hint || css_classes[kind]) + title = HTML.token_path_to_hint hint, k if hint + style = @css.get_style Array(k).map { |c| css_classes[c] } + "<span#{title}#{" style=\"#{style}\"" if style}>" end end diff --git a/lib/coderay/encoders/html/css.rb b/lib/coderay/encoders/html/css.rb index 05e4fa4..10e89fc 100644 --- a/lib/coderay/encoders/html/css.rb +++ b/lib/coderay/encoders/html/css.rb @@ -20,7 +20,7 @@ module Encoders parse style::TOKEN_COLORS end - def [] *styles + def get_style styles cl = @classes[styles.first] return '' unless cl style = '' diff --git a/lib/coderay/encoders/html/numbering.rb b/lib/coderay/encoders/html/numbering.rb index 3a7edce..ec6d569 100644 --- a/lib/coderay/encoders/html/numbering.rb +++ b/lib/coderay/encoders/html/numbering.rb @@ -26,7 +26,7 @@ module Encoders "<a href=\"##{anchor}\" name=\"#{anchor}\">#{line}</a>" end else - proc { |line| line.to_s } + proc { |line| line.to_s } # :to_s.to_proc in Ruby 1.8.7+ end bold_every = options[:bold_every] @@ -80,11 +80,11 @@ module Encoders end when :table - line_numbers = (start ... start + line_count).to_a.map(&bolding).join("\n") + line_numbers = (start ... start + line_count).map(&bolding).join("\n") line_numbers << "\n" - line_numbers_table_template = TABLE.apply('LINE_NUMBERS', line_numbers) - gsub!(/<\/div>\n/) { '</div>' } + + gsub!(/<\/div>\n/, '</div>') wrap_in! line_numbers_table_template @wrapped_in = :div @@ -101,7 +101,7 @@ module Encoders def line_count line_count = count("\n") - position_of_last_newline = rindex(?\n) + position_of_last_newline = rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n) if position_of_last_newline after_last_newline = self[position_of_last_newline + 1 .. -1] ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/] diff --git a/lib/coderay/token_kinds.rb b/lib/coderay/token_kinds.rb index e9e60cf..756f75e 100755 --- a/lib/coderay/token_kinds.rb +++ b/lib/coderay/token_kinds.rb @@ -4,7 +4,7 @@ module CodeRay if $CODERAY_DEBUG raise 'Undefined Token kind: %p' % [k] # :nodoc: else - :NO_HIGHLIGHT + false end end AbbreviationForKind.update with = { # :nodoc: @@ -74,11 +74,11 @@ module CodeRay :eyecatcher => 'eye', - :ident => :NO_HIGHLIGHT, # 'id' - #:operator => 'op', - :operator => :NO_HIGHLIGHT, # 'op' - :space => :NO_HIGHLIGHT, # 'sp' - :plain => :NO_HIGHLIGHT, + :ident => false, # 'id' + :operator => false, # 'op' + + :space => false, # 'sp' + :plain => false, } AbbreviationForKind[:method] = AbbreviationForKind[:function] AbbreviationForKind[:nesting_delimiter] = AbbreviationForKind[:delimiter] |