From 7371093d78689728c1bf8326987c24f73864edb2 Mon Sep 17 00:00:00 2001 From: murphy Date: Fri, 4 Nov 2005 00:16:58 +0000 Subject: HTML highlighting: html_css.rb: Bugfixes CSS style scanning went for wrong range moved some styles into the right place html_output.rb: numerization excluded templates renamed new LIST template html_numerization.rb (new): new :line_numbers style :list (beta) Benchmarking: Split Options into lines :list style for testing --- lib/coderay/encoders/helpers/html_output.rb | 86 +++-------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) (limited to 'lib/coderay/encoders/helpers/html_output.rb') diff --git a/lib/coderay/encoders/helpers/html_output.rb b/lib/coderay/encoders/helpers/html_output.rb index c6012f7..f17965d 100644 --- a/lib/coderay/encoders/helpers/html_output.rb +++ b/lib/coderay/encoders/helpers/html_output.rb @@ -13,6 +13,8 @@ module CodeRay # TODO: more doc. module Output + require 'coderay/encoders/helpers/html_numerization.rb' + attr_accessor :wrapped_in class << self @@ -104,82 +106,6 @@ module CodeRay clone.wrap!(*args) end - NUMERIZABLE_WRAPPINGS = { - :table => [:div, :page], - :inline => :all, - nil => :all - } - - def numerize! mode = :table, options = {} - return self unless mode - - options = DEFAULT_OPTIONS.merge options - - start = options[:line_number_start] - unless start.is_a? Integer - raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start - end - - allowed_wrappings = NUMERIZABLE_WRAPPINGS[mode] - unless allowed_wrappings == :all or allowed_wrappings.include? options[:wrap] - raise ArgumentError, "Can't numerize, :wrap must be in %p, but is %p" % [NUMERIZABLE_WRAPPINGS, options[:wrap]] - end - - bold_every = options[:bold_every] - bolding = - if bold_every == :no_bolding or bold_every == 0 - proc { |line| line.to_s } - elsif bold_every.is_a? Integer - proc do |line| - if line % bold_every == 0 - "#{line}" # every bold_every-th number in bold - else - line.to_s - end - end - else - raise ArgumentError, "Invalid value %p for :bolding; :no_bolding or Integer expected." % bolding - end - - line_count = count("\n") - line_count += 1 if self[-1] != ?\n - - case mode - when :inline - max_width = (start + line_count).to_s.size - line = start - gsub!(/^/) do - line_number = bolding.call line - line += 1 - "#{ line_number.rjust(max_width) } " - end - #wrap! :div - - when :table - # This is really ugly. - # Because even monospace fonts seem to have different heights when bold, - # I make the newline bold, both in the code and the line numbers. - # FIXME Still not working perfect for Mr. Internet Exploder - line_numbers = (start ... start + line_count).to_a.map(&bolding).join("\n") - line_numbers << "\n" # also for Mr. MS Internet Exploder :-/ - line_numbers.gsub!(/\n/) { "\n" } - - line_numbers_tpl = DIV_TABLE.apply('LINE_NUMBERS', line_numbers) - gsub!(/\n/) { "\n" } - wrap_in! line_numbers_tpl - @wrapped_in = :div - - else - raise ArgumentError, "Unknown value %p for mode: :inline or :table expected" % mode - end - - self - end - - def numerize *args - clone.numerize!(*args) - end - def stylesheet in_tag = false Output.stylesheet in_tag end @@ -224,14 +150,18 @@ module CodeRay DIV - DIV_TABLE = <<-`DIV_TABLE` + TABLE = <<-`TABLE`
<%LINE_NUMBERS%>
<%CONTENT%>
- DIV_TABLE + TABLE # title="double click to expand" + LIST = <<-`LIST` +
    <%CONTENT%>
+ LIST + PAGE = <<-`PAGE` -- cgit v1.2.1