Class: Coradoc::Html::Converters::Span
- Defined in:
- lib/coradoc/html/converters/span.rb
Overview
Converter for generic Span inline element
Class Method Summary collapse
-
.to_coradoc(node, state = {}) ⇒ Coradoc::CoreModel::InlineElement
Convert HTML <span> to CoreModel::InlineElement.
-
.to_html(model, state = {}) ⇒ String
Convert CoreModel::InlineElement (span) to HTML <span>.
Methods inherited from Base
build_class_attribute, build_element, build_html_attributes, convert_content_to_html, convert_element_to_core, convert_node_to_core, escape_attribute, escape_html, extract_model_attributes, extract_node_attributes, extract_text_fallback, find_converter_class_by_name, find_converter_for_model, handle_unknown_content, render_core_abbreviation, render_core_annotation_block, render_core_bibliography, render_core_bibliography_entry, render_core_block, render_core_block_image, render_core_definition_item, render_core_definition_list, render_core_footnote, render_core_footnote_reference, render_core_inline_element, render_core_inline_image, render_core_list_block, render_core_list_item, render_core_span, render_core_structural_element, render_core_table_cell, render_core_table_row, render_core_term, render_core_toc, render_core_toc_entry, resolve_block_semantic_type, resolve_format_specific_semantic, transform_to_coremodel, treat_children
Class Method Details
.to_coradoc(node, state = {}) ⇒ Coradoc::CoreModel::InlineElement
Convert HTML <span> to CoreModel::InlineElement
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/coradoc/html/converters/span.rb', line 13 def to_coradoc(node, state = {}) text = node.inner_text attrs = extract_node_attributes(node) # Collect all children for potential mixed content children = node.children.flat_map do |child| convert_node_to_core(child, state) end.compact span = Coradoc::CoreModel::InlineElement.new( format_type: 'span', content: text ) # Set class from attributes as metadata span.(:class, attrs[:class]) if attrs[:class] # If there are children (mixed content), use them span.children = children if children.any? span end |
.to_html(model, state = {}) ⇒ String
Convert CoreModel::InlineElement (span) to HTML <span>
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/coradoc/html/converters/span.rb', line 40 def to_html(model, state = {}) # Prefer children for mixed content, fall back to content content = if model.children&.any? model.children.map { |c| convert_content_to_html(c, state) }.join else escape_html(model.content || '') end # Build attributes from metadata attrs = {} if model. && model.[:class] attrs[:class] = model.[:class] end build_element('span', content, attrs) end |