Class: Syntax::Convertors::HTML

### Home Classes Methods

### In Files

- lib/syntax/convertors/html.rb

### Parent

Syntax::Convertors::Abstract

### Methods

- #convert

### Class/Module Index

Quicksearch

- Syntax
- Syntax::AnsiC
- Syntax::CSS21
- Syntax::Convertors
- Syntax::Convertors::Abstract
- Syntax::Convertors::HTML
- Syntax::Default
- Syntax::Fortran
- Syntax::Javascript
- Syntax::Ruby
- Syntax::SQLite
- Syntax::Token
- Syntax::Tokenizer
- Syntax::Version
- Syntax::XML
- Syntax::YAML

No matching classes.

# Syntax::Convertors::HTML

A simple class for converting a text into HTML.

### Public Instance Methods

convert( text, pre=true ) click to toggle source

Converts the given text to HTML, using spans to represent token groups of any type but `:normal` (which is always unhighlighted). If `pre` is `true`, the html is automatically wrapped in pre tags.

    # File lib/syntax/convertors/html.rb, line 12
    def convert( text, pre=true )
      html = ""
      html << "<pre>" if pre
      regions = []
      @tokenizer.tokenize( text ) do |tok|
        value = html_escape(tok)
        case tok.instruction
          when :region_close then
            regions.pop
            html << "</span>"
          when :region_open then
            regions.push tok.group
            html << "<span class=\"#{tok.group}\">#{value}"
          else
            if tok.group == ( regions.last || :normal )
              html << value
            else
              html << "<span class=\"#{tok.group}\">#{value}</span>"
            end
        end
      end
      html << "</span>" while regions.pop
      html << "</pre>" if pre
      html
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.