Module: Ronn::Utils

Included in:
Document, RoffFilter
Defined in:
lib/ronn/utils.rb

Constant Summary collapse

HTML =

All HTML 4 elements and some that are in common use.

%w[
  a abbr acronym address applet area b base basefont bdo big blockquote body br
  button caption center cite code col colgroup dd del dfn dir div dl dt em
  fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img
  input ins isindex kbd label legend li link map menu meta noframes noscript
  object ol optgroup option p param pre q s samp script select small span strike
  strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var
].to_set
HTML_BLOCK =

Block elements.

%w[
  blockquote body colgroup dd div dl dt fieldset form frame frameset
  h1 h2 h3 h4 h5 h6 hr head html iframe li noframes noscript
  object ol optgroup option p param pre script select
  style table tbody td textarea tfoot th thead title tr tt ul
].to_set
HTML_INLINE =

Inline elements

HTML - HTML_BLOCK
HTML_EMPTY =

Elements that don’t have a closing tag.

%w[area base basefont br col hr input link meta].to_set

Instance Method Summary collapse

Instance Method Details

#block_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ronn/utils.rb', line 31

def block_element?(name)
  HTML_BLOCK.include?(name)
end

#child_of?(node, tag) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/ronn/utils.rb', line 47

def child_of?(node, tag)
  while node
    return true if node.name && node.name.downcase == tag
    node = node.parent
  end
  false
end

#empty_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ronn/utils.rb', line 39

def empty_element?(name)
  HTML_EMPTY.include?(name)
end

#html_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ronn/utils.rb', line 43

def html_element?(name)
  HTML.include?(name)
end

#inline_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ronn/utils.rb', line 35

def inline_element?(name)
  HTML_INLINE.include?(name)
end