summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2017-04-19 17:54:58 +0200
committerAdam Niedzielski <adamsunday@gmail.com>2017-04-19 17:54:58 +0200
commit0945dc4179abbf435a9b0aaf4482c94bd0368e35 (patch)
treefad1a0bc90f4840600187b66d3d0778ee2da2811
parenta9446a279ad88169663cc4effb93c26426901a6a (diff)
downloadgitlab-ce-plantuml-filter-after-highlight.tar.gz
Fix PlantUML integration in GFMplantuml-filter-after-highlight
Fixes #30557 Use "lang" attribute instead of "class" in PlantumlFilter.
-rw-r--r--changelogs/unreleased/plantuml-filter-after-highlight.yml4
-rw-r--r--lib/banzai/filter/plantuml_filter.rb8
-rw-r--r--spec/lib/banzai/filter/plantuml_filter_spec.rb8
3 files changed, 12 insertions, 8 deletions
diff --git a/changelogs/unreleased/plantuml-filter-after-highlight.yml b/changelogs/unreleased/plantuml-filter-after-highlight.yml
new file mode 100644
index 00000000000..f438bfd2bf7
--- /dev/null
+++ b/changelogs/unreleased/plantuml-filter-after-highlight.yml
@@ -0,0 +1,4 @@
+---
+title: Fix PlantUML integration in GFM
+merge_request: 10651
+author:
diff --git a/lib/banzai/filter/plantuml_filter.rb b/lib/banzai/filter/plantuml_filter.rb
index b2537117558..5325819d828 100644
--- a/lib/banzai/filter/plantuml_filter.rb
+++ b/lib/banzai/filter/plantuml_filter.rb
@@ -7,14 +7,14 @@ module Banzai
#
class PlantumlFilter < HTML::Pipeline::Filter
def call
- return doc unless doc.at('pre.plantuml') && settings.plantuml_enabled
+ return doc unless doc.at('pre > code[lang="plantuml"]') && settings.plantuml_enabled
plantuml_setup
- doc.css('pre.plantuml').each do |el|
+ doc.css('pre > code[lang="plantuml"]').each do |node|
img_tag = Nokogiri::HTML::DocumentFragment.parse(
- Asciidoctor::PlantUml::Processor.plantuml_content(el.content, {}))
- el.replace img_tag
+ Asciidoctor::PlantUml::Processor.plantuml_content(node.content, {}))
+ node.parent.replace(img_tag)
end
doc
diff --git a/spec/lib/banzai/filter/plantuml_filter_spec.rb b/spec/lib/banzai/filter/plantuml_filter_spec.rb
index f85a5dcbd8b..9b8ecb201f3 100644
--- a/spec/lib/banzai/filter/plantuml_filter_spec.rb
+++ b/spec/lib/banzai/filter/plantuml_filter_spec.rb
@@ -5,7 +5,7 @@ describe Banzai::Filter::PlantumlFilter, lib: true do
it 'should replace plantuml pre tag with img tag' do
stub_application_setting(plantuml_enabled: true, plantuml_url: "http://localhost:8080")
- input = '<pre class="plantuml"><code>Bob -> Sara : Hello</code><pre>'
+ input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
output = '<div class="imageblock"><div class="content"><img class="plantuml" src="http://localhost:8080/png/U9npoazIqBLJ24uiIbImKl18pSd91m0rkGMq"></div></div>'
doc = filter(input)
@@ -14,8 +14,8 @@ describe Banzai::Filter::PlantumlFilter, lib: true do
it 'should not replace plantuml pre tag with img tag if disabled' do
stub_application_setting(plantuml_enabled: false)
- input = '<pre class="plantuml"><code>Bob -> Sara : Hello</code><pre>'
- output = '<pre class="plantuml"><code>Bob -&gt; Sara : Hello</code><pre></pre></pre>'
+ input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
+ output = '<pre><code lang="plantuml">Bob -&gt; Sara : Hello</code></pre>'
doc = filter(input)
expect(doc.to_s).to eq output
@@ -23,7 +23,7 @@ describe Banzai::Filter::PlantumlFilter, lib: true do
it 'should not replace plantuml pre tag with img tag if url is invalid' do
stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid")
- input = '<pre class="plantuml"><code>Bob -> Sara : Hello</code><pre>'
+ input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> PlantUML Error: cannot connect to PlantUML server at "invalid"</pre></div></div>'
doc = filter(input)