HTML Encoder
This is CodeRay’s most important highlighter: It provides save, fast XHTML generation and CSS support.
Usage
require 'coderay'
puts CodeRay.scan('Some /code/', :ruby).html #-> a HTML page
puts CodeRay.scan('Some /code/', :ruby).html(:wrap => :span) #-> <span class="CodeRay"><span class="co">Some</span> /code/</span>
puts CodeRay.scan('Some /code/', :ruby).span #-> the same
puts CodeRay.scan('Some code', :ruby).html(
:wrap => nil,
:line_numbers => :inline,
:css => :style
)
#-> <span class="no">1</span> <span style="color:#036; font-weight:bold;">Some</span> code
Options
:tab_width
Convert \t characters to n spaces (a number.) Default: 8
:css
How to include the styles; can be :class or :style.
Default: :class
:wrap
Wrap in :page, :div, :span or nil.
You can also use Encoders::Div and Encoders::Span.
Default: nil
:line_numbers
Include line numbers in :table, :inline, :list or nil (no line numbers)
Default: nil
:line_number_start
Where to start with line number counting.
Default: 1
:bold_every
Make every n-th number appear bold.
Default: 10
:hint
Include some information into the output using the title attribute. Can be :info (show token type on mouse-over), :info_long (with full path) or :debug (via inspect).
Default: false
Class CodeRay::Encoders::HTML::CSS
| FILE_EXTENSION | = | 'html' |
| DEFAULT_OPTIONS | = | { :tab_width => 8, :level => :xhtml, :css => :class, :style => :cycnus, :wrap => nil, :line_numbers => nil, :line_number_start => 1, :bold_every => 10, :hint => false, } |
| HTML_ESCAPE | = | { #:nodoc: '&' => '&', '"' => '"', '>' => '>', '<' => '<', } |
| HTML_ESCAPE_PATTERN | = | /[\t"&><\0-\x8\xB-\x1f]/ |
ansi_chars = Array(0x7f..0xff) ansi_chars.each { |i| HTML_ESCAPE = ’&#%d;’ % i }
\x9 (\t) and \xA (\n) not included HTML_ESCAPE_PATTERN = /[\t&"><\0-\x8\xB-\x1f\x7f-\xff]/ |
||
| TOKEN_KIND_TO_INFO | = | Hash.new { |h, kind| h[kind] = case kind |
| ClassOfKind | = | { :attribute_name => 'an', :attribute_name_fat => 'af', :attribute_value => 'av', :attribute_value_fat => 'aw', :bin => 'bi', :char => 'ch', :class => 'cl', :class_variable => 'cv', :color => 'cr', :comment => 'c', :constant => 'co', :content => 'k', :definition => 'df', :delimiter => 'dl', :directive => 'di', :doc => 'do', :doc_string => 'ds', :error => 'er', :escape => 'e', :exception => 'ex', :float => 'fl', :function => 'fu', :global_variable => 'gv', :hex => 'hx', :include => 'ic', :inline => 'il', :instance_variable => 'iv', :integer => 'i', :interpreted => 'in', :label => 'la', :local_variable => 'lv', :modifier => 'mod', :oct => 'oc', :operator_name => 'on', :pre_constant => 'pc', :pre_type => 'pt', :predefined => 'pd', :preprocessor => 'pp', :regexp => 'rx', :reserved => 'r', :shell => 'sh', :string => 's', :symbol => 'sy', :tag => 'ta', :tag_fat => 'tf', :tag_special => 'ts', :type => 'ty', :variable => 'v', :xml_text => 'xt', :ident => :NO_HIGHLIGHT, # 'id' #:operator => 'op', :operator => :NO_HIGHLIGHT, # 'op' :space => :NO_HIGHLIGHT, # 'sp' :plain => :NO_HIGHLIGHT, } |
| [R] | css |
# File lib/coderay/encoders/html.rb, line 89 def initialize(*) super @last_options = nil end
