Class: Metanorma::Html::BaseRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/html/base_renderer.rb

Direct Known Subclasses

StandardRenderer

Defined Under Namespace

Classes: RendererContext

Constant Summary collapse

LOGO_DIR =
File.expand_path("../../../data/logos", __dir__)
SPAN_ROLE_CLASSES =
{
  "boldtitle" => "title-text",
  "nonboldtitle" => "subtitle-text",
  "citeapp" => "xref-app",
  "citefig" => "xref-fig",
  "citesec" => "xref-section",
  "citetbl" => "xref-table",
  "fmt-autonum-delim" => "number-delim",
  "fmt-caption-label" => "caption-label",
  "fmt-caption-delim" => "caption-delim",
  "fmt-element-name" => "element-label",
  "fmt-comma" => "comma",
  "fmt-conn" => "connector",
  "fmt-label-delim" => "label-delim",
  "fmt-obligation" => "obligation-text",
  "fmt-xref-container" => "xref-container",
  "fmt-xref-label" => "xref-label",
  "std_publisher" => "ref-publisher",
  "stdpublisher" => "ref-publisher-name",
  "stddocNumber" => "ref-doc-number",
  "stddocTitle" => "ref-title",
  "stddocPartNumber" => "ref-part-number",
  "stdyear" => "ref-year",
  "date" => "date",
  "smallcap" => "small-caps",
}.freeze
METANORMA_LOGO =
"metanorma-logo.svg"
FLAVOR_MAP =

--- Flavor configuration hooks ---

{
  "IsoDocument" => :iso,
  "IecDocument" => :iec,
  "IeeeDocument" => :ieee,
  "IetfDocument" => :ietf,
  "ItuDocument" => :itu,
  "IhoDocument" => :iho,
  "BipmDocument" => :bipm,
  "OgcDocument" => :ogc,
  "OimlDocument" => :oiml,
  "CcDocument" => :cc,
  "IccDocument" => :icc,
  "RiboseDocument" => :ribose,
  "PdfaDocument" => :pdfa,
}.freeze
TEMPLATE_CACHE =

--- Document Assembly ---

{}
TEMPLATE_CACHE_MUTEX =

rubocop:disable Style/MutableConstant

