Class: Coradoc::Html::Converters::AttributeReference
- Defined in:
- lib/coradoc/html/converters/attribute_reference.rb
Overview
Converts CoreModel::InlineElement with format_type “attribute_reference”
Attribute references are inline placeholders that reference document attributes (e.g., author, docname, revnumber).
In HTML, we render them as-is with the curly braces to preserve the reference syntax. Actual substitution of attribute values would happen at a different processing layer if needed.
Examples:
{author} => {author}
{docname} => {docname}
Class Method Summary collapse
-
.to_coradoc(text, _options = {}) ⇒ Coradoc::CoreModel::InlineElement?
Convert HTML text to CoreModel::InlineElement (attribute_reference).
-
.to_html(model, options = {}) ⇒ String
Convert CoreModel::InlineElement (attribute_reference) to HTML.
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(text, _options = {}) ⇒ Coradoc::CoreModel::InlineElement?
Convert HTML text to CoreModel::InlineElement (attribute_reference)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/coradoc/html/converters/attribute_reference.rb', line 43 def self.to_coradoc(text, = {}) return nil unless text.is_a?(String) # Match attribute reference pattern: {name} match = text.match(/^\{([^}]+)\}$/) return nil unless match name = match[1] Coradoc::CoreModel::InlineElement.new( format_type: 'attribute_reference', target: name ) end |
.to_html(model, options = {}) ⇒ String
Convert CoreModel::InlineElement (attribute_reference) to HTML
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/coradoc/html/converters/attribute_reference.rb', line 25 def self.to_html(model, = {}) name = model.target.to_s # Try to substitute with actual attribute value if document_attributes provided if [:document_attributes] value = [:document_attributes][name] || [:document_attributes][name] return escape_html(value.to_s) if value end # Fallback: render as-is with curly braces escape_html("{#{name}}") end |