Class: Asciidoctor::Rhrev::ChangeBarsHtmlTreeprocessor

Inherits:
Extensions::Treeprocessor
  • Object
show all
Defined in:
lib/asciidoctor/rhrev/rhrev_html.rb

Overview

Tags blocks marked with the current revision (revnumber 1.2 => attribute rhrev1-2) with the rhrev-changed role so a stylesheet can draw an HTML change bar (border on the right side). Enabled by the rhrev-change-bars document attribute, mirroring the PDF backend. The rhrev-change-bars-color, -width, and -offset attributes are emitted as CSS custom properties; the side is always right in HTML output (no recto/verso model).

Constant Summary collapse

TRACKED_CONTEXTS =

The first six are marked and tagged directly. The other nine (mirrors Converter::ROLLUP_CONTEXTS on the PDF side) get their own bar too: unlike the PDF backend, tagging here needs no id or anchor, it is just a role on whatever block carries the attribute, so a rollup context is tagged exactly the same way as a section or a table. Their revision-history entry is a separate concern, handled by Html5Converter#collect_all_entries below.

[
  :section, :floating_title, :example, :listing, :table, :image,
  :paragraph, :ulist, :olist, :dlist, :admonition, :open, :quote, :verse, :sidebar
].freeze

Instance Method Summary collapse

Instance Method Details

#process(document) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 82

def process document
  return document unless document.basebackend? 'html'
  return document unless document.attr? 'rhrev-change-bars'
  return document unless (revnumber = document.attr 'revnumber')
  prefix = document.attr 'revhistoryprefix', 'rhrev'
  change_attr = %(#{prefix}#{revnumber.to_s.tr '.', '-'})

  tagged = false
  document.find_by { |b| TRACKED_CONTEXTS.include? b.context }.each do |block|
    next unless block.attributes && (block.attributes.key? change_attr)
    roles = (block.attr 'role')
    block.set_attr 'role', [roles, 'rhrev-changed'].compact.join(' ')
    tagged = true
  end
  return document unless tagged

  overrides = []
  if (color = document.attr 'rhrev-change-bars-color')
    overrides << %(--rhrev-change-bar-color: ##{color.to_s.delete_prefix '#'};)
  end
  if (width = document.attr 'rhrev-change-bars-width')
    overrides << %(--rhrev-change-bar-width: #{width}px;)
  end
  if (offset = document.attr 'rhrev-change-bars-offset')
    overrides << %(--rhrev-change-bar-offset: #{offset}px;)
  end
  unless overrides.empty?
    style = create_block document, :pass, %(<style>:root { #{overrides.join ' '} }</style>), {}
    document.blocks.unshift style
  end
  document
end