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
end.join(', ')
def call
# QUESTION: should we make Kroki and PlantUML mutually exclusive?
# Potentially, Kroki and PlantUML could work side by side.
# In fact, if both PlantUML and Kroki are enabled, PlantUML could still render PlantUML diagrams and Kroki could render the other diagrams?
# Having said that, since Kroki can render PlantUML diagrams, maybe it will be confusing...
#
# What about Mermaid? should we keep client side rendering for Mermaid?
return doc unless settings.kroki_enabled && doc.at(DIAGRAM_SELECTORS)
plantuml_enabled = settings.plantuml_enabled
diagram_selectors = ::Gitlab::Kroki::DIAGRAM_TYPES.map do |diagram_type|
# if PlantUML is enabled, PlantUML diagrams will be processed by the PlantUML filter.
%(pre[lang="#{diagram_type}"] > code) if (plantuml_enabled && diagram_type != 'plantuml') || !plantuml_enabled
end.compact.join(', ')
return doc unless settings.kroki_enabled && doc.at(diagram_selectors)
diagram_format = "svg"
doc.css(DIAGRAM_SELECTORS).each do |node|
......
......@@ -5,17 +5,37 @@ require 'spec_helper'
RSpec.describe Banzai::Filter::KrokiFilter do
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")
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 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)
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>"
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
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