coradoc 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.docker/Dockerfile +1 -1
  3. data/.docker/docker-compose.yml +2 -2
  4. data/.editorconfig +15 -0
  5. data/CHANGELOG.md +4 -0
  6. data/README.md +4 -0
  7. data/Rakefile +10 -0
  8. data/coradoc.gemspec +11 -2
  9. data/exe/reverse_adoc +91 -0
  10. data/exe/w2a +72 -0
  11. data/lib/coradoc/document.rb +6 -6
  12. data/lib/coradoc/element/admonition.rb +8 -6
  13. data/lib/coradoc/element/attribute.rb +2 -2
  14. data/lib/coradoc/element/attribute_list.rb +94 -15
  15. data/lib/coradoc/element/audio.rb +14 -3
  16. data/lib/coradoc/element/author.rb +18 -14
  17. data/lib/coradoc/element/base.rb +69 -8
  18. data/lib/coradoc/element/block/core.rb +10 -6
  19. data/lib/coradoc/element/block/literal.rb +1 -1
  20. data/lib/coradoc/element/block/quote.rb +1 -1
  21. data/lib/coradoc/element/block/sourcecode.rb +2 -2
  22. data/lib/coradoc/element/break.rb +1 -1
  23. data/lib/coradoc/element/document_attributes.rb +6 -6
  24. data/lib/coradoc/element/header.rb +4 -2
  25. data/lib/coradoc/element/image/block_image.rb +13 -2
  26. data/lib/coradoc/element/image/core.rb +35 -5
  27. data/lib/coradoc/element/image/inline_image.rb +2 -2
  28. data/lib/coradoc/element/image.rb +0 -1
  29. data/lib/coradoc/element/inline/anchor.rb +4 -2
  30. data/lib/coradoc/element/inline/bold.rb +10 -4
  31. data/lib/coradoc/element/inline/cross_reference.rb +4 -2
  32. data/lib/coradoc/element/inline/hard_line_break.rb +1 -1
  33. data/lib/coradoc/element/inline/highlight.rb +12 -6
  34. data/lib/coradoc/element/inline/italic.rb +10 -4
  35. data/lib/coradoc/element/inline/link.rb +26 -10
  36. data/lib/coradoc/element/inline/monospace.rb +10 -4
  37. data/lib/coradoc/element/inline/quotation.rb +4 -1
  38. data/lib/coradoc/element/inline/subscript.rb +5 -2
  39. data/lib/coradoc/element/inline/superscript.rb +5 -2
  40. data/lib/coradoc/element/inline.rb +0 -1
  41. data/lib/coradoc/element/list/core.rb +10 -8
  42. data/lib/coradoc/element/list/definition.rb +19 -0
  43. data/lib/coradoc/element/list/ordered.rb +1 -1
  44. data/lib/coradoc/element/list/unordered.rb +1 -1
  45. data/lib/coradoc/element/list.rb +1 -1
  46. data/lib/coradoc/element/list_item.rb +9 -4
  47. data/lib/coradoc/element/list_item_definition.rb +32 -0
  48. data/lib/coradoc/element/paragraph.rb +5 -3
  49. data/lib/coradoc/element/revision.rb +20 -16
  50. data/lib/coradoc/element/section.rb +21 -4
  51. data/lib/coradoc/element/table.rb +36 -19
  52. data/lib/coradoc/element/text_element.rb +63 -17
  53. data/lib/coradoc/element/title.rb +27 -7
  54. data/lib/coradoc/element/video.rb +33 -6
  55. data/lib/coradoc/generator.rb +2 -2
  56. data/lib/coradoc/legacy_parser.rb +41 -41
  57. data/lib/coradoc/oscal.rb +2 -4
  58. data/lib/coradoc/parser/asciidoc/content.rb +15 -15
  59. data/lib/coradoc/parser/asciidoc/document_attributes.rb +1 -1
  60. data/lib/coradoc/parser/asciidoc/header.rb +6 -6
  61. data/lib/coradoc/parser/asciidoc/section.rb +1 -1
  62. data/lib/coradoc/reverse_adoc/LICENSE.txt +25 -0
  63. data/lib/coradoc/reverse_adoc/README.adoc +308 -0
  64. data/lib/coradoc/reverse_adoc/cleaner.rb +125 -0
  65. data/lib/coradoc/reverse_adoc/config.rb +73 -0
  66. data/lib/coradoc/reverse_adoc/converters/a.rb +47 -0
  67. data/lib/coradoc/reverse_adoc/converters/aside.rb +12 -0
  68. data/lib/coradoc/reverse_adoc/converters/audio.rb +25 -0
  69. data/lib/coradoc/reverse_adoc/converters/base.rb +104 -0
  70. data/lib/coradoc/reverse_adoc/converters/blockquote.rb +18 -0
  71. data/lib/coradoc/reverse_adoc/converters/br.rb +11 -0
  72. data/lib/coradoc/reverse_adoc/converters/bypass.rb +77 -0
  73. data/lib/coradoc/reverse_adoc/converters/code.rb +19 -0
  74. data/lib/coradoc/reverse_adoc/converters/div.rb +14 -0
  75. data/lib/coradoc/reverse_adoc/converters/dl.rb +55 -0
  76. data/lib/coradoc/reverse_adoc/converters/drop.rb +22 -0
  77. data/lib/coradoc/reverse_adoc/converters/em.rb +17 -0
  78. data/lib/coradoc/reverse_adoc/converters/figure.rb +21 -0
  79. data/lib/coradoc/reverse_adoc/converters/h.rb +38 -0
  80. data/lib/coradoc/reverse_adoc/converters/head.rb +19 -0
  81. data/lib/coradoc/reverse_adoc/converters/hr.rb +11 -0
  82. data/lib/coradoc/reverse_adoc/converters/ignore.rb +16 -0
  83. data/lib/coradoc/reverse_adoc/converters/img.rb +98 -0
  84. data/lib/coradoc/reverse_adoc/converters/li.rb +13 -0
  85. data/lib/coradoc/reverse_adoc/converters/mark.rb +15 -0
  86. data/lib/coradoc/reverse_adoc/converters/markup.rb +27 -0
  87. data/lib/coradoc/reverse_adoc/converters/math.rb +31 -0
  88. data/lib/coradoc/reverse_adoc/converters/ol.rb +60 -0
  89. data/lib/coradoc/reverse_adoc/converters/p.rb +19 -0
  90. data/lib/coradoc/reverse_adoc/converters/pass_through.rb +13 -0
  91. data/lib/coradoc/reverse_adoc/converters/pre.rb +51 -0
  92. data/lib/coradoc/reverse_adoc/converters/q.rb +12 -0
  93. data/lib/coradoc/reverse_adoc/converters/strong.rb +16 -0
  94. data/lib/coradoc/reverse_adoc/converters/sub.rb +18 -0
  95. data/lib/coradoc/reverse_adoc/converters/sup.rb +18 -0
  96. data/lib/coradoc/reverse_adoc/converters/table.rb +280 -0
  97. data/lib/coradoc/reverse_adoc/converters/td.rb +77 -0
  98. data/lib/coradoc/reverse_adoc/converters/text.rb +28 -0
  99. data/lib/coradoc/reverse_adoc/converters/th.rb +14 -0
  100. data/lib/coradoc/reverse_adoc/converters/tr.rb +18 -0
  101. data/lib/coradoc/reverse_adoc/converters/video.rb +25 -0
  102. data/lib/coradoc/reverse_adoc/converters.rb +53 -0
  103. data/lib/coradoc/reverse_adoc/errors.rb +10 -0
  104. data/lib/coradoc/reverse_adoc/html_converter.rb +150 -0
  105. data/lib/coradoc/reverse_adoc/plugin.rb +131 -0
  106. data/lib/coradoc/reverse_adoc/plugins/plateau.rb +174 -0
  107. data/lib/coradoc/reverse_adoc/postprocessor.rb +148 -0
  108. data/lib/coradoc/reverse_adoc.rb +30 -0
  109. data/lib/coradoc/transformer.rb +24 -14
  110. data/lib/coradoc/version.rb +1 -1
  111. data/lib/reverse_adoc.rb +20 -0
  112. metadata +184 -5
  113. data/lib/coradoc/element/inline/image.rb +0 -25
