Class: Coradoc::Input::Html::Converters::Figure
- Defined in:
- lib/coradoc/html/input/converters/figure.rb
Instance Method Summary collapse
-
#extract_text_from_content(content) ⇒ Object
Extract text from content array.
- #extract_title(node) ⇒ Object
- #to_coradoc(node, state = {}) ⇒ Object
Methods inherited from Base
#convert, #escape_text, #extract_leading_trailing_whitespace, #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
#extract_text_from_content(content) ⇒ Object
Extract text from content array
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/coradoc/html/input/converters/figure.rb', line 29 def extract_text_from_content(content) return content if content.is_a?(String) return '' if content.nil? content.map do |item| case item when String item when Coradoc::CoreModel::InlineElement item.content.to_s when Coradoc::CoreModel::Base if item.content item.content.to_s elsif item.title item.title.to_s else '' end else item.to_s end end.join end |
#extract_title(node) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/coradoc/html/input/converters/figure.rb', line 21 def extract_title(node) title = node.at('./figcaption') return '' if title.nil? treat_children_coradoc(title, {}) end |
#to_coradoc(node, state = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/coradoc/html/input/converters/figure.rb', line 8 def to_coradoc(node, state = {}) id = node['id'] title_content = extract_title(node) content = treat_children_coradoc(node, state) # Use CoreModel::ExampleBlock for example/figure Coradoc::CoreModel::ExampleBlock.new( title: extract_text_from_content(title_content), children: content, id: id ) end |