asciidoctor-mermaid 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf054c6571d774e0c343d901f9f8891a49132718b417aaad6289f3062e254457
4
- data.tar.gz: 19325bd648918a4aa728aca18979d591075d4cb380f62f175b0746ba9da10ae0
3
+ metadata.gz: 58b562bc72d72c35ead0c58aeac9854f338118dd827c511d8f93145c52f51ce7
4
+ data.tar.gz: d4804028270f704bf76312b5383b49eb5428dbffed6cacb1568968ab907fabfd
5
5
  SHA512:
6
- metadata.gz: 05ff0b4ddd38f36c531665c5fc775be5790159cd0c25ba043f102bad97bf51224af794a5cea3605ad52fcc3ffbed444851b0d2b1a5997d585533a423c4c134cb
7
- data.tar.gz: 51e6e80ee1e9db6b942d52a151507409a6355b535679598e6fffa4ce804cc534c3e30a0841627cdfa8efc042877936a16cc5b79f18e65f0977388f78988bcf4e
6
+ metadata.gz: b777dd329e10488527dce93d7e02603850b2bec4ba1504215a22a6401d224c9872ce4c3e1602333ab7a27b989379f1ec55b2e2beb0d47480f9683c690319bf8a
7
+ data.tar.gz: ee96b36f01f0983e61ebe541c640d881f6ca68edcce4cc3e615f23dbf8ba13580d5dc7dcd86d19372e3ce99cc2a06576d4d77e99d2c30614cc9b8353bd5aa997
@@ -6,13 +6,16 @@ require_relative 'cli'
6
6
  class MermaidTreeProcessor < Asciidoctor::Extensions::TreeProcessor
7
7
  def process(document)
8
8
  document.blocks.map! do |block|
9
- if block.attributes['style'] === 'source' &&
9
+ if !block.blocks.empty?
10
+ process(block)
11
+ elsif block.attributes['style'] === 'source' &&
10
12
  block.attributes['language'] === 'mermaid'
11
13
  self.convert_block(block)
12
14
  else
13
15
  block
14
16
  end
15
17
  end
18
+ document
16
19
  end
17
20
 
18
21
  protected
@@ -0,0 +1,44 @@
1
+ # An alternative entry point to be used w/ asciidoctor-pdf
2
+ require 'asciidoctor/extensions'
3
+ require 'digest/md5'
4
+ require 'tempfile'
5
+ require_relative 'cli'
6
+
7
+ class MermaidTreeProcessor < Asciidoctor::Extensions::TreeProcessor
8
+ def process(document)
9
+ document.blocks.map! do |block|
10
+ if !block.blocks.empty?
11
+ process(block)
12
+ elsif block.attributes['style'] === 'source' &&
13
+ block.attributes['language'] === 'mermaid'
14
+ self.convert_block(block)
15
+ else
16
+ block
17
+ end
18
+ end
19
+ document
20
+ end
21
+
22
+ protected
23
+
24
+ def convert_block(block)
25
+ # TODO: Currently I'm unsure how to clean up tmp images after pdf generation completes
26
+ img = self.render_svg(block.source)
27
+ Asciidoctor::Block.new block.parent,
28
+ :image,
29
+ attributes: {
30
+ 'imagesdir' => nil,
31
+ 'target' => img.path,
32
+ 'align' => 'center',
33
+ }
34
+ end
35
+
36
+ def render_svg(content)
37
+ file_name = Digest::MD5.hexdigest(content)
38
+ output_file = Tempfile.new([file_name, '.png'])
39
+ ::Asciidoctor::Mermaid::Cli.run(content, "-o#{output_file.path}")
40
+ output_file
41
+ end
42
+ end
43
+
44
+ Asciidoctor::Extensions.register { treeprocessor MermaidTreeProcessor }
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Mermaid
3
- VERSION = '0.1.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -1,8 +1,6 @@
1
1
  require 'asciidoctor'
2
- require 'asciidoctor-mermaid'
3
- require 'pry'
4
2
 
5
- MERMAID_DOC = <<-eos
3
+ mermaid_doc = <<-eos
6
4
  lorem ipsum
7
5
 
8
6
  ```mermaid
@@ -12,8 +10,13 @@ flowchart LR
12
10
  eos
13
11
 
14
12
  describe 'extension' do
13
+ before do
14
+ Asciidoctor::Extensions.unregister_all
15
+ require 'asciidoctor-mermaid'
16
+ end
15
17
  it 'renders a basic mermaid diagram' do
16
- doc = Asciidoctor.convert MERMAID_DOC
18
+ doc = Asciidoctor.convert mermaid_doc
19
+ expect(doc).to include('id="mermaid-')
17
20
  expect(doc).to include('flowchart node text')
18
21
  end
19
22
  end
@@ -0,0 +1,22 @@
1
+ require 'asciidoctor'
2
+
3
+ mermaid_doc = <<-eos
4
+ lorem ipsum
5
+
6
+ ```mermaid
7
+ flowchart LR
8
+ id1[flowchart node text]
9
+ ```
10
+ eos
11
+
12
+ describe 'pdf extension' do
13
+ before do
14
+ Asciidoctor::Extensions.unregister_all
15
+ require 'asciidoctor-mermaid/pdf'
16
+ end
17
+ it 'renders a basic mermaid diagram' do
18
+ doc = Asciidoctor.convert mermaid_doc
19
+ expect(doc).to include('class="imageblock text-center"')
20
+ expect(doc).to include('<img src=')
21
+ end
22
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'rspec/snapshot'
1
+ require 'asciidoctor'
2
2
 
3
3
  # This file was generated by the `rspec --init` command. Conventionally, all
4
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-mermaid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Bennett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-05 00:00:00.000000000 Z
11
+ date: 2022-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,8 +104,10 @@ files:
104
104
  - lib/asciidoctor-mermaid.rb
105
105
  - lib/asciidoctor-mermaid/cli.rb
106
106
  - lib/asciidoctor-mermaid/extension.rb
107
+ - lib/asciidoctor-mermaid/pdf.rb
107
108
  - lib/asciidoctor-mermaid/version.rb
108
109
  - spec/extension_spec.rb
110
+ - spec/pdf_extension_spec.rb
109
111
  - spec/spec_helper.rb
110
112
  homepage: https://github.com/oxidecomputer/asciidoctor-mermaid
111
113
  licenses:
@@ -133,4 +135,5 @@ summary: An Asciidoctor extension that transforms Mermaid diagrams in markdown c
133
135
  to inline svgs.
134
136
  test_files:
135
137
  - spec/extension_spec.rb
138
+ - spec/pdf_extension_spec.rb
136
139
  - spec/spec_helper.rb