Class: Coradoc::Html::Converters::Paragraph
- Defined in:
- lib/coradoc/html/converters/paragraph.rb
Overview
Converter for Paragraph block element
Class Method Summary collapse
-
.to_coradoc(node, state = {}) ⇒ Coradoc::CoreModel::Block
Convert HTML <p> to CoreModel Block.
-
.to_html(model, state = {}) ⇒ String
Convert CoreModel::Block (element_type: paragraph) to HTML <p>.
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::Block
Convert HTML <p> to CoreModel Block
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/coradoc/html/converters/paragraph.rb', line 13 def to_coradoc(node, state = {}) content = treat_children(node, state) attrs = extract_node_attributes(node) # Create paragraph block with content paragraph = Coradoc::CoreModel::Block.new( element_type: 'paragraph', children: [content] ) # Set ID if present paragraph.id = attrs[:id] if attrs[:id] paragraph end |
.to_html(model, state = {}) ⇒ String
Convert CoreModel::Block (element_type: paragraph) to HTML <p>
33 34 35 36 37 38 39 40 41 |
# File 'lib/coradoc/html/converters/paragraph.rb', line 33 def to_html(model, state = {}) # Use renderable_content to handle both content and children content_to_render = model.renderable_content content = convert_content_to_html(content_to_render, state) # Strip trailing whitespace from content to avoid issues with line breaks content = content.rstrip attributes = extract_model_attributes(model) build_element('p', content, attributes) end |