@@ -3,15 +3,17 @@ require_relative "../inline/anchor"
3
3
  module Coradoc
4
4
  module Element
5
5
  module Block
6
- class Core
7
- attr_reader :title, :lines, :attributes, :lang, :id
6
+ class Core < Base
7
+ attr_accessor :title, :lines, :attributes, :lang, :id
8
+
9
+ declare_children :title, :lines, :attributes, :lang, :id
8
10
 
9
11
  def initialize(title, options = {})
10
12
  @title = title
11
13
  @lines = options.fetch(:lines, [])
12
14
  @type_str = options.fetch(:type, nil)
13
15
  @delimiter = options.fetch(:delimiter, "")
14
- @attributes = options.fetch(:attributes, {})
16
+ @attributes = options.fetch(:attributes, AttributeList.new)
15
17
  @lang = options.fetch(:lang, nil)
16
18
  @id = options.fetch(:id, nil)
17
19
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
@@ -28,11 +30,14 @@ module Coradoc
28
30
  def gen_title
29
31
  t = Coradoc::Generator.gen_adoc(@title)
30
32
  return "" if t.empty?
33
+
31
34
  ".#{t}\n"
32
35
  end
33
36
 
34
37
  def gen_attributes
35
- @attributes.nil? ? "" : "#{@attributes.to_adoc}\n"
38
+ attrs = @attributes.to_adoc(false)
39
+ return "#{attrs}\n" if !attrs.empty?
40
+ ""
36
41
  end
