Class: Asciidoctor::Rhrev::TableCellMarkPropagationHtmlTreeprocessor
- Inherits:
-
Extensions::Treeprocessor
- Object
- Extensions::Treeprocessor
- Asciidoctor::Rhrev::TableCellMarkPropagationHtmlTreeprocessor
- Defined in:
- lib/asciidoctor/rhrev/rhrev_html.rb
Overview
Table cells cannot carry an rhrev attribute of their own through normal AsciiDoc parsing: a plain (|) cell never parses its content as blocks at all, an attribute list there is just literal text; an AsciiDoc-style (a|) cell does parse its content as blocks, so [rhrev1-2="..."] before content parses and attaches, but to the first nested block, not the cell, and that nested block is not reachable from the outer document (its inner_document is a separate tree). Same limitation the PDF backend works around (Converter#propagate_cell_content_marks, converter.rb), for the same reason: neither Html5Converter#rollup_table_cell_revision_entries below (the revision-history side) nor Html5Converter#convert_table's role check (the CSS-bar side) can see a mark that never left the nested block.
Must run as its own treeprocessor, before ChangeBarsHtmlTreeprocessor, not lazily from Html5Converter#collect_all_entries at render time: treeprocessors all run before conversion starts, so if propagation happened later, ChangeBarsHtmlTreeprocessor would already have tagged the nested paragraph directly (it is a rollup context, tracked in its own right) using the mark's original, unpropagated location, before this ever got a chance to move it.
Copies any rhrev-prefixed attribute from a marked nested rollup-context node onto the enclosing cell, then strips it from the nested node, same as the PDF side: leaving it in place would tag both the cell and the nested paragraph independently, a redundant double border for what is really one mark on one piece of content.
Instance Method Summary collapse
Instance Method Details
#process(document) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 35 def process document return document unless document.basebackend? 'html' prefix = document.attr 'revhistoryprefix', 'rhrev' document.find_by(context: :table).each do |table| cells = (table.rows[:head] + table.rows[:body]).flatten cells.each do |cell| next unless cell.style == :asciidoc inner = (cell.inner_document rescue nil) next unless inner inner.find_by { |node| Html5Converter::ROLLUP_CONTEXTS.include? node.context }.each do |node| attr_entries = (node.instance_variable_get(:@attributes) rescue nil) next if attr_entries.nil? || attr_entries.empty? attr_entries.keys.each do |key| key_str = key.to_s next unless key_str.start_with?(prefix) cell.set_attr key_str, attr_entries[key] node.remove_attr key_str end end end end document end |