Class: Banzai::Filter::PlantumlFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/banzai/filter/plantuml_filter.rb

Overview

HTML that replaces all `lang plantuml` tags with PlantUML img tags.

Instance Method Summary collapse

Instance Method Details

#callObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/banzai/filter/plantuml_filter.rb', line 11

def call
  return doc unless settings.plantuml_enabled? && doc.at_xpath(lang_tag)

  plantuml_setup

  doc.xpath(lang_tag).each do |node|
    img_tag = Nokogiri::HTML::DocumentFragment.parse(
      Asciidoctor::PlantUml::Processor.plantuml_content(node.content, {})).css('img').first

    unless img_tag.nil?
      img_tag.set_attribute('data-diagram', 'plantuml')
      img_tag.set_attribute('data-diagram-src', "data:text/plain;base64,#{Base64.strict_encode64(node.content)}")

      node.parent.replace(img_tag)
    end
  end

  doc
end