diff options
-rw-r--r-- | lib/coderay/encoders/html.rb | 9 | ||||
-rw-r--r-- | lib/coderay/encoders/html/output.rb | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index f7f99f7..4e47396 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -41,6 +41,12 @@ module Encoders # # Default: nil # + # === :title + # + # The title of the HTML page (works only when :wrap is set to :page.) + # + # Default: 'CodeRay output' + # # === :line_numbers # Include line numbers in :table, :inline, :list or nil (no line numbers) # @@ -86,8 +92,8 @@ module Encoders :css => :class, :style => :cycnus, - :wrap => nil, + :title => 'CodeRay output', :line_numbers => nil, :line_number_start => 1, @@ -227,6 +233,7 @@ module Encoders @out.css = @css @out.numerize! options[:line_numbers], options @out.wrap! options[:wrap] + @out.apply_title! options[:title] super end diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 32ee5be..28574a5 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -86,6 +86,11 @@ module Encoders Template.wrap! self, template, 'CONTENT' self end + + def apply_title! title + self.sub!(/(<title>)(<\/title>)/) { $1 + title + $2 } + self + end def wrap! element, *args return self if not element or element == wrapped_in @@ -100,6 +105,10 @@ module Encoders wrap! :div if wrapped_in? nil raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? :div wrap_in! Output.page_template_for_css(@css) + if args.first.is_a?(Hash) && title = args.first[:title] + apply_title! title + end + self when nil return self else @@ -177,7 +186,7 @@ module Encoders <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>CodeRay Output</title> + <title></title> <style type="text/css"> <%CSS%> </style> |