asciidoctor-xml-ast 0.1.0 → 0.2.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: f5787ab74943ac77f8d74feeacc44271123a213cc97ecf0b97c43eed74ac6b9d
4
- data.tar.gz: 4a80b86fe5ede21a76b77aaef3c43636b6e51b842af0f635252c2349d4719713
3
+ metadata.gz: d398d5cfbde670383fe6d8fd4adfcf5a25e486da4ce443671460a463b20873f1
4
+ data.tar.gz: c2d621080c90e79dd304bad61efa021ab4918905b078b8feb3adc0acb2d83d25
5
5
  SHA512:
6
- metadata.gz: c9a384773cbaa0b32d1a1b00fa77c811814b941a29e9c866618a695f8fa7e83cb390b2d6d1d28c2b3e75148e8867d7629888738964e3536f7f2423b5c569dcad
7
- data.tar.gz: f7751122d0b16ce7e7e7890303b316188d433d310fd1a3ab874d1dd6472c6d528287a6b029d36a2d24732d1f0e1e9c22701e2f6a6a6a431b104c8e3323242b82
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-xml
12
+ $ gem install asciidoctor-xml-ast
13
13
  ```
14
14
 
15
- Then, add the options `--require asciidoctor-ast-xml` and `--backend xml-ast`.
16
- For example:
15
+ The gem includes the executable `asciidoctor-xml-ast`, which you can use instead
16
+ of `asciidoctor`:
17
17
 
18
18
  ```console
19
- $ asciidoctor -r asciidoctor-ast-xml -b xml-ast document.adoc
19
+ $ asciidoctor-xml-ast document.adoc
20
20
  ```
21
21
 
22
- In the previous command, the output will be in the `document.ast.xml` file.
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
@@ -23,21 +23,35 @@ class AstConverter
23
23
  end
24
24
 
25
25
  node.attributes.each_pair do |name, value|
26
- if not value.nil?
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.1.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: