Class: Coradoc::Input::Html::Converters::Td
- Defined in:
- lib/coradoc/html/input/converters/td.rb
Direct Known Subclasses
Instance Method Summary collapse
- #extract_alignment(node) ⇒ Object
-
#extract_text_from_content(content) ⇒ Object
Extract text from content array.
- #to_coradoc(node, state = {}) ⇒ Object
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
#extract_alignment(node) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/coradoc/html/input/converters/td.rb', line 29 def extract_alignment(node) align = node['align'] node['valign'] # Combine horizontal and vertical alignment case align when 'left' then 'left' when 'center' then 'center' when 'right' then 'right' end # Return alignment string (can be extended to include vertical) end |
#extract_text_from_content(content) ⇒ Object
Extract text from content array
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/coradoc/html/input/converters/td.rb', line 42 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 else '' end else item.to_s end end.join end |
#to_coradoc(node, state = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/coradoc/html/input/converters/td.rb', line 8 def to_coradoc(node, state = {}) node['id'] colspan = node['colspan']&.to_i rowspan = node['rowspan']&.to_i alignment = extract_alignment(node) singlepara = node.elements.size == 1 && node.elements.first.name == 'p' state[:tdsinglepara] = singlepara if singlepara content = treat_children_coradoc(node, state) # Use CoreModel::TableCell Coradoc::CoreModel::TableCell.new( content: extract_text_from_content(content), alignment: alignment, colspan: colspan && colspan > 1 ? colspan : nil, rowspan: rowspan && rowspan > 1 ? rowspan : nil, header: node.name == 'th' ) end |