Module: Kramdown::Utils::Html

### Home Classes Methods

### In Files

- lib/kramdown/utils/html.rb

### Methods

- #entity_to_str
- #escape_html
- #html_attributes

### Class/Module Index

Quicksearch

- Kramdown
- Kramdown::Converter
- Kramdown::Converter::Base
- Kramdown::Converter::Html
- Kramdown::Converter::Kramdown
- Kramdown::Converter::Latex
- Kramdown::Converter::MathEngine
- Kramdown::Converter::MathEngine::Itex2MML
- Kramdown::Converter::MathEngine::Mathjax
- Kramdown::Converter::MathEngine::Ritex
- Kramdown::Converter::RemoveHtmlTags
- Kramdown::Converter::SyntaxHighlighter
- Kramdown::Converter::SyntaxHighlighter::Coderay
- Kramdown::Converter::SyntaxHighlighter::Rouge
- Kramdown::Converter::Toc
- Kramdown::Document
- Kramdown::Element
- Kramdown::Error
- Kramdown::Options
- Kramdown::Options::Boolean
- Kramdown::Parser
- Kramdown::Parser::Base
- Kramdown::Parser::GFM
- Kramdown::Parser::Html
- Kramdown::Parser::Html::Constants
- Kramdown::Parser::Html::ElementConverter
- Kramdown::Parser::Html::Parser
- Kramdown::Parser::Kramdown
- Kramdown::Parser::Markdown
- Kramdown::Utils
- Kramdown::Utils::Configurable
- Kramdown::Utils::Entities
- Kramdown::Utils::Entities::Entity
- Kramdown::Utils::Html
- Kramdown::Utils::OrderedHash
- Kramdown::Utils::StringScanner
- Kramdown::Utils::Unidecoder

No matching classes.

# Kramdown::Utils::Html

Provides convenience methods for HTML related tasks.

Note that this module has to be mixed into a class that has a @root (containing an element of type :root) and an @options (containing an options hash) instance variable so that some of the methods can work correctly.

### Public Instance Methods

entity_to_str(e, original = nil) click to toggle source

Convert the entity `e` to a string. The optional parameter `original` may contain the original representation of the entity.

This method uses the option `entity_output` to determine the output form for the entity.

    # File lib/kramdown/utils/html.rb, line 24
    def entity_to_str(e, original = nil)
      entity_output = @options[:entity_output]

      if e.char.respond_to?(:encoding) && entity_output == :as_char &&
          (c = e.char.encode(@root.options[:encoding]) rescue nil) &&
          ((c = e.char) == '"' || !ESCAPE_MAP.has_key?(c))
        c
      elsif (entity_output == :as_input || entity_output == :as_char) && original
        original
      elsif (entity_output == :symbolic || ESCAPE_MAP.has_key?(e.char)) && !e.name.nil?
        "&#{e.name};"
      else # default to :numeric
        "&##{e.code_point};"
      end
    end

escape_html(str, type = :all) click to toggle source

Escape the special HTML characters in the string `str`. The parameter `type` specifies what is escaped: :all - all special HTML characters except the quotation mark as well as entities, :text - all special HTML characters except the quotation mark but no entities and :attribute - all special HTML characters including the quotation mark but no entities.

    # File lib/kramdown/utils/html.rb, line 66
    def escape_html(str, type = :all)
      str.gsub(ESCAPE_RE_FROM_TYPE[type]) {|m| ESCAPE_MAP[m] || m}
    end

html_attributes(attr) click to toggle source

Return the HTML representation of the attributes `attr`.

    # File lib/kramdown/utils/html.rb, line 41
    def html_attributes(attr)
      attr.map {|k,v| v.nil? || (k == 'id' && v.strip.empty?) ? '' : " #{k}=\"#{escape_html(v.to_s, :attribute)}\"" }.join('')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.