From d6b081a9d84994be7b838b1b74152bc9e5c712b3 Mon Sep 17 00:00:00 2001 From: Juracy Filho Date: Wed, 26 May 2021 00:40:17 -0300 Subject: [PATCH] resolves #245 adding support for pikchr --- README.md | 1 + .../extensions/asciidoctor_kroki/extension.rb | 1 + ruby/spec/asciidoctor_kroki_spec.rb | 2 +- src/asciidoctor-kroki.js | 1 + test/test.spec.js | 50 +++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19bc2bea..097613e5 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ Kroki currently supports the following diagram libraries: * [Nomnoml](https://github.com/skanaar/nomnoml): `nomnoml` * [NwDiag](https://github.com/blockdiag/nwdiag): `nwdiag` * [PacketDiag](https://github.com/blockdiag/nwdiag): `packetdiag` +* [Pikchr](https://github.com/drhsqlite/pikchr): `pikchr` * [PlantUML](https://github.com/plantuml/plantuml): `plantuml` * [RackDiag](https://github.com/blockdiag/nwdiag): `rackdiag` * [SeqDiag](https://github.com/blockdiag/seqdiag): `seqdiag` diff --git a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb index 2f734b07..7a11ee3d 100644 --- a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb +++ b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb @@ -117,6 +117,7 @@ module Kroki nomnoml nwdiag packetdiag + pikchr plantuml rackdiag seqdiag diff --git a/ruby/spec/asciidoctor_kroki_spec.rb b/ruby/spec/asciidoctor_kroki_spec.rb index c8976bf1..ff8f1e0d 100644 --- a/ruby/spec/asciidoctor_kroki_spec.rb +++ b/ruby/spec/asciidoctor_kroki_spec.rb @@ -146,7 +146,7 @@ describe ::AsciidoctorExtensions::Kroki do it 'should return the list of supported diagrams' do diagram_names = ::AsciidoctorExtensions::Kroki::SUPPORTED_DIAGRAM_NAMES - expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw', 'wavedrom') + expect(diagram_names).to include('vegalite', 'plantuml', 'bytefield', 'bpmn', 'excalidraw', 'wavedrom', 'pikchr') end it 'should register the extension for the list of supported diagrams' do doc = Asciidoctor::Document.new diff --git a/src/asciidoctor-kroki.js b/src/asciidoctor-kroki.js index b22002fa..591847a1 100644 --- a/src/asciidoctor-kroki.js +++ b/src/asciidoctor-kroki.js @@ -212,6 +212,7 @@ module.exports.register = function register (registry, context = {}) { 'nomnoml', 'nwdiag', 'packetdiag', + 'pikchr', 'plantuml', 'rackdiag', 'seqdiag', diff --git a/test/test.spec.js b/test/test.spec.js index 31ac2fc6..5c613310 100644 --- a/test/test.spec.js +++ b/test/test.spec.js @@ -31,6 +31,7 @@ describe('Registration', () => { expect(registry['$registered_for_block_macro?']('rackdiag')).to.be.an('object') expect(registry['$registered_for_block_macro?']('wavedrom')).to.be.an('object') expect(registry['$registered_for_block_macro?']('excalidraw')).to.be.an('object') + expect(registry['$registered_for_block_macro?']('pikchr')).to.be.an('object') }) }) @@ -917,6 +918,55 @@ rackdiag { expect(html).to.contain('https://kroki.io/bytefield/svg/eNrTSClKLNdNzs8pzc3TzUhNTEktKtbk0gCLJuVXKCg5pqQUpRYXKylUWxUXJOYpmNSiSAdnVqXC5YxQ5AwwhdMTCxSUAhIrc_ITU5QQaktK8nM1AW7MLSU') expect(html).to.contain('
') }) + it('should convert a Pikchr diagram to an image', () => { + const input = ` +[pikchr] +.... +$r = 0.2in +linerad = 0.75*$r +linewid = 0.25 + +# Start and end blocks +# +box "element" bold fit +line down 50% from last box.sw +dot rad 250% color black +X0: last.e + (0.3,0) +arrow from last dot to X0 +move right 3.9in +box wid 5% ht 25% fill black +X9: last.w - (0.3,0) +arrow from X9 to last box.w + + +# The main rule that goes straight through from start to finish +# +box "object-definition" italic fit at 11/16 way between X0 and X9 +arrow to X9 +arrow from X0 to last box.w + +# The LABEL: rule +# +arrow right $r from X0 then down 1.25*$r then right $r +oval " LABEL " fit +arrow 50% +oval "\\":\\"" fit +arrow 200% +box "position" italic fit +arrow +line right until even with X9 - ($r,0) \ + then up until even with X9 then to X9 +arrow from last oval.e right $r*0.5 then up $r*0.8 right $r*0.8 +line up $r*0.45 right $r*0.45 then right +.... +` + const registry = asciidoctor.Extensions.create() + asciidoctorKroki.register(registry) + const html = asciidoctor.convert(input, { extension_registry: registry }) + expect(html).to.contain('https://kroki.io/pikchr/svg/eNptUk1T2zAQvetX7Jgww0cxisEUZ6aHdoYbNzjkwEW2lVhF0TLyJqL_vispSV3g4NFo3-rt2_c88_ADZFkZJ6xx2qs-3b_XFzOfKsHkSlULcQJPpDyBcj1o_lqL3esoTkSL71BoqzfaUQEt2h5WhtJ76DE4qOUprDxuwKqRuOG9HIPokSAOrCLaoUXPjKp7FUu5SI2lhks4k-XNN3kulPcYJiTxNSEspdjgToM364Hgpmx4kygn6q5PgWsVHytj7YG82ZMHuPqKfNlE2qPOIOLez4OGjTIO_NZqoEERrFGPMJJXaTANHrfrIVOMySVmWRlnxuFgELa_dUdXvY5lMugKMKSs6aJZwJTz-fX8DoL6A62moLXj7ZLZy2avMC7c_KdWflSbxT7-_PXwuEhyeXx-kC2a-X8vBx6R8plzvpx4rhz6BO6UhSJz8RkjzUwc2B58KRYvxRSqJGNp3TccP22Zm_KPkcdsHRkLesdzg6Eh2s-xzDynApD1bN--6krQJz-SE1FaqY97XMiyPjKl6_0Uu89yDthtPQVv64knfwGrmf6K') + + expect(html).to.contain('
') + }) it('should convert a Vega-Lite diagram and resolve data.url relative to the diagram file', async () => { const registry = asciidoctor.Extensions.create() asciidoctorKroki.register(registry)