From 0945dc4179abbf435a9b0aaf4482c94bd0368e35 Mon Sep 17 00:00:00 2001 From: Adam Niedzielski Date: Wed, 19 Apr 2017 17:54:58 +0200 Subject: Fix PlantUML integration in GFM Fixes #30557 Use "lang" attribute instead of "class" in PlantumlFilter. --- changelogs/unreleased/plantuml-filter-after-highlight.yml | 4 ++++ lib/banzai/filter/plantuml_filter.rb | 8 ++++---- spec/lib/banzai/filter/plantuml_filter_spec.rb | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 changelogs/unreleased/plantuml-filter-after-highlight.yml 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 = '
Bob -> Sara : Hello
'
+    input = '
Bob -> Sara : Hello
' output = '
' 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 = '
Bob -> Sara : Hello
'
-    output = '
Bob -> Sara : Hello
' + input = '
Bob -> Sara : Hello
' + output = '
Bob -> Sara : Hello
' 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 = '
Bob -> Sara : Hello
'
+    input = '
Bob -> Sara : Hello
' output = '
 PlantUML Error: cannot connect to PlantUML server at "invalid"
' doc = filter(input) -- cgit v1.2.3