37
42
 
38
43
  def gen_delimiter
@@ -59,10 +64,9 @@ module Coradoc
59
64
  "****" => :side,
60
65
  "----" => :source,
61
66
  "====" => :example,
62
- "...." => :literal
67
+ "...." => :literal,
63
68
  }
64
69
  end
65
-
66
70
  end
67
71
  end
68
72
  end
@@ -2,7 +2,7 @@ module Coradoc
2
2
  module Element
3
3
  module Block
4
4
  class Literal < Core
5
- def initialize(title, options = {})
5
+ def initialize(_title, options = {})
6
6
  @id = options.fetch(:id, nil)
7
7
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
8
  @lines = options.fetch(:lines, [])
@@ -4,7 +4,7 @@ module Coradoc
4
4
  class Quote < Core
5
5
  def initialize(title, options = {})
6
6
  @title = title
7
- @attributes = options.fetch(:attributes, {})
7
+ @attributes = options.fetch(:attributes, AttributeList.new)
8
8
  @lines = options.fetch(:lines, [])
9
9
  @delimiter_char = "_"
10
10
  @delimiter_len = options.fetch(:delimiter_len, 4)
@@ -2,10 +2,10 @@ module Coradoc
2
2
  module Element
3
3
  module Block
4
4
  class SourceCode < Core
5
- def initialize(title, options = {})
5
+ def initialize(_title, options = {})
6
6
  @id = options.fetch(:id, nil)
7
7
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
- @lang = options.fetch(:lang, '')
8
+ @lang = options.fetch(:lang, "")
9
9
  @lines = options.fetch(:lines, [])
10
10
  @delimiter_char = "-"
11
11
  @delimiter_len = options.fetch(:delimiter_len, 4)
@@ -1,7 +1,7 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Break
4
- class ThematicBreak
4
+ class ThematicBreak < Base
5
5
  def to_adoc
6
6
  "\n* * *\n"
7
7
  end
@@ -1,7 +1,9 @@
1
1
  module Coradoc
2
2
  module Element
3
- class DocumentAttributes
4
- attr_reader :data
3
+ class DocumentAttributes < Base
4
+ attr_accessor :data
5
+
6
+ declare_children :data
5
7
 
6
8
  def initialize(data = {}, options = {})
7
9
  @data = data
@@ -9,10 +11,8 @@ module Coradoc
9
11
  end
10
12
 
11
13
  def to_hash
12
- Hash.new.tap do |hash|
13
- data.each do |attribute|
14
- hash[attribute.key.to_s] = attribute.value.to_s.gsub("'", "")
15
- end
14
+ data.to_h do |attribute|
15
+ [attribute.key.to_s, attribute.value.to_s.gsub("'", "")]
16
16
  end
17
17
  end
18
18
  end
@@ -1,7 +1,9 @@
1
1
  module Coradoc
2
2
  module Element
3
- class Header
4
- attr_reader :title, :author, :revision
3
+ class Header < Base
4
+ attr_accessor :title, :author, :revision
5
+
6
+ declare_children :title
5
7
 
6
8
  def initialize(title, options = {})
7
9
  @title = title
@@ -2,10 +2,21 @@ module Coradoc
2
2
  module Element
3
3
  module Image
4
4
  class BlockImage < Core
5
- def initialize(title, id, src, options = ())
6
- super(title, id, src, options)
5
+ def initialize(title, id, src, options = {})
6
+ super
7
7
  @colons = "::"
8
8
  end
9
+
10
+ def validate_named
11
+ @attributes.validate_named(VALIDATORS_NAMED, VALIDATORS_NAMED_BLOCK)
12
+ end
13
+
14
+ extend AttributeList::Matchers
15
+ VALIDATORS_NAMED_BLOCK = {
16
+ caption: String,
17
+ align: one("left", "center", "right"),
18
+ float: one("left", "right"),
19
+ }
9
20
  end
