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 +4 -4
- data/lib/asciidoctor-mermaid/extension.rb +4 -1
- data/lib/asciidoctor-mermaid/pdf.rb +44 -0
- data/lib/asciidoctor-mermaid/version.rb +1 -1
- data/spec/extension_spec.rb +7 -4
- data/spec/pdf_extension_spec.rb +22 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b562bc72d72c35ead0c58aeac9854f338118dd827c511d8f93145c52f51ce7
|
4
|
+
data.tar.gz: d4804028270f704bf76312b5383b49eb5428dbffed6cacb1568968ab907fabfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 }
|
data/spec/extension_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'asciidoctor'
|
2
|
-
require 'asciidoctor-mermaid'
|
3
|
-
require 'pry'
|
4
2
|
|
5
|
-
|
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
|
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
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.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
|
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
|