Commit 04c41cb3 authored by Guillaume Grossetie's avatar Guillaume Grossetie

Do not process PlantUML diagrams with Kroki if PlantUML is enabled

parent 8cb4c0dd
...@@ -14,13 +14,12 @@ module Banzai ...@@ -14,13 +14,12 @@ module Banzai
end.join(', ') end.join(', ')
def call def call
# QUESTION: should we make Kroki and PlantUML mutually exclusive? plantuml_enabled = settings.plantuml_enabled
# Potentially, Kroki and PlantUML could work side by side. diagram_selectors = ::Gitlab::Kroki::DIAGRAM_TYPES.map do |diagram_type|
# In fact, if both PlantUML and Kroki are enabled, PlantUML could still render PlantUML diagrams and Kroki could render the other diagrams? # if PlantUML is enabled, PlantUML diagrams will be processed by the PlantUML filter.
# Having said that, since Kroki can render PlantUML diagrams, maybe it will be confusing... %(pre[lang="#{diagram_type}"] > code) if (plantuml_enabled && diagram_type != 'plantuml') || !plantuml_enabled
# end.compact.join(', ')
# What about Mermaid? should we keep client side rendering for Mermaid? return doc unless settings.kroki_enabled && doc.at(diagram_selectors)
return doc unless settings.kroki_enabled && doc.at(DIAGRAM_SELECTORS)
diagram_format = "svg" diagram_format = "svg"
doc.css(DIAGRAM_SELECTORS).each do |node| doc.css(DIAGRAM_SELECTORS).each do |node|
......
...@@ -5,17 +5,37 @@ require 'spec_helper' ...@@ -5,17 +5,37 @@ require 'spec_helper'
RSpec.describe Banzai::Filter::KrokiFilter do RSpec.describe Banzai::Filter::KrokiFilter do
include FilterSpecHelper include FilterSpecHelper
it 'replaces nomnoml pre tag with img tag' do it 'replaces nomnoml pre tag with img tag if kroki is enabled' do
stub_application_setting(kroki_enabled: true, kroki_url: "http://localhost:8000") stub_application_setting(kroki_enabled: true, kroki_url: "http://localhost:8000")
doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>") doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>")
expect(doc.to_s).to eq '<img src="http://localhost:8000/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g==">' expect(doc.to_s).to eq '<img src="http://localhost:8000/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g==">'
end end
it 'does not replace nomnoml pre tag with img tag if disabled' do it 'replaces nomnoml pre tag with img tag if both kroki and plantuml are enabled' do
stub_application_setting(kroki_enabled: true,
kroki_url: "http://localhost:8000",
plantuml_enabled: true,
plantuml_url: "http://localhost:8080")
doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>")
expect(doc.to_s).to eq '<img src="http://localhost:8000/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g==">'
end
it 'does not replace nomnoml pre tag with img tag if kroki is disabled' do
stub_application_setting(kroki_enabled: false) stub_application_setting(kroki_enabled: false)
doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>") doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>")
expect(doc.to_s).to eq "<pre lang=\"nomnoml\"><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:&gt;[foul mouth]\n]</code></pre>" expect(doc.to_s).to eq "<pre lang=\"nomnoml\"><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:&gt;[foul mouth]\n]</code></pre>"
end end
it 'does not replace plantuml pre tag with img tag if both kroki and plantuml are enabled' do
stub_application_setting(kroki_enabled: true,
kroki_url: "http://localhost:8000",
plantuml_enabled: true,
plantuml_url: "http://localhost:8080")
doc = filter("<pre lang='plantuml'><code>Bob->Alice : hello</code></pre>")
expect(doc.to_s).to eq '<pre lang="plantuml"><code>Bob-&gt;Alice : hello</code></pre>'
end
end end
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