10
21
  end
11
22
  end
@@ -1,23 +1,53 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Image
4
- class Core
5
- attr_reader :title, :id, :src, :attributes
6
- def initialize(title, id, src, options = ())
4
+ class Core < Base
5
+ attr_accessor :title, :id, :src, :attributes
6
+
7
+ declare_children :id, :src, :title, :attributes
8
+
9
+ def initialize(title, id, src, options = {})
7
10
  @title = title
8
11
  @id = id
9
12
  @anchor = @id.nil? ? nil : Coradoc::Element::Inline::Anchor.new(@id)
10
13
  @src = src
11
- @attributes = options.fetch(:attributes, [])
14
+ @attributes = options.fetch(:attributes, AttributeList.new)
12
15
  @title = options.fetch(:title, nil)
16
+ if @attributes.any?
17
+ @attributes.validate_positional(VALIDATORS_POSITIONAL)
18
+ @attributes.validate_named(VALIDATORS_NAMED)
19
+ end
13
20
  end
14
21
 
15
22
  def to_adoc
16
23
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
17
24
  title = ".#{@title}\n" unless @title.to_s.empty?
18
- attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
25
+ attrs = @attributes.to_adoc
19
26
  [anchor, title, "image", @colons, @src, attrs].join("")
20
27
  end
28
+
29
+ extend AttributeList::Matchers
30
+ VALIDATORS_POSITIONAL = [
31
+ [:alt, String],
32
+ [:width, Integer],
33
+ [:height, Integer],
34
+ ]
35
+
36
+ VALIDATORS_NAMED = {
37
+ id: String,
38
+ alt: String,
39
+ fallback: String,
40
+ title: String,
41
+ width: Integer,
42
+ height: Integer,
43
+ link: String, # change to that URI regexp
44
+ window: String,
45
+ scale: Integer,
46
+ scaledwidth: /\A[0-9]{1,2}%\z/,
47
+ pdfwidth: /\A[0-9]+vw\z/,
48
+ role: many(/.*/, "left", "right", "th", "thumb", "related", "rel"),
49
+ opts: many("nofollow", "noopener", "inline", "interactive"),
50
+ }
21
51
  end
22
52
  end
23
53
  end
@@ -2,8 +2,8 @@ module Coradoc
2
2
  module Element
3
3
  module Image
4
4
  class InlineImage < Core
5
- def initialize(title, id, src, options = ())
6
- super(title, id, src, options)
5
+ def initialize(title, id, src, options = {})
6
+ super
7
7
  @colons = ":"
8
8
  end
9
9
  end
@@ -1,7 +1,6 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Image
4
-
5
4
  end
6
5
  end
7
6
  end
@@ -1,8 +1,10 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Anchor
5
- attr_reader :id
4
+ class Anchor < Base
5
+ attr_accessor :id
6
+
7
+ declare_children :id
6
8
 
7
9
  def initialize(id)
8
10
  @id = id
@@ -1,17 +1,23 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Bold
4
+ class Bold < Base
5
5
  attr_accessor :content, :unconstrained
6
- def initialize(content, unconstrained = true)
6
+
7
+ declare_children :content
8
+
9
+ def initialize(content, unconstrained: true)
7
10
  @content = content
8
11
  @unconstrained = unconstrained
9
12
  end
10
13
 
11
14
  def to_adoc
12
15
  content = Coradoc::Generator.gen_adoc(@content)
13
- doubled = @unconstrained ? "*" : ""
14
- "#{doubled}*#{content.strip}*#{doubled}#{content[/\s+$/]}"
16
+ if @unconstrained
17
+ "**#{content}**"
18
+ else
19
+ "*#{content}*"
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -1,8 +1,10 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class CrossReference
5
- attr_reader :href, :name
4
+ class CrossReference < Base
5
+ attr_accessor :href, :name
6
+
7
+ declare_children :href, :name
6
8
 
7
9
  def initialize(href, name = nil)
8
10
  @href = href
@@ -1,7 +1,7 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class HardLineBreak
4
+ class HardLineBreak < Base
5
5
  def to_adoc
6
6
  " +\n"
7
7
  end
@@ -1,17 +1,23 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Highlight
5
- attr_accessor :content
6
- def initialize(content, constrained = true)
4
+ class Highlight < Base
5
+ attr_accessor :content, :unconstrained
6
+
7
+ declare_children :content
8
+
9
+ def initialize(content, unconstrained: true)
7
10
  @content = content
