asciidoctor-xml-ast 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/bin/asciidoctor-xml-ast +15 -0
- data/lib/asciidoctor-xml-ast.rb +34 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d398d5cfbde670383fe6d8fd4adfcf5a25e486da4ce443671460a463b20873f1
|
4
|
+
data.tar.gz: c2d621080c90e79dd304bad61efa021ab4918905b078b8feb3adc0acb2d83d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03d02b57a7586834e9d1c7e84d1495bc6e914f8db3fe9e3d92bfcd5fb3af7f39a6c8416c33afbecdfeb36d37d5ab0f912034a72bd7637fe981b05b2bb6691440
|
7
|
+
data.tar.gz: 31a94f7bf8e53731aaf149062760275d30aa676e881f359ec8f9907b51e3b7f36772ba4cfb2e963d7875f4cf9b2b49f5bc5b6f08976f80aff184723d486a07b0
|
data/README.md
CHANGED
@@ -9,17 +9,24 @@ The converter is available as a Ruby gem, and can be installed with the
|
|
9
9
|
following command:
|
10
10
|
|
11
11
|
```console
|
12
|
-
$ gem install asciidoctor-ast
|
12
|
+
$ gem install asciidoctor-xml-ast
|
13
13
|
```
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
The gem includes the executable `asciidoctor-xml-ast`, which you can use instead
|
16
|
+
of `asciidoctor`:
|
17
17
|
|
18
18
|
```console
|
19
|
-
$ asciidoctor
|
19
|
+
$ asciidoctor-xml-ast document.adoc
|
20
20
|
```
|
21
21
|
|
22
|
-
|
22
|
+
Alternatively, you can invoke `asciidoctor` directly, and add the options
|
23
|
+
`--require asciidoctor-ast-xml` and `--backend xml-ast`:
|
24
|
+
|
25
|
+
```console
|
26
|
+
$ asciidoctor -r asciidoctor-xml-ast -b xml-ast document.adoc
|
27
|
+
```
|
28
|
+
|
29
|
+
In the previous examples, the output will be in the `document.ast.xml` file.
|
23
30
|
|
24
31
|
## Example
|
25
32
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "asciidoctor"
|
4
|
+
require "asciidoctor/cli"
|
5
|
+
|
6
|
+
lib = File.expand_path("../../lib/asciidoctor-xml-ast.rb", __FILE__)
|
7
|
+
if not File.exist?(lib)
|
8
|
+
lib = "asciidoctor-xml-ast"
|
9
|
+
end
|
10
|
+
|
11
|
+
args = %W(--require #{lib} --backend xml-ast) + ARGV
|
12
|
+
|
13
|
+
invoker = Asciidoctor::Cli::Invoker.new(args)
|
14
|
+
invoker.invoke!
|
15
|
+
exit invoker.code
|
data/lib/asciidoctor-xml-ast.rb
CHANGED
@@ -23,21 +23,35 @@ class AstConverter
|
|
23
23
|
end
|
24
24
|
|
25
25
|
node.attributes.each_pair do |name, value|
|
26
|
-
if
|
26
|
+
next if value.nil?
|
27
|
+
|
28
|
+
Array(value).each do |value|
|
29
|
+
if value.kind_of?(Asciidoctor::Document::AttributeEntry)
|
30
|
+
value = value.value
|
31
|
+
end
|
32
|
+
|
27
33
|
value = CGI.escapeHTML(value.to_s)
|
28
34
|
attributes << %[ attr-#{name}="#{value}"]
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
38
|
+
if transform == "table" and node.title?
|
39
|
+
attributes << %[ table-caption="#{node.captioned_title}"]
|
40
|
+
end
|
41
|
+
|
32
42
|
# Element body.
|
33
43
|
result = []
|
34
44
|
|
35
45
|
result << "<#{element_name}#{attributes.join}>"
|
36
46
|
|
37
|
-
if node.respond_to?(:text)
|
47
|
+
if node.respond_to?(:text) and transform != "table_cell"
|
38
48
|
result << node.text
|
39
49
|
end
|
40
50
|
|
51
|
+
if transform == "table"
|
52
|
+
convert_table(result, node)
|
53
|
+
end
|
54
|
+
|
41
55
|
if node.block?
|
42
56
|
append_content(result, node.content)
|
43
57
|
end
|
@@ -46,6 +60,24 @@ class AstConverter
|
|
46
60
|
result.join
|
47
61
|
end
|
48
62
|
|
63
|
+
def convert_table(result, node)
|
64
|
+
node.rows.to_h.each do |section, rows|
|
65
|
+
next if rows.empty?
|
66
|
+
|
67
|
+
section_element = "table-#{section}"
|
68
|
+
|
69
|
+
result << "<#{section_element}>"
|
70
|
+
rows.each do |row|
|
71
|
+
result << "<table-row>"
|
72
|
+
row.each do |cell|
|
73
|
+
result << cell.convert
|
74
|
+
end
|
75
|
+
result << "</table-row>"
|
76
|
+
end
|
77
|
+
result << "</#{section_element}>"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
49
81
|
def append_content(result, content)
|
50
82
|
case content
|
51
83
|
when Array
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-xml-ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ayosec
|
@@ -28,11 +28,13 @@ description: |2
|
|
28
28
|
Asciidoctor converter to generate a XML file with the syntax
|
29
29
|
nodes from a parsed document.
|
30
30
|
email:
|
31
|
-
executables:
|
31
|
+
executables:
|
32
|
+
- asciidoctor-xml-ast
|
32
33
|
extensions: []
|
33
34
|
extra_rdoc_files: []
|
34
35
|
files:
|
35
36
|
- README.md
|
37
|
+
- bin/asciidoctor-xml-ast
|
36
38
|
- lib/asciidoctor-xml-ast.rb
|
37
39
|
homepage: https://github.com/ayosec/asciidoctor-xml-ast
|
38
40
|
licenses:
|