Class: CodeRay::Encoders::HTML

Inherits:
Encoder
  • Object
show all
Includes:
CodeRay::Streamable
Defined in:
vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html.rb,
vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html/css.rb,
vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html/output.rb,
vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html/numerization.rb

Overview

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

: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)

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

:highlight_lines

Highlights certain line numbers. Can be any Enumerable, typically just an Array or Range, of numbers.

Bolding is deactivated when :highlight_lines is set. It only makes sense in combination with :line_numbers.

Default: nil

: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

Direct Known Subclasses

Div, Page, Span

Defined Under Namespace

Modules: Output Classes: CSS

Constant Summary

FILE_EXTENSION =
'html'
DEFAULT_OPTIONS =
{
  :tab_width => 8,

  :css => :class,

  :style => :cycnus,
  :wrap => nil,
  :title => 'CodeRay output',

  :line_numbers => nil,
  :line_number_start => 1,
  :bold_every => 10,
  :highlight_lines => nil,

  :hint => false,
}
HTML_ESCAPE =
{  #:nodoc:
  '&' => '&amp;',
  '"' => '&quot;',
  '>' => '&gt;',
  '<' => '&lt;',
}
HTML_ESCAPE_PATTERN =

ansi_chars = Array(0x7f..0xff) ansi_chars.each { |i| HTML_ESCAPE[i.chr] = ’&#%d;’ % i } \x9 (\t) and \xA (\n) not included HTML_ESCAPE_PATTERN = /[\t&"><\0-\x8\xB-\x1f\x7f-\xff]/

/[\t"&><\0-\x8\xB-\x1f]/
TOKEN_KIND_TO_INFO =
Hash.new {
TRANSPARENT_TOKEN_KINDS =
[
  :delimiter, :modifier, :content, :escape, :inline_delimiter,
].to_set

Constants inherited from Encoder

DEFAULT_OPTIONS

Instance Attribute Summary

Method Summary

Methods inherited from Encoder

const_missing, #encode, #encode_stream, #encode_tokens, #file_extension, #initialize, streamable?, #to_proc

Methods included from CodeRay::Plugin

#helper, #included, #plugin_host, #plugin_id, #register_for, #title

Constructor Details

This class inherits a constructor from CodeRay::Encoders::Encoder

Instance Attribute Details

- (Object) css (readonly)

Returns the value of attribute css



107
108
109
# File 'vendor/plugins/coderay-0.9.2/lib/coderay/encoders/html.rb', line 107

def css
  @css
end