8
- @constrained = constrained
11
+ @unconstrained = unconstrained
9
12
  end
10
13
 
11
14
  def to_adoc
12
15
  content = Coradoc::Generator.gen_adoc(@content)
13
- doubled = @constrained ? "" : "#"
14
- "#{content[/^\s*/]}#{doubled}##{content.strip}##{doubled}#{content[/\s*$/]}"
16
+ if @unconstrained
17
+ "###{content}##"
18
+ else
19
+ "##{content}#"
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -1,17 +1,23 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Italic
4
+ class Italic < Base
5
5
  attr_accessor :content, :unconstrained
6
- def initialize(content, unconstrained = true)
6
+
7
+ declare_children :content
8
+
9
+ def initialize(content, unconstrained: true)
7
10
  @content = content
8
11
  @unconstrained = unconstrained
9
12
  end
10
13
 
11
14
  def to_adoc
12
15
  content = Coradoc::Generator.gen_adoc(@content)
13
- doubled = @unconstrained ? "_" : ""
14
- "#{content[/^\s+/]}#{doubled}_#{content.strip}_#{doubled}#{content[/\s+$/]}"
16
+ if @unconstrained
17
+ "__#{content}__"
18
+ else
19
+ "_#{content}_"
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -1,23 +1,39 @@
1
+ require "uri"
2
+
1
3
  module Coradoc
2
4
  module Element
3
5
  module Inline
4
- class Link
5
- attr_reader :path, :title, :name
6
+ class Link < Base
7
+ attr_accessor :path, :title, :name, :right_constrain
8
+
9
+ declare_children :path, :title, :name
6
10
 
7
11
  def initialize(options = {})
8
- @path = options.fetch(:path,nil)
12
+ @path = options.fetch(:path, nil)
9
13
  @title = options.fetch(:title, nil)
10
- @name = options.fetch(:name,nil)
14
+ @name = options.fetch(:name, nil)
15
+ @right_constrain = options.fetch(:right_constrain, false)
11
16
  end
12
17
 
13
18
  def to_adoc
14
- link = @path.to_s =~ URI::DEFAULT_PARSER.make_regexp ? @path : "link:#{@path}"
15
- if @name.to_s.empty?
16
- link << "[#{@title}]"
17
- else
18
- link << "[#{@name}]"
19
+ link = @path
20
+ unless @path.to_s&.match?(URI::DEFAULT_PARSER.make_regexp)
21
+ link = "link:#{link}"
19
22
  end
