Skip to content

Commit

Permalink
Remove env-idea logic (use kroki-default-format instead)
Browse files Browse the repository at this point in the history
The env-idea attribute leaked from an early version of this library that was used in an IntelliJ environment,and doesn't make sense in the more general usage of this library. kroki-default-format has already been implemented in the JavaScript version of this library.
  • Loading branch information
ahus1 authored and ggrossetie committed Oct 18, 2021
1 parent ca912b3 commit 86340a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
12 changes: 6 additions & 6 deletions ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ def get_role(format, role)
end

def get_format(doc, attrs, diagram_type)
format = attrs['format'] || 'svg'
# The JavaFX preview doesn't support SVG well, therefore we'll use PNG format...
if doc.attr?('env-idea') && format == 'svg'
# ... unless the diagram library does not support PNG as output format!
format = attrs['format'] || doc.attr('kroki-default-format') || 'svg'
if format == 'png'
# redirect PNG format to SVG if the diagram library only supports SVG as output format.
# this is useful when the default format has been set to PNG
# Currently, mermaid, nomnoml, svgbob, wavedrom only support SVG as output format.
svg_only_diagram_types = %w[:mermaid :nomnoml :svgbob :wavedrom]
format = 'png' unless svg_only_diagram_types.include?(diagram_type)
svg_only_diagram_types = %i[mermaid nomnoml svgbob wavedrom]
format = 'svg' if svg_only_diagram_types.include?(diagram_type)
end
format
end
Expand Down
37 changes: 27 additions & 10 deletions ruby/spec/asciidoctor_kroki_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,33 @@
</div>
</div>)
end
it 'should use png if env-idea is defined' do
it 'should use png if kroki-default-format is set to png' do
input = <<~'ADOC'
[plantuml]
....
alice -> bob: hello
....
ADOC
output = Asciidoctor.convert(input, attributes: { 'env-idea' => '' }, standalone: false)
output = Asciidoctor.convert(input, attributes: { 'kroki-default-format' => 'png' }, standalone: false)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/plantuml/png/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
</div>
</div>)
end
it 'should use svg if kroki-default-format is set to png and the diagram type does not support png' do
input = <<~'ADOC'
[mermaid]
....
graph TD;
A-->B;
....
ADOC
output = Asciidoctor.convert(input, attributes: { 'kroki-default-format' => 'png' }, standalone: false)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/mermaid/svg/eNpLL0osyFAIcbHmUlBw1NW1c7IGADLKBKY=" alt="Diagram">
</div>
</div>)
end
it 'should include the plantuml-include file when safe mode is safe' do
Expand All @@ -41,10 +56,12 @@
alice -> bob: hello
....
ADOC
output = Asciidoctor.convert(input, attributes: { 'env-idea' => '', 'kroki-plantuml-include' => 'spec/fixtures/config.puml' }, standalone: false, safe: :safe)
output = Asciidoctor.convert(input,
attributes: { 'kroki-plantuml-include' => 'spec/fixtures/config.puml' },
standalone: false, safe: :safe)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/plantuml/png/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJKzMlMTlXQtVNIyk-yUshIzcnJBwCT9xBc" alt="Diagram">
<img src="https://kroki.io/plantuml/svg/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJKzMlMTlXQtVNIyk-yUshIzcnJBwCT9xBc" alt="Diagram">
</div>
</div>)
end
Expand All @@ -55,10 +72,10 @@
alice -> bob: hello
....
ADOC
output = Asciidoctor.convert(input, attributes: { 'env-idea' => '', 'kroki-plantuml-include' => '../../../spec/fixtures/config.puml' }, standalone: false, safe: :safe)
output = Asciidoctor.convert(input, attributes: { 'kroki-plantuml-include' => '../../../spec/fixtures/config.puml' }, standalone: false, safe: :safe)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/plantuml/png/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJKzMlMTlXQtVNIyk-yUshIzcnJBwCT9xBc" alt="Diagram">
<img src="https://kroki.io/plantuml/svg/eNorzs7MK0gsSsxVyM3Py0_OKMrPTVUoKSpN5eJKzMlMTlXQtVNIyk-yUshIzcnJBwCT9xBc" alt="Diagram">
</div>
</div>)
end
Expand All @@ -69,10 +86,10 @@
alice -> bob: hello
....
ADOC
output = Asciidoctor.convert(input, attributes: { 'env-idea' => '', 'kroki-plantuml-include' => '/etc/passwd' }, standalone: false, safe: :safe)
output = Asciidoctor.convert(input, attributes: { 'kroki-plantuml-include' => '/etc/passwd' }, standalone: false, safe: :safe)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/plantuml/png/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
</div>
</div>)
end
Expand All @@ -83,10 +100,10 @@
alice -> bob: hello
....
ADOC
output = Asciidoctor.convert(input, attributes: { 'env-idea' => '', 'kroki-plantuml-include' => 'spec/fixtures/config.puml' }, standalone: false, safe: :secure)
output = Asciidoctor.convert(input, attributes: { 'kroki-plantuml-include' => 'spec/fixtures/config.puml' }, standalone: false, safe: :secure)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/plantuml/png/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
</div>
</div>)
end
Expand Down

0 comments on commit 86340a2

Please sign in to comment.