asciidoctor-mermaid 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor-mermaid/extension.rb +3 -2
- data/lib/asciidoctor-mermaid/pdf.rb +14 -9
- data/lib/asciidoctor-mermaid/version.rb +1 -1
- data/spec/extension_spec.rb +25 -1
- data/spec/pdf_extension_spec.rb +25 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6275fc0501bbfa03f17c82eb2dd86b750ca881042b2c749e614b1d046e440d33
|
4
|
+
data.tar.gz: 348cd60e6d9f67ff5a2537fcddf70b542e6937f87785def52cefd002baeb4197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c834f88d3e763e66898b88a316516087b001025cefe690aa85a1c4892dd1f6ff23d6c0c6fadd44b47e850bc193aed4a6141dc48c1a1b1aca58aa09d4d277739c
|
7
|
+
data.tar.gz: 57bfc15c788c8d0b0b5de8f36e461c26ef2e862faa7519e80f59dce08917aa9ddad1ec7c556a43d4d179c6d8a909a9e4888b3d1413e913cc902a0155bdacd8e3
|
@@ -6,9 +6,10 @@ 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.blocks.empty?
|
9
|
+
if block.respond_to?(:blocks) && !block.blocks.empty?
|
10
10
|
process(block)
|
11
|
-
elsif block.attributes
|
11
|
+
elsif block.respond_to?(:attributes) &&
|
12
|
+
block.attributes['style'] === 'source' &&
|
12
13
|
block.attributes['language'] === 'mermaid'
|
13
14
|
self.convert_block(block)
|
14
15
|
else
|
@@ -4,12 +4,13 @@ require 'digest/md5'
|
|
4
4
|
require 'tempfile'
|
5
5
|
require_relative 'cli'
|
6
6
|
|
7
|
-
class
|
7
|
+
class MermaidPDFTreeProcessor < Asciidoctor::Extensions::TreeProcessor
|
8
8
|
def process(document)
|
9
9
|
document.blocks.map! do |block|
|
10
|
-
if !block.blocks.empty?
|
10
|
+
if block.respond_to?(:blocks) && !block.blocks.empty?
|
11
11
|
process(block)
|
12
|
-
elsif block.attributes
|
12
|
+
elsif block.respond_to?(:attributes) &&
|
13
|
+
block.attributes['style'] === 'source' &&
|
13
14
|
block.attributes['language'] === 'mermaid'
|
14
15
|
self.convert_block(block)
|
15
16
|
else
|
@@ -22,23 +23,27 @@ class MermaidTreeProcessor < Asciidoctor::Extensions::TreeProcessor
|
|
22
23
|
protected
|
23
24
|
|
24
25
|
def convert_block(block)
|
25
|
-
|
26
|
-
|
26
|
+
image_contents = "data:image/png;base64," + Base64.strict_encode64(self.render_png(block.source))
|
27
|
+
|
27
28
|
Asciidoctor::Block.new block.parent,
|
28
29
|
:image,
|
29
30
|
attributes: {
|
30
31
|
'imagesdir' => nil,
|
31
|
-
'target' =>
|
32
|
+
'target' => image_contents,
|
32
33
|
'align' => 'center',
|
33
34
|
}
|
34
35
|
end
|
35
36
|
|
36
|
-
def
|
37
|
+
def render_png(content)
|
37
38
|
file_name = Digest::MD5.hexdigest(content)
|
38
39
|
output_file = Tempfile.new([file_name, '.png'])
|
39
40
|
::Asciidoctor::Mermaid::Cli.run(content, "-o#{output_file.path}")
|
40
|
-
|
41
|
+
|
42
|
+
# Tempfile will unlink the underlying PDF by the time bundling occurs. Therefore we need to
|
43
|
+
# read back in the data so that we can tell Asciidoctor to use an inline data uri.
|
44
|
+
# TODO: Does this event need to use a tmp file? Can mmdc return the contents directly?
|
45
|
+
File.read(output_file.path)
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
|
-
Asciidoctor::Extensions.register { treeprocessor
|
49
|
+
Asciidoctor::Extensions.register { treeprocessor MermaidPDFTreeProcessor }
|
data/spec/extension_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'asciidoctor'
|
2
|
+
require 'asciidoctor-mermaid'
|
2
3
|
|
3
4
|
mermaid_doc = <<-eos
|
4
5
|
lorem ipsum
|
@@ -9,14 +10,37 @@ flowchart LR
|
|
9
10
|
```
|
10
11
|
eos
|
11
12
|
|
13
|
+
array_handling = <<-eos
|
14
|
+
[glossary]
|
15
|
+
== Glossary
|
16
|
+
|
17
|
+
- [[g-foo, FOO]]
|
18
|
+
FOO::
|
19
|
+
|
20
|
+
This is the first entry
|
21
|
+
|
22
|
+
- [[g-bar, BAR]]
|
23
|
+
BAR::
|
24
|
+
|
25
|
+
This is the second entry
|
26
|
+
eos
|
27
|
+
|
12
28
|
describe 'extension' do
|
13
29
|
before do
|
14
30
|
Asciidoctor::Extensions.unregister_all
|
15
|
-
|
31
|
+
Asciidoctor::Extensions.register { treeprocessor MermaidTreeProcessor }
|
16
32
|
end
|
33
|
+
|
17
34
|
it 'renders a basic mermaid diagram' do
|
18
35
|
doc = Asciidoctor.convert mermaid_doc
|
19
36
|
expect(doc).to include('id="mermaid-')
|
20
37
|
expect(doc).to include('flowchart node text')
|
21
38
|
end
|
39
|
+
|
40
|
+
# On v0.3.0 this should fail with NoMethodError: undefined method `blocks' for #<Array...>
|
41
|
+
it 'renders a document containing arrays' do
|
42
|
+
doc = Asciidoctor.convert array_handling
|
43
|
+
expect(doc).to include('FOO')
|
44
|
+
expect(doc).to include('BAR')
|
45
|
+
end
|
22
46
|
end
|
data/spec/pdf_extension_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'asciidoctor'
|
2
|
+
require 'asciidoctor-mermaid/pdf'
|
2
3
|
|
3
4
|
mermaid_doc = <<-eos
|
4
5
|
lorem ipsum
|
@@ -9,14 +10,37 @@ flowchart LR
|
|
9
10
|
```
|
10
11
|
eos
|
11
12
|
|
13
|
+
array_handling = <<-eos
|
14
|
+
[glossary]
|
15
|
+
== Glossary
|
16
|
+
|
17
|
+
- [[g-foo, FOO]]
|
18
|
+
FOO::
|
19
|
+
|
20
|
+
This is the first entry
|
21
|
+
|
22
|
+
- [[g-bar, BAR]]
|
23
|
+
BAR::
|
24
|
+
|
25
|
+
This is the second entry
|
26
|
+
eos
|
27
|
+
|
12
28
|
describe 'pdf extension' do
|
13
29
|
before do
|
14
30
|
Asciidoctor::Extensions.unregister_all
|
15
|
-
|
31
|
+
Asciidoctor::Extensions.register { treeprocessor MermaidPDFTreeProcessor }
|
16
32
|
end
|
33
|
+
|
17
34
|
it 'renders a basic mermaid diagram' do
|
18
35
|
doc = Asciidoctor.convert mermaid_doc
|
19
36
|
expect(doc).to include('class="imageblock text-center"')
|
20
37
|
expect(doc).to include('<img src=')
|
21
38
|
end
|
39
|
+
|
40
|
+
# On v0.3.0 this should fail with NoMethodError: undefined method `blocks' for #<Array...>
|
41
|
+
it 'renders a document containing arrays' do
|
42
|
+
doc = Asciidoctor.convert array_handling
|
43
|
+
expect(doc).to include('FOO')
|
44
|
+
expect(doc).to include('BAR')
|
45
|
+
end
|
22
46
|
end
|
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.
|
4
|
+
version: 0.4.1
|
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-
|
11
|
+
date: 2022-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|