Class: Coradoc::Input::Html::Converters::Sub

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/html/input/converters/sub.rb

Instance Method Summary collapse

Methods inherited from Base

#convert, #escape_text, #extract_leading_trailing_whitespace, #extract_title, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#to_coradoc(node, state = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/coradoc/html/input/converters/sub.rb', line 8

def to_coradoc(node, state = {})
  leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)

  content = treat_children_coradoc(node, state)

  # Check if content is empty
  return nil if content_empty?(content)

  # Create CoreModel::InlineElement with format_type "subscript"
  e = Coradoc::CoreModel::InlineElement.new(
    format_type: 'subscript',
    content: content
  )
  result = [leading_whitespace, e, trailing_whitespace].compact
  result.length == 1 ? result.first : result
end