Class: Kramdown::CustomDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown/custom_document.rb

Constant Summary collapse

DEFAULTS =
{
  parse_block_html: true
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ CustomDocument

Returns a new instance of CustomDocument.



22
23
24
25
26
# File 'lib/kramdown/custom_document.rb', line 22

def initialize(source, options={})
  @source = source
  @parsed_dom = Kramdown::Document.new(@source, DEFAULTS.merge(options))
  @custom_elements = extract_custom_elements
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *attr, &block) ⇒ Object



40
41
42
# File 'lib/kramdown/custom_document.rb', line 40

def method_missing(id, *attr, &block)
  @parsed_dom.send(id, attr, &block)
end

Instance Attribute Details

#custom_elementsObject (readonly)

Returns the value of attribute custom_elements.



20
21
22
# File 'lib/kramdown/custom_document.rb', line 20

def custom_elements
  @custom_elements
end

Class Method Details

.define_element(name, element = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/kramdown/custom_document.rb', line 5

def self.define_element(name, element=nil)
  if element.nil?
    element = CustomElement
  end
  tag_name = name.downcase
  Kramdown::Parser::Html::Constants::HTML_ELEMENT[tag_name] = true
  Kramdown::Parser::Html::Constants::HTML_CONTENT_MODEL[tag_name] = :block
  @@custom_elements ||= {}
  @@custom_elements[tag_name] = element
end

Instance Method Details

#rootObject



28
29
30
# File 'lib/kramdown/custom_document.rb', line 28

def root
  @parsed_dom.root
end

#to_htmlObject



36
37
38
# File 'lib/kramdown/custom_document.rb', line 36

def to_html
  @parsed_dom.to_html
end

#warningsObject



32
33
34
# File 'lib/kramdown/custom_document.rb', line 32

def warnings
  @parsed_dom.warnings
end