Commit 08b2e7cd authored by Sean McGivern's avatar Sean McGivern

Merge branch 'plantuml-filter-after-highlight' into 'master'

Fix PlantUML integration in GFM

Closes #30557

See merge request !10651
parents 6e1069d5 0945dc41
---
title: Fix PlantUML integration in GFM
merge_request: 10651
author:
...@@ -7,14 +7,14 @@ module Banzai ...@@ -7,14 +7,14 @@ module Banzai
# #
class PlantumlFilter < HTML::Pipeline::Filter class PlantumlFilter < HTML::Pipeline::Filter
def call 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 plantuml_setup
doc.css('pre.plantuml').each do |el| doc.css('pre > code[lang="plantuml"]').each do |node|
img_tag = Nokogiri::HTML::DocumentFragment.parse( img_tag = Nokogiri::HTML::DocumentFragment.parse(
Asciidoctor::PlantUml::Processor.plantuml_content(el.content, {})) Asciidoctor::PlantUml::Processor.plantuml_content(node.content, {}))
el.replace img_tag node.parent.replace(img_tag)
end end
doc doc
......
...@@ -5,7 +5,7 @@ describe Banzai::Filter::PlantumlFilter, lib: true do ...@@ -5,7 +5,7 @@ describe Banzai::Filter::PlantumlFilter, lib: true do
it 'should replace plantuml pre tag with img tag' do it 'should replace plantuml pre tag with img tag' do
stub_application_setting(plantuml_enabled: true, plantuml_url: "http://localhost:8080") 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>' output = '<div class="imageblock"><div class="content"><img class="plantuml" src="http://localhost:8080/png/U9npoazIqBLJ24uiIbImKl18pSd91m0rkGMq"></div></div>'
doc = filter(input) doc = filter(input)
...@@ -14,8 +14,8 @@ describe Banzai::Filter::PlantumlFilter, lib: true do ...@@ -14,8 +14,8 @@ describe Banzai::Filter::PlantumlFilter, lib: true do
it 'should not replace plantuml pre tag with img tag if disabled' do it 'should not replace plantuml pre tag with img tag if disabled' do
stub_application_setting(plantuml_enabled: false) stub_application_setting(plantuml_enabled: false)
input = '<pre class="plantuml"><code>Bob -> Sara : Hello</code><pre>' input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
output = '<pre class="plantuml"><code>Bob -&gt; Sara : Hello</code><pre></pre></pre>' output = '<pre><code lang="plantuml">Bob -&gt; Sara : Hello</code></pre>'
doc = filter(input) doc = filter(input)
expect(doc.to_s).to eq output expect(doc.to_s).to eq output
...@@ -23,7 +23,7 @@ describe Banzai::Filter::PlantumlFilter, lib: true do ...@@ -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 it 'should not replace plantuml pre tag with img tag if url is invalid' do
stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid") 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>' 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) doc = filter(input)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment