coradoc 0.2.0 → 1.0.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/.docker/Dockerfile +1 -1
- data/.docker/docker-compose.yml +2 -2
- data/.editorconfig +15 -0
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/Rakefile +10 -0
- data/coradoc.gemspec +11 -2
- data/exe/reverse_adoc +91 -0
- data/exe/w2a +72 -0
- data/lib/coradoc/document.rb +6 -6
- data/lib/coradoc/element/admonition.rb +8 -6
- data/lib/coradoc/element/attribute.rb +2 -2
- data/lib/coradoc/element/attribute_list.rb +94 -15
- data/lib/coradoc/element/audio.rb +14 -3
- data/lib/coradoc/element/author.rb +18 -14
- data/lib/coradoc/element/base.rb +69 -8
- data/lib/coradoc/element/block/core.rb +10 -6
- data/lib/coradoc/element/block/literal.rb +1 -1
- data/lib/coradoc/element/block/quote.rb +1 -1
- data/lib/coradoc/element/block/sourcecode.rb +2 -2
- data/lib/coradoc/element/break.rb +1 -1
- data/lib/coradoc/element/document_attributes.rb +6 -6
- data/lib/coradoc/element/header.rb +4 -2
- data/lib/coradoc/element/image/block_image.rb +13 -2
- data/lib/coradoc/element/image/core.rb +35 -5
- data/lib/coradoc/element/image/inline_image.rb +2 -2
- data/lib/coradoc/element/image.rb +0 -1
- data/lib/coradoc/element/inline/anchor.rb +4 -2
- data/lib/coradoc/element/inline/bold.rb +10 -4
- data/lib/coradoc/element/inline/cross_reference.rb +4 -2
- data/lib/coradoc/element/inline/hard_line_break.rb +1 -1
- data/lib/coradoc/element/inline/highlight.rb +12 -6
- data/lib/coradoc/element/inline/italic.rb +10 -4
- data/lib/coradoc/element/inline/link.rb +26 -10
- data/lib/coradoc/element/inline/monospace.rb +10 -4
- data/lib/coradoc/element/inline/quotation.rb +4 -1
- data/lib/coradoc/element/inline/subscript.rb +5 -2
- data/lib/coradoc/element/inline/superscript.rb +5 -2
- data/lib/coradoc/element/inline.rb +0 -1
- data/lib/coradoc/element/list/core.rb +10 -8
- data/lib/coradoc/element/list/definition.rb +19 -0
- data/lib/coradoc/element/list/ordered.rb +1 -1
- data/lib/coradoc/element/list/unordered.rb +1 -1
- data/lib/coradoc/element/list.rb +1 -1
- data/lib/coradoc/element/list_item.rb +9 -4
- data/lib/coradoc/element/list_item_definition.rb +32 -0
- data/lib/coradoc/element/paragraph.rb +5 -3
- data/lib/coradoc/element/revision.rb +20 -16
- data/lib/coradoc/element/section.rb +21 -4
- data/lib/coradoc/element/table.rb +36 -19
- data/lib/coradoc/element/text_element.rb +63 -17
- data/lib/coradoc/element/title.rb +27 -7
- data/lib/coradoc/element/video.rb +33 -6
- data/lib/coradoc/generator.rb +2 -2
- data/lib/coradoc/legacy_parser.rb +41 -41
- data/lib/coradoc/oscal.rb +2 -4
- data/lib/coradoc/parser/asciidoc/content.rb +15 -15
- data/lib/coradoc/parser/asciidoc/document_attributes.rb +1 -1
- data/lib/coradoc/parser/asciidoc/header.rb +6 -6
- data/lib/coradoc/parser/asciidoc/section.rb +1 -1
- data/lib/coradoc/reverse_adoc/LICENSE.txt +25 -0
- data/lib/coradoc/reverse_adoc/README.adoc +308 -0
- data/lib/coradoc/reverse_adoc/cleaner.rb +125 -0
- data/lib/coradoc/reverse_adoc/config.rb +73 -0
- data/lib/coradoc/reverse_adoc/converters/a.rb +47 -0
- data/lib/coradoc/reverse_adoc/converters/aside.rb +12 -0
- data/lib/coradoc/reverse_adoc/converters/audio.rb +25 -0
- data/lib/coradoc/reverse_adoc/converters/base.rb +104 -0
- data/lib/coradoc/reverse_adoc/converters/blockquote.rb +18 -0
- data/lib/coradoc/reverse_adoc/converters/br.rb +11 -0
- data/lib/coradoc/reverse_adoc/converters/bypass.rb +77 -0
- data/lib/coradoc/reverse_adoc/converters/code.rb +19 -0
- data/lib/coradoc/reverse_adoc/converters/div.rb +14 -0
- data/lib/coradoc/reverse_adoc/converters/dl.rb +55 -0
- data/lib/coradoc/reverse_adoc/converters/drop.rb +22 -0
- data/lib/coradoc/reverse_adoc/converters/em.rb +17 -0
- data/lib/coradoc/reverse_adoc/converters/figure.rb +21 -0
- data/lib/coradoc/reverse_adoc/converters/h.rb +38 -0
- data/lib/coradoc/reverse_adoc/converters/head.rb +19 -0
- data/lib/coradoc/reverse_adoc/converters/hr.rb +11 -0
- data/lib/coradoc/reverse_adoc/converters/ignore.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/img.rb +98 -0
- data/lib/coradoc/reverse_adoc/converters/li.rb +13 -0
- data/lib/coradoc/reverse_adoc/converters/mark.rb +15 -0
- data/lib/coradoc/reverse_adoc/converters/markup.rb +27 -0
- data/lib/coradoc/reverse_adoc/converters/math.rb +31 -0
- data/lib/coradoc/reverse_adoc/converters/ol.rb +60 -0
- data/lib/coradoc/reverse_adoc/converters/p.rb +19 -0
- data/lib/coradoc/reverse_adoc/converters/pass_through.rb +13 -0
- data/lib/coradoc/reverse_adoc/converters/pre.rb +51 -0
- data/lib/coradoc/reverse_adoc/converters/q.rb +12 -0
- data/lib/coradoc/reverse_adoc/converters/strong.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/sub.rb +18 -0
- data/lib/coradoc/reverse_adoc/converters/sup.rb +18 -0
- data/lib/coradoc/reverse_adoc/converters/table.rb +280 -0
- data/lib/coradoc/reverse_adoc/converters/td.rb +77 -0
- data/lib/coradoc/reverse_adoc/converters/text.rb +28 -0
- data/lib/coradoc/reverse_adoc/converters/th.rb +14 -0
- data/lib/coradoc/reverse_adoc/converters/tr.rb +18 -0
- data/lib/coradoc/reverse_adoc/converters/video.rb +25 -0
- data/lib/coradoc/reverse_adoc/converters.rb +53 -0
- data/lib/coradoc/reverse_adoc/errors.rb +10 -0
- data/lib/coradoc/reverse_adoc/html_converter.rb +150 -0
- data/lib/coradoc/reverse_adoc/plugin.rb +131 -0
- data/lib/coradoc/reverse_adoc/plugins/plateau.rb +174 -0
- data/lib/coradoc/reverse_adoc/postprocessor.rb +148 -0
- data/lib/coradoc/reverse_adoc.rb +30 -0
- data/lib/coradoc/transformer.rb +24 -14
- data/lib/coradoc/version.rb +1 -1
- data/lib/reverse_adoc.rb +20 -0
- metadata +184 -5
- 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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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,9 @@
|
|
|
1
1
|
module Coradoc
|
|
2
2
|
module Element
|
|
3
|
-
class DocumentAttributes
|
|
4
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
|
@@ -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
|
|
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
|
-
|
|
6
|
-
|
|
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.
|
|
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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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 Highlight
|
|
5
|
-
attr_accessor :content
|
|
6
|
-
|
|
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
|
-
@
|
|
11
|
+
@unconstrained = unconstrained
|
|
9
12
|
end
|
|
10
13
|
|
|
11
14
|
def to_adoc
|
|
12
15
|
content = Coradoc::Generator.gen_adoc(@content)
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
link
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
16
|
+
if @unconstrained
|
|
17
|
+
"``#{content}``"
|
|
18
|
+
else
|
|
19
|
+
"`#{content}`"
|
|
20
|
+
end
|
|
15
21
|
end
|
|
16
22
|
end
|
|
17
23
|
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
|
-
"
|
|
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
|
-
"
|
|
15
|
+
"^#{content}^"
|
|
13
16
|
end
|
|
14
17
|
end
|
|
15
18
|
end
|
|
@@ -4,32 +4,34 @@ require_relative "core"
|
|
|
4
4
|
module Coradoc
|
|
5
5
|
module Element
|
|
6
6
|
module List
|
|
7
|
-
class Core
|
|
8
|
-
|
|
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,
|
|
16
|
-
@attrs = options.fetch(:attrs,
|
|
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 <<
|
|
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
|
data/lib/coradoc/element/list.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module Coradoc
|
|
2
2
|
module Element
|
|
3
|
-
class ListItem
|
|
4
|
-
|
|
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? ? "" :
|
|
14
|
-
content =
|
|
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
|