20
- link.prepend(' ')
23
+
24
+ name_empty = @name.to_s.empty?
25
+ title_empty = @title.to_s.empty?
26
+ valid_empty_name_link = link.start_with?(%r{https?://})
27
+
28
+ link << if name_empty && !title_empty
29
+ "[#{@title}]"
30
+ elsif !name_empty
31
+ "[#{@name}]"
32
+ elsif valid_empty_name_link && !right_constrain
33
+ ""
34
+ else
35
+ "[]"
36
+ end
21
37
  link
22
38
  end
23
39
  end
@@ -1,17 +1,23 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Monospace
4
+ class Monospace < Base
5
5
  attr_accessor :content, :constrained
6
- def initialize(content, unconstrained = true)
6
+
7
+ declare_children :content
8
+
9
+ def initialize(content, unconstrained: true)
7
10
  @content = content
8
11
  @unconstrained = unconstrained
9
12
  end
10
13
 
11
14
  def to_adoc
12
15
  content = Coradoc::Generator.gen_adoc(@content)
13
- doubled = @unconstrained ? "`" : ""
14
- "#{doubled}`#{content}`#{doubled}"
16
+ if @unconstrained
17
+ "``#{content}``"
18
+ else
19
+ "`#{content}`"
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -1,8 +1,11 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Quotation
4
+ class Quotation < Base
5
5
  attr_accessor :content
6
+
7
+ declare_children :content
8
+
6
9
  def initialize(content)
7
10
  @content = content
8
11
  end
@@ -1,15 +1,18 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Subscript
4
+ class Subscript < Base
5
5
  attr_accessor :content
6
+
7
+ declare_children :content
8
+
6
9
  def initialize(content)
7
10
  @content = content
8
11
  end
9
12
 
10
13
  def to_adoc
11
14
  content = Coradoc::Generator.gen_adoc(@content)
12
- "#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
15
+ "~#{content}~"
13
16
  end
14
17
  end
15
18
  end
@@ -1,15 +1,18 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
- class Superscript
4
+ class Superscript < Base
5
5
  attr_accessor :content
6
+
7
+ declare_children :content
8
+
6
9
  def initialize(content)
7
10
  @content = content
8
11
  end
9
12
 
10
13
  def to_adoc
11
14
  content = Coradoc::Generator.gen_adoc(@content)
12
- "#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
15
+ "^#{content}^"
13
16
  end
14
17
  end
15
18
  end
@@ -1,7 +1,6 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
-
5
4
  end
6
5
  end
7
6
  end
@@ -4,32 +4,34 @@ require_relative "core"
4
4
  module Coradoc
5
5
  module Element
6
6
  module List
7
- class Core
8
- attr_reader :items, :prefix, :id, :ol_count, :anchor
7
+ class Core < Base
8
+ attr_accessor :items, :prefix, :id, :ol_count, :anchor
9
+
10
+ declare_children :items, :anchor, :id
9
11
 
10
12
  def initialize(items, options = {})
11
13
  @items = items
12
14
  @items = [@items] unless @items.is_a?(Array)
13
15
  @id = options.fetch(:id, nil)
14
16
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
15
- @ol_count = options.fetch(:ol_count, 0)
16
- @attrs = options.fetch(:attrs, nil)
17
+ @ol_count = options.fetch(:ol_count, 1)
18
+ @attrs = options.fetch(:attrs, AttributeList.new)
17
19
  end
18
20
 
19
21
  def to_adoc
22
+ anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
23
+ attrs = @attrs.to_adoc(false).to_s
20
24
  content = "\n"
21
25
  @items.each do |item|
22
26
  c = Coradoc::Generator.gen_adoc(item)
23
27
  if !c.empty?
24
- content << "#{prefix}"
28
+ content << prefix.to_s
29
+ content << " " if c[0]!=" "
25
30
  content << c
26
31
  end
27
32
  end
28
- anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}"
29
- attrs = @attrs.nil? ? "" : "#{@attrs.to_adoc}"
30
33
  "\n#{anchor}#{attrs}" + content
31
34
  end
32
-
33
35
  end
34
36
  end
35
37
  end
@@ -2,6 +2,25 @@ module Coradoc
2
2
  module Element
3
3
  module List
4
4
  class Definition < Core
5
+ attr_accessor :items, :delimiter
6
+
7
+ def initialize(items, options = {})
8
+ @items = items
9
+ @delimiter = options.fetch(:delimiter, "::")
10
+ # super(items, options)
11
+ end
12
+
13
+ def prefix
14
+ @delimiter
15
+ end
16
+
17
+ def to_adoc
18
+ content = "\n"
19
+ @items.each do |item|
20
+ content << item.to_adoc(@delimiter)
21
+ end
22
+ content
23
+ end
5
24
  end
6
25
  end
7
26
  end
@@ -7,7 +7,7 @@ module Coradoc
7
7
  end
8
8
 
9
9
  def prefix
10
- "." * [@ol_count, 0].max
10
+ "." * [@ol_count, 1].max
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module Coradoc
7
7
  end
8
8
 
9
9
  def prefix
10
- "*" * [@ol_count, 0].max
10
+ "*" * [@ol_count, 1].max
11
11
  end
12
12
  end
13
13
  end
@@ -1,12 +1,12 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module List
4
-
5
4
  end
6
5
  end
7
6
  end
8
7
 
9
8
  require_relative "list_item"
9
+ require_relative "list_item_definition"
10
10
  require_relative "list/core"
11
11
  require_relative "list/ordered"
12
12
  require_relative "list/unordered"
@@ -1,7 +1,9 @@
1
1
  module Coradoc
2
2
  module Element
3
- class ListItem
4
- attr_reader :id
3
+ class ListItem < Base
4
+ attr_accessor :id
5
+
6
+ declare_children :content, :id, :anchor
5
7
 
6
8
  def initialize(content, options = {})
7
9
  @content = content
@@ -10,8 +12,11 @@ module Coradoc
10
12
  end
11
13
 
12
14
  def to_adoc
13
- anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}"
14
- content = Coradoc::Generator.gen_adoc(@content).chomp
15
+ anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
16
+ content = Array(@content).map do |subitem|
17
+ Coradoc::Generator.gen_adoc(subitem).chomp
18
+ end.join("\n+\n")
19
+
15
20
  " #{anchor}#{content.chomp}\n"
16
21
  end
17
22
  end