summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/plantuml_filter.rb
diff options
context:
space:
mode:
authorHoracio Sanson <horacio@allm.net>2017-01-16 09:07:02 +0900
committerHoracio Sanson <horacio@allm.net>2017-02-03 08:49:48 +0900
commitd9e9ad2211c06159914e0183e4842abc16e5666f (patch)
treeffa7e02948f10a42b42d33d3b568774c147bd98c /lib/banzai/filter/plantuml_filter.rb
parente7d530a624fbb8854047c3983eaa0972a19f36c8 (diff)
downloadgitlab-ce-d9e9ad2211c06159914e0183e4842abc16e5666f.tar.gz
PlantUML support for Markdown
Allow rendering of PlantUML diagrams in Markdown documents using fenced blocks: ```plantuml Bob -> Sara : Hello Sara -> Bob : Go away ``` Closes: #4048
Diffstat (limited to 'lib/banzai/filter/plantuml_filter.rb')
-rw-r--r--lib/banzai/filter/plantuml_filter.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/banzai/filter/plantuml_filter.rb b/lib/banzai/filter/plantuml_filter.rb
new file mode 100644
index 00000000000..e194cf59275
--- /dev/null
+++ b/lib/banzai/filter/plantuml_filter.rb
@@ -0,0 +1,39 @@
+require "nokogiri"
+require "asciidoctor-plantuml/plantuml"
+
+module Banzai
+ module Filter
+ # HTML that replaces all `code plantuml` tags with PlantUML img tags.
+ #
+ class PlantumlFilter < HTML::Pipeline::Filter
+ def call
+ return doc unless doc.at('pre.plantuml') and settings.plantuml_enabled
+
+ plantuml_setup
+
+ doc.css('pre.plantuml').each do |el|
+ img_tag = Nokogiri::HTML::DocumentFragment.parse(
+ Asciidoctor::PlantUml::Processor.plantuml_content(el.content, {}))
+ el.replace img_tag
+ end
+
+ doc
+ end
+
+ private
+
+ def settings
+ ApplicationSetting.current || ApplicationSetting.create_from_defaults
+ end
+
+ def plantuml_setup
+ Asciidoctor::PlantUml.configure do |conf|
+ conf.url = settings.plantuml_url
+ conf.png_enable = settings.plantuml_enabled
+ conf.svg_enable = false
+ conf.txt_enable = false
+ end
+ end
+ end
+ end
+end