Mutex.new
BLOCK_TYPES =
{
  Metanorma::Document::Components::Paragraphs::ParagraphBlock => true,
  Metanorma::Document::Components::Tables::TableBlock => true,
  Metanorma::Document::Components::Lists::UnorderedList => true,
  Metanorma::Document::Components::Lists::OrderedList => true,
  Metanorma::Document::Components::Lists::DefinitionList => true,
  Metanorma::Document::Components::AncillaryBlocks::FigureBlock => true,
  Metanorma::Document::Components::Blocks::NoteBlock => true,
  Metanorma::Document::Components::AncillaryBlocks::ExampleBlock => true,
  Metanorma::Document::Components::AncillaryBlocks::SourcecodeBlock => true,
  Metanorma::Document::Components::AncillaryBlocks::FormulaBlock => true,
  Metanorma::Document::Components::MultiParagraph::QuoteBlock => true,
  Metanorma::Document::Components::MultiParagraph::AdmonitionBlock => true,
  Metanorma::Document::Components::Sections::HierarchicalSection => true,
  Metanorma::Document::Components::Sections::BasicSection => true,
  Metanorma::Document::Components::Sections::ContentSection => true,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseRenderer

Returns a new instance of BaseRenderer.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/metanorma/html/base_renderer.rb', line 71

def initialize
  @toc_entries = []
  @figure_entries = []
  @table_entries = []
  @index_term_collector = Component::IndexTermCollector.new
  @footnote_collector = Component::FootnoteCollector.new
  @current_section_id = nil
  @current_section_number = nil

  @inline_renderer = Renderers::InlineRenderer.new(self)
  @block_renderer = Renderers::BlockRenderer.new(self)
  @section_renderer = Renderers::SectionRenderer.new(self)
  @pubid_renderer = Renderers::PubidRenderer.new(self)
end

Instance Attribute Details

#document=(value) ⇒ Object (writeonly)

Sets the attribute document

Parameters:

  • value

    the value to set the attribute document to.



124
125
126
# File 'lib/metanorma/html/base_renderer.rb', line 124

def document=(value)
  @document = value
end

#footnote_collectorObject (readonly)

Returns the value of attribute footnote_collector.



66
67
68
# File 'lib/metanorma/html/base_renderer.rb', line 66

def footnote_collector
  @footnote_collector
end

#index_term_collectorObject (readonly)

Returns the value of attribute index_term_collector.



66
67
68
# File 'lib/metanorma/html/base_renderer.rb', line 66

def index_term_collector
  @index_term_collector
end

#themeObject



153
154
155
# File 'lib/metanorma/html/base_renderer.rb', line 153

def theme
  @theme ||= resolve_theme
end

Class Method Details

.inline_registryObject



57
58
59
# File 'lib/metanorma/html/base_renderer.rb', line 57

def inline_registry
  @inline_registry ||= {}
end

.register_inline_render(type_class, method_name) ⇒ Object



61
62
63
# File 'lib/metanorma/html/base_renderer.rb', line 61

def register_inline_render(type_class, method_name)
  inline_registry[type_class] = method_name
end

.register_render(type_class, method_name) ⇒ Object



53
54
55
# File 'lib/metanorma/html/base_renderer.rb', line 53

def register_render(type_class, method_name)
  render_registry[type_class] = method_name
end

.render_registryObject



49
50
51
# File 'lib/metanorma/html/base_renderer.rb', line 49

def render_registry
  @render_registry ||= {}
end

Instance Method Details

#alignment_style(alignment) ⇒ Object



926
927
928
929
930
# File 'lib/metanorma/html/base_renderer.rb', line 926

def alignment_style(alignment)
  return nil if alignment.nil? || alignment.to_s.empty?

  "text-align: #{alignment}"
end

#assemble_document(body) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/metanorma/html/base_renderer.rb', line 200

def assemble_document(body)
  toc_html = build_toc_html(@toc_entries)
  header = build_header
  footer = build_footer

  render_liquid("document.html.liquid", {
                  "lang" => language,
                  "title" => html_title,
                  "font_url" => flavor_font_url,
                  "styles" => build_styles,
                  "header" => header,
                  "toc" => toc_html,
                  "body" => body,
                  "footer" => footer,
                  "scripts" => build_scripts,
                })
end

#block_element?(obj) ⇒ Boolean

Returns:

  • (Boolean)


880
881
882
# File 'lib/metanorma/html/base_renderer.rb', line 880

def block_element?(obj)
  BLOCK_TYPES[obj.class] || BLOCK_TYPES.any? { |type, _| obj.is_a?(type) }
end


291
292
293
294
295
296
297
# File 'lib/metanorma/html/base_renderer.rb', line 291

def build_footer
   = load_logo_svg(METANORMA_LOGO, height: 20)
  render_liquid("_footer.html.liquid", {
                  "mn_logo" => ,
                  "generated_at" => Time.now.strftime("%Y-%m-%d %H:%M"),
                })
end

#build_headerObject

--- Header and Footer ---



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/metanorma/html/base_renderer.rb', line 220

def build_header
  doc_id = extract_primary_doc_id
  pub_logos = build_publisher_logos
  pub_name = flavor_publisher_name
  display_id = if pub_name && doc_id && !doc_id.start_with?(pub_name)
                 "#{pub_name} #{doc_id}"
               else
                 doc_id
               end

  render_liquid("_header.html.liquid", {
                  "publisher_logos" => pub_logos,
                  "doc_id" => display_id,
                  "doc_title" => header_title_text,
                })
end

#build_publisher_logosObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/metanorma/html/base_renderer.rb', line 242

def build_publisher_logos
  publishers = flavor_publishers(extract_primary_doc_id)
  logo_map = publisher_logo_map
  return "" if publishers.empty? && logo_map.empty?

  dark_logo_map = theme.logos_dark
  display_pubs = publishers.empty? ? logo_map.keys : publishers

  display_pubs.filter_map do |pub|
    filename = logo_map[pub]
    next unless filename

    svg = load_logo_svg(filename, height: 26)
    next unless svg

    light_span = "<span class=\"brand-logo brand-logo-light\" aria-label=\"#{pub} logo\">#{svg}</span>"

    dark_span = ""
    dark_filename = dark_logo_map[pub]
    if dark_filename
      dark_svg = load_logo_svg(dark_filename, height: 26)
      if dark_svg
        dark_span = "<span class=\"brand-logo brand-logo-dark\" aria-label=\"#{pub} logo\">#{dark_svg}</span>"
      end
    end

    "#{light_span}\n#{dark_span}"
  end.join("\n")
end

#build_scriptsObject

--- Scripts ---



317
318
319
320
321
# File 'lib/metanorma/html/base_renderer.rb', line 317

def build_scripts
  pipeline = AssetPipeline.new
  compiled = pipeline.compile_js(flavor_js: flavor_js_module)
  "<script>\n#{compiled}\n</script>"
end

#build_stylesObject



331
332
333
334
335
336
337
338
# File 'lib/metanorma/html/base_renderer.rb', line 331

def build_styles
  pipeline = AssetPipeline.new
  css = pipeline.compile_css(flavor_css: flavor_css_module)
  parts = [theme.to_css_root, css, theme.to_css_extras]
  custom_css_path = theme.theme_css_path
  parts << File.read(custom_css_path) if custom_css_path
  parts.join("\n")
end

#build_toc_html(entries) ⇒ Object

--- ToC generation ---



301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/metanorma/html/base_renderer.rb', line 301

def build_toc_html(entries)
  entry_drops = entries.map { |e| Drops::TocEntryDrop.new(e) }
  figure_drops = @figure_entries.map { |f| Drops::FigureListEntryDrop.new(f) }
  table_drops = @table_entries.map { |t| Drops::FigureListEntryDrop.new(t) }
  has_special_lists = !@figure_entries.empty? || !@table_entries.empty?

  render_liquid("_toc.html.liquid", {
                  "entries" => entry_drops,
                  "figures" => figure_drops,
                  "tables" => table_drops,
                  "has_special_lists" => has_special_lists,
                })
end

#check_presentation_markers(node) ⇒ Object



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/metanorma/html/base_renderer.rb', line 352

def check_presentation_markers(node)
  return false unless node
  return false if node.is_a?(String)

  if node.is_a?(Lutaml::Model::Serializable)
    node_attrs = node.class.attributes
    if node_attrs.key?(:type) && node.type == "presentation"
      return true
    end
    if node_attrs.key?(:fmt_title) && node.fmt_title
      return true
    end
    if node_attrs.key?(:displayorder) && node.displayorder
      return true
    end

    %i[preface sections annex bibliography].each do |attr|
      next unless node_attrs.key?(attr)

      val = node.public_send(attr)
      next unless val

      Array(val).each { |v| return true if check_presentation_markers(v) }
    end

    node.each_mixed_content do |child|
      next if child.is_a?(String)
      return true if check_presentation_markers(child)
    end
  end

  false
end

#collect_index_term(element) ⇒ Object



894
895
896
897
898
899
900
901
902
903
904
905
906
907
# File 'lib/metanorma/html/base_renderer.rb', line 894

def collect_index_term(element)
  primary = safe_attr(element, :primary)
  return unless primary && !primary.to_s.strip.empty?

  @index_term_collector.add(
    primary: primary.to_s.strip,
    secondary: safe_attr(element, :secondary)&.to_s&.strip,
    tertiary: safe_attr(element, :tertiary)&.to_s&.strip,
    target_id: @current_section_id,
    target_text: @current_section_number,
  )
rescue StandardError
  nil
end

#collect_ordered_children(section) ⇒ Object



834
# File 'lib/metanorma/html/base_renderer.rb', line 834

def collect_ordered_children(section) = @section_renderer.collect_ordered_children(section)

#element_attrs(**attrs) ⇒ Object

--- Helper methods ---



848
849
850
851
852
853
854
855
856
# File 'lib/metanorma/html/base_renderer.rb', line 848

def element_attrs(**attrs)
  parts = []
  attrs.each do |k, v|
    next if v.nil? || v == false || (v.is_a?(String) && v.empty?)

    parts << %( #{k}="#{escape_html(v.to_s)}")
  end
  parts.join
end

#escape_html(text) ⇒ Object



941
942
943
# File 'lib/metanorma/html/base_renderer.rb', line 941

def escape_html(text)
  CGI.escapeHTML(text.to_s)
end

#extract_block_label(block, default) ⇒ Object



909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'lib/metanorma/html/base_renderer.rb', line 909

def extract_block_label(block, default)
  names = safe_attr(block, :name)
  if names && !names.empty?
    name = names.is_a?(Array) ? names.first : names
    text = extract_text_value(name)
    return text unless text.to_s.strip.empty?
  end

  autonum = safe_attr(block, :autonum)
  if autonum && !autonum.to_s.empty?
    number = autonum.to_s
    return "#{default} #{number}"
  end

  default
end

#extract_display_title(bibdata) ⇒ Object



405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/metanorma/html/base_renderer.rb', line 405

def extract_display_title(bibdata)
  return nil unless bibdata

  title = bibdata.title_for("en") if bibdata.is_a?(Metanorma::Document::Components::BibData::BibData)
  return title.to_s if title && !title.to_s.empty?

  titles = safe_attr(bibdata, :title)
  return nil unless titles && !titles.is_a?(String) && !titles.empty?

  en = titles.find { |t| safe_attr(t, :language) == "en" }
  found = en || titles.first
  extract_text_value(found).to_s
end

#extract_plain_text(node) ⇒ Object



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/metanorma/html/base_renderer.rb', line 455

def extract_plain_text(node)
  return node.to_s if node.is_a?(String)
  return extract_text_value(node).to_s unless node.is_a?(Lutaml::Model::Serializable)

  parts = []
  xml_mapping = node.class.mappings_for(:xml, node.lutaml_register)

  if node.element_order.is_a?(Array) && xml_mapping
    element_to_attr = {}
    xml_mapping.mapping_elements_hash.each_value do |rule_or_array|
      Array(rule_or_array).each do |rule|
        element_to_attr[rule.name.to_s] = rule.to
      end
    end

    indices = Hash.new(0)
    node.element_order.each do |el|
      next unless el.is_a?(Lutaml::Xml::Element)

      if el.text?
        parts << el.text_content.to_s
      elsif el.name == "tab"
        parts << " "
      elsif el.name == "br"
        parts << " "
      elsif el.element?
        attr_name = element_to_attr[el.name]
        if attr_name
          coll = node.public_send(attr_name)
          obj = if coll.is_a?(Array)
                  idx = indices[attr_name]
                  indices[attr_name] += 1
                  coll[idx]
                else
                  coll
                end
          text = extract_plain_text(obj)
          parts << (text.empty? ? " " : text)
        elsif el.name == "span"
          parts << " "
        end
      end
    end
  end

  if parts.join.strip.empty?
    t = safe_attr(node, :text)
    parts << (t.is_a?(Array) ? t.join : t.to_s) if t
  end

  parts.join.strip.gsub(" ", " ")
end

#extract_primary_doc_idObject



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/metanorma/html/base_renderer.rb', line 419

def extract_primary_doc_id
  bibdata = @document.bibdata
  return nil unless bibdata

  identifiers = bibdata.doc_identifier
  return nil unless identifiers && !identifiers.empty?

  first_id = identifiers.first
  text = if first_id.is_a?(String)
           first_id
         elsif first_id.is_a?(Lutaml::Model::Serializable)
           Array(first_id.value).join
         else
           first_id.to_s
         end
  text.strip.empty? ? nil : text.strip
end

#extract_text_value(val) ⇒ Object



945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# File 'lib/metanorma/html/base_renderer.rb', line 945

def extract_text_value(val)
  return nil if val.nil?
  return val if val.is_a?(String)

  if val.is_a?(Array)
    val.map { |v| extract_text_value(v) }.join
  elsif val.is_a?(Lutaml::Model::Serializable)
    c = safe_attr(val, :content)
    if c && !c.equal?(val)
      extract_text_value(c)
    else
      t = safe_attr(val, :text)
      if t
        extract_text_value(t)
      else
        v = safe_attr(val, :value)
        if v
          extract_text_value(v)
        else
          val.to_s
        end
      end
    end
  else
    val.to_s
  end
end

#extract_title_text(titles) ⇒ Object



932
933
934
935
936
937
938
939
# File 'lib/metanorma/html/base_renderer.rb', line 932

def extract_title_text(titles)
  return "" if titles.nil?
  return extract_text_value(titles).to_s unless titles.is_a?(Array)
  return "" if titles.empty?

  title = titles.first
  extract_text_value(title).to_s
end

#figure_entriesObject



447
448
449
# File 'lib/metanorma/html/base_renderer.rb', line 447

def figure_entries
  @figure_entries
end

#flavor_css_moduleObject



327
328
329
# File 'lib/metanorma/html/base_renderer.rb', line 327

def flavor_css_module
  nil
end

#flavor_font_urlObject



182
183
184
# File 'lib/metanorma/html/base_renderer.rb', line 182

def flavor_font_url
  theme.font_url
end

#flavor_js_moduleObject



323
324
325
# File 'lib/metanorma/html/base_renderer.rb', line 323

def flavor_js_module
  nil
end

#flavor_nameObject



162
163
164
165
166
167
168
# File 'lib/metanorma/html/base_renderer.rb', line 162

def flavor_name
  return nil unless defined?(@document) && @document

  @document.class.name&.split("::")&.detect do |ns|
    FLAVOR_MAP.key?(ns)
  end&.then { |ns| FLAVOR_MAP[ns] }
end

#flavor_publisher_nameObject



174
175
176
# File 'lib/metanorma/html/base_renderer.rb', line 174

def flavor_publisher_name
  theme.publisher_name
end

#flavor_publishers(_doc_id) ⇒ Object



170
171
172
# File 'lib/metanorma/html/base_renderer.rb', line 170

def flavor_publishers(_doc_id)
  theme.publishers
end

#generate_full_document(document) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/metanorma/html/base_renderer.rb', line 126

def generate_full_document(document, **)
  @document = document
  validate_presentation_xml!

  body = render(@document) || ""

  assemble_document(body)
end

#header_title_textObject



237
238
239
240
# File 'lib/metanorma/html/base_renderer.rb', line 237

def header_title_text
  raw = html_title.to_s.split(" — ").first.to_s
  raw.length > 60 ? "#{raw[0, 57]}..." : raw
end

#html_class_for_span(xml_class) ⇒ Object



876
877
878
# File 'lib/metanorma/html/base_renderer.rb', line 876

def html_class_for_span(xml_class)
  SPAN_ROLE_CLASSES[xml_class] || "span-#{xml_class}"
end

#html_titleObject



401
402
403
# File 'lib/metanorma/html/base_renderer.rb', line 401

def html_title
  extract_display_title(@document.bibdata) || "Document"
end

#is_title_element?(node, section) ⇒ Boolean

Returns:

  • (Boolean)


521
522
523
524
525
526
# File 'lib/metanorma/html/base_renderer.rb', line 521

def is_title_element?(node, section)
  title = safe_attr(section, :title)
  return false unless title

  node.equal?(title)
end

#languageObject

--- Metadata extraction ---



388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/metanorma/html/base_renderer.rb', line 388

def language
  bibdata = @document.bibdata
  return "en" unless bibdata

  langs = bibdata.language
  if langs && !langs.empty?
    lang = langs.find { |l| l.current == "true" } || langs.first
    lang.value || lang.to_s
  else
    "en"
  end
end

#load_logo_svg(filename, height: 32) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/metanorma/html/base_renderer.rb', line 272

def load_logo_svg(filename, height: 32)
  path = theme.resolve_asset(filename) || File.join(LOGO_DIR, filename)
  return nil unless File.exist?(path)

  svg = File.read(path)
  svg = svg.sub(/\A<\?xml[^?]*\?>\s*/, "")
  svg = svg.sub(/\A\s*<!--.*?-->\s*/m, "")
  svg = svg.sub(/<svg\s/, '<svg class="header-logo" ')
  svg = if svg.match?(/<svg[^>]*\sheight="[^"]*"/)
          svg.sub(/(<svg[^>]*?)(\sheight="[^"]*")/,
                  "\\1 height=\"#{height}\"")
        else
          svg.sub(/(<svg\b)/, "\\1 height=\"#{height}\"")
        end
  svg.sub(/(<svg[^>]*?)\swidth="[^"]*"/, '\1')
rescue StandardError
  nil
end

#lookup_dispatch(type_class, registry_method) ⇒ Object



672
673
674
675
676
677
678
679
680
681
# File 'lib/metanorma/html/base_renderer.rb', line 672

def lookup_dispatch(type_class, registry_method)
  self.class.ancestors.each do |ancestor|
    next unless ancestor.is_a?(Class) && (ancestor == BaseRenderer || ancestor < BaseRenderer)

    registry = ancestor.public_send(registry_method)
    method_name = registry[type_class]
    return method_name if method_name
  end
  nil
end

#parse_pubid(docidentifier_string) ⇒ Object

Pubid rendering delegation



843
# File 'lib/metanorma/html/base_renderer.rb', line 843

def parse_pubid(docidentifier_string) = @pubid_renderer.parse_pubid(docidentifier_string)

#pubid_to_html(identifier) ⇒ Object



844
# File 'lib/metanorma/html/base_renderer.rb', line 844

def pubid_to_html(identifier) = @pubid_renderer.pubid_to_html(identifier)

#publisher_logo_mapObject



178
179
180
# File 'lib/metanorma/html/base_renderer.rb', line 178

def publisher_logo_map
  theme.logos_light
end

#register_figure_entry(id:, text:) ⇒ Object



443
444
445
# File 'lib/metanorma/html/base_renderer.rb', line 443

def register_figure_entry(id:, text:)
  @figure_entries << { id: id, text: text }
end

#register_table_entry(id:, text:) ⇒ Object



451
452
453
# File 'lib/metanorma/html/base_renderer.rb', line 451

def register_table_entry(id:, text:)
  @table_entries << { id: id, text: text }
end

#register_toc_entry(id:, level:, text:) ⇒ Object

--- Registration helpers ---



439
440
441
# File 'lib/metanorma/html/base_renderer.rb', line 439

def register_toc_entry(id:, level:, text:)
  @toc_entries << { id: id, level: level, text: text }
end

#render(node) ⇒ Object

--- Dispatch ---



510
511
512
513
514
515
# File 'lib/metanorma/html/base_renderer.rb', line 510

def render(node, **)
  return escape_html(node) if node.is_a?(String)

  method = lookup_dispatch(node.class, :render_registry)
  method ? public_send(method, node, **) : ""
end

#render_admonition(admonition) ⇒ Object



794
795
796
797
# File 'lib/metanorma/html/base_renderer.rb', line 794

def render_admonition(admonition,
**)
  @block_renderer.render_admonition(admonition, **)
end

#render_asciimath(el) ⇒ Object



720
# File 'lib/metanorma/html/base_renderer.rb', line 720

def render_asciimath(el) = @inline_renderer.render_asciimath(el)

#render_audio(audio) ⇒ Object



771
# File 'lib/metanorma/html/base_renderer.rb', line 771

def render_audio(audio) = @block_renderer.render_audio(audio)

#render_basic_section(section) ⇒ Object

Section rendering delegation



814
815
816
817
# File 'lib/metanorma/html/base_renderer.rb', line 814

def render_basic_section(section,
**)
  @section_renderer.render_basic_section(section, **)
end

#render_block_children(model, children:) ⇒ Object



804
805
806
807
# File 'lib/metanorma/html/base_renderer.rb', line 804

def render_block_children(model,
children:)
  @block_renderer.render_block_children(model, children: children)
end

#render_bookmark(bookmark) ⇒ Object



799
800
801
802
# File 'lib/metanorma/html/base_renderer.rb', line 799

def render_bookmark(bookmark,
**)
  @block_renderer.render_bookmark(bookmark, **)
end

#render_brObject



711
# File 'lib/metanorma/html/base_renderer.rb', line 711

def render_br(*) = @inline_renderer.render_br

#render_cell_content(cell) ⇒ Object



702
# File 'lib/metanorma/html/base_renderer.rb', line 702

def render_cell_content(cell) = @inline_renderer.render_cell_content(cell)

#render_commaObject



718
# File 'lib/metanorma/html/base_renderer.rb', line 718

def render_comma(*) = @inline_renderer.render_comma

#render_concept(concept) ⇒ Object



734
# File 'lib/metanorma/html/base_renderer.rb', line 734

def render_concept(concept) = @inline_renderer.render_concept(concept)

#render_content_section(section) ⇒ Object



824
825
826
827
# File 'lib/metanorma/html/base_renderer.rb', line 824

def render_content_section(section,
**)
  @section_renderer.render_content_section(section, **)
end

#render_definition_list(dl) ⇒ Object



759
760
761
762
# File 'lib/metanorma/html/base_renderer.rb', line 759

def render_definition_list(dl,
**)
  @block_renderer.render_definition_list(dl, **)
end

#render_em(el) ⇒ Object



703
# File 'lib/metanorma/html/base_renderer.rb', line 703

def render_em(el) = @inline_renderer.render_em(el)

#render_eref(eref) ⇒ Object



732
# File 'lib/metanorma/html/base_renderer.rb', line 732

def render_eref(eref) = @inline_renderer.render_eref(eref)

#render_example(example) ⇒ Object



774
775
776
777
# File 'lib/metanorma/html/base_renderer.rb', line 774

def render_example(example,
**)
  @block_renderer.render_example(example, **)
end

#render_figure(figure) ⇒ Object



764
765
766
767
# File 'lib/metanorma/html/base_renderer.rb', line 764

def render_figure(figure,
**)
  @block_renderer.render_figure(figure, **)
end

#render_fmt_stem(fmt_stem) ⇒ Object



735
# File 'lib/metanorma/html/base_renderer.rb', line 735

def render_fmt_stem(fmt_stem) = @inline_renderer.render_fmt_stem(fmt_stem)

#render_fmt_xref(el) ⇒ Object



717
# File 'lib/metanorma/html/base_renderer.rb', line 717

def render_fmt_xref(el) = @inline_renderer.render_fmt_xref(el)

#render_fn(fn) ⇒ Object



733
# File 'lib/metanorma/html/base_renderer.rb', line 733

def render_fn(fn) = @inline_renderer.render_fn(fn)

#render_fn_inline(el) ⇒ Object



714
# File 'lib/metanorma/html/base_renderer.rb', line 714

def render_fn_inline(el) = @inline_renderer.render_fn_inline(el)

#render_footnotes_sectionObject



973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
# File 'lib/metanorma/html/base_renderer.rb', line 973

def render_footnotes_section
  return nil if @footnote_collector.empty?

  drops = @footnote_collector.to_a.map do |entry|
    content_html = ""
    if entry.content && !entry.content.empty?
      content_html = Array(entry.content).filter_map do |p|
        render_paragraph(p)
      end.join
    end
    Drops::FootnoteDrop.new(entry, content_html)
  end

  render_liquid("_footnotes.html.liquid",
                { "footnotes" => drops })
end

#render_formula(formula) ⇒ Object



784
785
786
787
# File 'lib/metanorma/html/base_renderer.rb', line 784

def render_formula(formula,
**)
  @block_renderer.render_formula(formula, **)
end

#render_full_block_children(model) ⇒ Object



811
# File 'lib/metanorma/html/base_renderer.rb', line 811

def render_full_block_children(model) = @block_renderer.render_full_block_children(model)

#render_hierarchical_section(section) ⇒ Object



819
820
821
822
# File 'lib/metanorma/html/base_renderer.rb', line 819

def render_hierarchical_section(section,
**)
  @section_renderer.render_hierarchical_section(section, **)
end

#render_image(image) ⇒ Object



769
# File 'lib/metanorma/html/base_renderer.rb', line 769

def render_image(image) = @block_renderer.render_image(image)

#render_index(el) ⇒ Object



721
# File 'lib/metanorma/html/base_renderer.rb', line 721

def render_index(el) = @inline_renderer.render_index(el)

#render_inline_element(element) ⇒ Object



517
518
519
# File 'lib/metanorma/html/base_renderer.rb', line 517

def render_inline_element(element, **)
  @inline_renderer.render_inline_element(element)
end


730
# File 'lib/metanorma/html/base_renderer.rb', line 730

def render_link(link) = @inline_renderer.render_link(link)

#render_liquid(template_name, assigns) ⇒ Object



191
192
193
194
195
196
197
198
# File 'lib/metanorma/html/base_renderer.rb', line 191

def render_liquid(template_name, assigns)
  template_path = theme.resolve_template(template_name)
  template = TEMPLATE_CACHE_MUTEX.synchronize do
    TEMPLATE_CACHE[template_path] ||= Liquid::Template.parse(File.read(template_path))
  end
  assigns = assigns.transform_keys(&:to_s) if assigns.is_a?(Hash)
  template.render(assigns)
end

#render_math(el) ⇒ Object



719
# File 'lib/metanorma/html/base_renderer.rb', line 719

def render_math(el) = @inline_renderer.render_math(el)

#render_mixed_content_in_order(node) ⇒ Object



736
# File 'lib/metanorma/html/base_renderer.rb', line 736

def render_mixed_content_in_order(node) = @inline_renderer.render_mixed_content_in_order(node)

#render_mixed_inline(node) ⇒ Object



698
699
700
# File 'lib/metanorma/html/base_renderer.rb', line 698

def render_mixed_inline(node)
  @inline_renderer.render_mixed_inline(node)
end

#render_noopObject



683
684
685
# File 'lib/metanorma/html/base_renderer.rb', line 683

def render_noop(*)
  ""
end

#render_noop_inlineObject



687
688
689
# File 'lib/metanorma/html/base_renderer.rb', line 687

def render_noop_inline(*)
  nil
end

#render_note(note) ⇒ Object



772
# File 'lib/metanorma/html/base_renderer.rb', line 772

def render_note(note, **) = @block_renderer.render_note(note, **)

#render_note_children(model) ⇒ Object



809
# File 'lib/metanorma/html/base_renderer.rb', line 809

def render_note_children(model) = @block_renderer.render_note_children(model)

#render_note_inline(el) ⇒ Object



722
# File 'lib/metanorma/html/base_renderer.rb', line 722

def render_note_inline(el) = @inline_renderer.render_note_inline(el)

#render_ordered_content(section, level = 1) ⇒ Object



829
830
831
832
# File 'lib/metanorma/html/base_renderer.rb', line 829

def render_ordered_content(section,
level = 1)
  @section_renderer.render_ordered_content(section, level)
end

#render_ordered_list(ol) ⇒ Object



754
755
756
757
# File 'lib/metanorma/html/base_renderer.rb', line 754

def render_ordered_list(ol,
**)
  @block_renderer.render_ordered_list(ol, **)
end

#render_paragraph(p) ⇒ Object

Block rendering delegation



739
740
741
742
# File 'lib/metanorma/html/base_renderer.rb', line 739

def render_paragraph(p,
**)
  @block_renderer.render_paragraph(p, **)
end

#render_preface(preface) ⇒ Object



837
838
839
840
# File 'lib/metanorma/html/base_renderer.rb', line 837

def render_preface(preface,
**)
  @section_renderer.render_preface(preface, **)
end

#render_quote(quote) ⇒ Object



789
790
791
792
# File 'lib/metanorma/html/base_renderer.rb', line 789

def render_quote(quote,
**)
  @block_renderer.render_quote(quote, **)
end

#render_semx_content(el) ⇒ Object



724
725
726
727
# File 'lib/metanorma/html/base_renderer.rb', line 724

def render_semx_content(el,
**)
  @inline_renderer.render_semx_content(el, **)
end

#render_semx_inline(el) ⇒ Object



716
# File 'lib/metanorma/html/base_renderer.rb', line 716

def render_semx_inline(el) = @inline_renderer.render_semx_inline(el)

#render_simple_children(model) ⇒ Object



810
# File 'lib/metanorma/html/base_renderer.rb', line 810

def render_simple_children(model) = @block_renderer.render_simple_children(model)

#render_small_caps(el) ⇒ Object



708
# File 'lib/metanorma/html/base_renderer.rb', line 708

def render_small_caps(el) = @inline_renderer.render_small_caps(el)

#render_sourcecode(sc) ⇒ Object



779
780
781
782
# File 'lib/metanorma/html/base_renderer.rb', line 779

def render_sourcecode(sc,
**)
  @block_renderer.render_sourcecode(sc, **)
end

#render_span(el) ⇒ Object



713
# File 'lib/metanorma/html/base_renderer.rb', line 713

def render_span(el) = @inline_renderer.render_span(el)

#render_stem(el) ⇒ Object



715
# File 'lib/metanorma/html/base_renderer.rb', line 715

def render_stem(el) = @inline_renderer.render_stem(el)

#render_stem_content(stem) ⇒ Object



729
# File 'lib/metanorma/html/base_renderer.rb', line 729

def render_stem_content(stem) = @inline_renderer.render_stem_content(stem)

#render_strike(el) ⇒ Object



710
# File 'lib/metanorma/html/base_renderer.rb', line 710

def render_strike(el) = @inline_renderer.render_strike(el)

#render_strong(el) ⇒ Object



704
# File 'lib/metanorma/html/base_renderer.rb', line 704

def render_strong(el) = @inline_renderer.render_strong(el)

#render_sub(el) ⇒ Object



706
# File 'lib/metanorma/html/base_renderer.rb', line 706

def render_sub(el) = @inline_renderer.render_sub(el)

#render_sup(el) ⇒ Object



707
# File 'lib/metanorma/html/base_renderer.rb', line 707

def render_sup(el) = @inline_renderer.render_sup(el)

#render_tabObject



712
# File 'lib/metanorma/html/base_renderer.rb', line 712

def render_tab(*) = @inline_renderer.render_tab

#render_table(table) ⇒ Object



744
745
746
747
# File 'lib/metanorma/html/base_renderer.rb', line 744

def render_table(table,
**)
  @block_renderer.render_table(table, **)
end

#render_tt(el) ⇒ Object



705
# File 'lib/metanorma/html/base_renderer.rb', line 705

def render_tt(el) = @inline_renderer.render_tt(el)

#render_underline(el) ⇒ Object



709
# File 'lib/metanorma/html/base_renderer.rb', line 709

def render_underline(el) = @inline_renderer.render_underline(el)

#render_unordered_list(ul) ⇒ Object



749
750
751
752
# File 'lib/metanorma/html/base_renderer.rb', line 749

def render_unordered_list(ul,
**)
  @block_renderer.render_unordered_list(ul, **)
end

#render_video(video) ⇒ Object



770
# File 'lib/metanorma/html/base_renderer.rb', line 770

def render_video(video) = @block_renderer.render_video(video)

#render_xref(xref) ⇒ Object



731
# File 'lib/metanorma/html/base_renderer.rb', line 731

def render_xref(xref) = @inline_renderer.render_xref(xref)

#renderer_contextObject



116
117
118
# File 'lib/metanorma/html/base_renderer.rb', line 116

def renderer_context
  @renderer_context ||= RendererContext.new(self)
end

#resolve_themeObject



157
158
159
160
# File 'lib/metanorma/html/base_renderer.rb', line 157

def resolve_theme
  flavor = flavor_name
  flavor ? Theme.load(flavor) : Theme.new
end

#safe_attr(obj, method_name) ⇒ Object



884
885
886
887
888
889
890
891
892
# File 'lib/metanorma/html/base_renderer.rb', line 884

def safe_attr(obj, method_name)
  if obj.is_a?(Lutaml::Model::Serializable) && !obj.class.attributes.key?(method_name)
    return nil
  end

  obj.public_send(method_name)
rescue NoMethodError
  nil
end

#sort_by_displayorder(children) ⇒ Object



835
# File 'lib/metanorma/html/base_renderer.rb', line 835

def sort_by_displayorder(children) = @section_renderer.sort_by_displayorder(children)

#toc_entriesObject



120
121
122
# File 'lib/metanorma/html/base_renderer.rb', line 120

def toc_entries
  @toc_entries
end

#validate_presentation_xml!Object

--- Validation ---

Raises:

  • (ArgumentError)


342
343
344
345
346
347
348
349
350
# File 'lib/metanorma/html/base_renderer.rb', line 342

def validate_presentation_xml!
  has_presentation = check_presentation_markers(@document)
  return if has_presentation

  raise ArgumentError,
        "HTML generation requires Presentation XML input. " \
        "Semantic XML does not contain formatting data needed for HTML. " \
        "Use a '.presentation.xml' file instead."
end

#walk_ordered(node, allow_filter: nil) ⇒ Object

Inline rendering delegation



694
695
696
# File 'lib/metanorma/html/base_renderer.rb', line 694

def walk_ordered(node, allow_filter: nil, &)
  @inline_renderer.walk_ordered(node, allow_filter: allow_filter, &)
end