Class: Coradoc::Html::Converters::CommentBlock
- Defined in:
- lib/coradoc/html/converters/comment_block.rb
Overview
Converter for CoreModel::Block with element_type “comment”
Class Method Summary collapse
-
.to_coradoc(element, _options = {}) ⇒ Object
Convert HTML comment to CoreModel::Block (comment).
-
.to_html(comment_block, options = {}) ⇒ Object
Convert CoreModel::Block (comment) to HTML comment.
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(element, _options = {}) ⇒ Object
Convert HTML comment to CoreModel::Block (comment)
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/coradoc/html/converters/comment_block.rb', line 28 def self.to_coradoc(element, = {}) return nil unless element.comment? # Extract comment text text = element.text.to_s Coradoc::CoreModel::Block.new( element_type: 'comment', content: text ) end |
.to_html(comment_block, options = {}) ⇒ Object
Convert CoreModel::Block (comment) to HTML comment
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/coradoc/html/converters/comment_block.rb', line 9 def self.to_html(comment_block, = {}) return '' unless comment_block # Check if comments should be preserved return '' unless [:preserve_comments] # Get comment text (CoreModel::Block has content attribute) text = comment_block.content.to_s # HTML comments cannot contain -- # Replace -- with - - to avoid breaking the comment safe_text = text.gsub('--', '- -') # Preserve newlines in comment block # Multi-line comment blocks should preserve their internal newlines "<!--\n#{escape_html(safe_text)}\n-->" end |