coradoc 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.docker/Dockerfile +1 -1
- data/.docker/docker-compose.yml +2 -2
- data/.editorconfig +15 -0
- data/.pryrc.sample +1 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +10 -0
- data/coradoc.gemspec +11 -2
- data/exe/reverse_adoc +70 -0
- data/exe/w2a +72 -0
- data/lib/coradoc/document.rb +40 -23
- data/lib/coradoc/element/admonition.rb +13 -0
- data/lib/coradoc/{document → element}/attribute.rb +1 -1
- data/lib/coradoc/element/attribute_list.rb +46 -0
- data/lib/coradoc/element/audio.rb +22 -0
- data/lib/coradoc/element/author.rb +22 -0
- data/lib/coradoc/element/base.rb +15 -0
- data/lib/coradoc/element/block/core.rb +69 -0
- data/lib/coradoc/element/block/example.rb +22 -0
- data/lib/coradoc/element/block/literal.rb +19 -0
- data/lib/coradoc/element/block/quote.rb +19 -0
- data/lib/coradoc/element/block/side.rb +17 -0
- data/lib/coradoc/element/block/sourcecode.rb +20 -0
- data/lib/coradoc/element/block.rb +13 -0
- data/lib/coradoc/element/break.rb +11 -0
- data/lib/coradoc/{document/bibdata.rb → element/document_attributes.rb} +4 -8
- data/lib/coradoc/element/header.rb +20 -0
- data/lib/coradoc/element/image/block_image.rb +12 -0
- data/lib/coradoc/element/image/core.rb +25 -0
- data/lib/coradoc/element/image/inline_image.rb +12 -0
- data/lib/coradoc/element/image.rb +10 -0
- data/lib/coradoc/element/inline/anchor.rb +17 -0
- data/lib/coradoc/element/inline/bold.rb +20 -0
- data/lib/coradoc/element/inline/cross_reference.rb +22 -0
- data/lib/coradoc/element/inline/hard_line_break.rb +11 -0
- data/lib/coradoc/element/inline/highlight.rb +20 -0
- data/lib/coradoc/element/inline/image.rb +26 -0
- data/lib/coradoc/element/inline/italic.rb +20 -0
- data/lib/coradoc/element/inline/link.rb +26 -0
- data/lib/coradoc/element/inline/monospace.rb +20 -0
- data/lib/coradoc/element/inline/quotation.rb +18 -0
- data/lib/coradoc/element/inline/subscript.rb +18 -0
- data/lib/coradoc/element/inline/superscript.rb +18 -0
- data/lib/coradoc/element/inline.rb +18 -0
- data/lib/coradoc/element/list/core.rb +35 -0
- data/lib/coradoc/element/list/definition.rb +8 -0
- data/lib/coradoc/element/list/ordered.rb +15 -0
- data/lib/coradoc/element/list/unordered.rb +15 -0
- data/lib/coradoc/element/list.rb +12 -0
- data/lib/coradoc/element/list_item.rb +19 -0
- data/lib/coradoc/element/paragraph.rb +32 -0
- data/lib/coradoc/element/revision.rb +25 -0
- data/lib/coradoc/element/section.rb +37 -0
- data/lib/coradoc/element/table.rb +67 -0
- data/lib/coradoc/element/text_element.rb +32 -0
- data/lib/coradoc/{document → element}/title.rb +14 -5
- data/lib/coradoc/element/video.rb +23 -0
- data/lib/coradoc/generator.rb +17 -0
- data/lib/coradoc/legacy_parser.rb +48 -48
- data/lib/coradoc/oscal.rb +6 -5
- data/lib/coradoc/parser/asciidoc/base.rb +17 -17
- data/lib/coradoc/parser/asciidoc/content.rb +55 -29
- data/lib/coradoc/parser/asciidoc/document_attributes.rb +19 -0
- data/lib/coradoc/parser/asciidoc/header.rb +13 -10
- data/lib/coradoc/parser/asciidoc/section.rb +6 -6
- data/lib/coradoc/parser/base.rb +5 -5
- data/lib/coradoc/parser.rb +1 -1
- data/lib/coradoc/reverse_adoc/LICENSE.txt +25 -0
- data/lib/coradoc/reverse_adoc/README.adoc +302 -0
- data/lib/coradoc/reverse_adoc/cleaner.rb +113 -0
- data/lib/coradoc/reverse_adoc/config.rb +54 -0
- data/lib/coradoc/reverse_adoc/converters/a.rb +42 -0
- data/lib/coradoc/reverse_adoc/converters/aside.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/audio.rb +29 -0
- data/lib/coradoc/reverse_adoc/converters/base.rb +100 -0
- data/lib/coradoc/reverse_adoc/converters/blockquote.rb +27 -0
- data/lib/coradoc/reverse_adoc/converters/br.rb +15 -0
- data/lib/coradoc/reverse_adoc/converters/bypass.rb +81 -0
- data/lib/coradoc/reverse_adoc/converters/code.rb +56 -0
- data/lib/coradoc/reverse_adoc/converters/div.rb +18 -0
- data/lib/coradoc/reverse_adoc/converters/drop.rb +22 -0
- data/lib/coradoc/reverse_adoc/converters/em.rb +55 -0
- data/lib/coradoc/reverse_adoc/converters/figure.rb +25 -0
- data/lib/coradoc/reverse_adoc/converters/h.rb +42 -0
- data/lib/coradoc/reverse_adoc/converters/head.rb +23 -0
- data/lib/coradoc/reverse_adoc/converters/hr.rb +15 -0
- data/lib/coradoc/reverse_adoc/converters/ignore.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/img.rb +93 -0
- data/lib/coradoc/reverse_adoc/converters/li.rb +17 -0
- data/lib/coradoc/reverse_adoc/converters/mark.rb +21 -0
- data/lib/coradoc/reverse_adoc/converters/math.rb +31 -0
- data/lib/coradoc/reverse_adoc/converters/ol.rb +64 -0
- data/lib/coradoc/reverse_adoc/converters/p.rb +23 -0
- data/lib/coradoc/reverse_adoc/converters/pass_through.rb +13 -0
- data/lib/coradoc/reverse_adoc/converters/pre.rb +55 -0
- data/lib/coradoc/reverse_adoc/converters/q.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/strong.rb +52 -0
- data/lib/coradoc/reverse_adoc/converters/sub.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/sup.rb +16 -0
- data/lib/coradoc/reverse_adoc/converters/table.rb +69 -0
- data/lib/coradoc/reverse_adoc/converters/td.rb +83 -0
- data/lib/coradoc/reverse_adoc/converters/text.rb +65 -0
- data/lib/coradoc/reverse_adoc/converters/th.rb +14 -0
- data/lib/coradoc/reverse_adoc/converters/tr.rb +22 -0
- data/lib/coradoc/reverse_adoc/converters/video.rb +29 -0
- data/lib/coradoc/reverse_adoc/converters.rb +32 -0
- data/lib/coradoc/reverse_adoc/errors.rb +10 -0
- data/lib/coradoc/reverse_adoc/html_converter.rb +61 -0
- data/lib/coradoc/reverse_adoc.rb +27 -0
- data/lib/coradoc/transformer.rb +59 -46
- data/lib/coradoc/version.rb +1 -1
- data/lib/coradoc.rb +6 -4
- data/lib/reverse_adoc.rb +20 -0
- metadata +231 -23
- data/lib/coradoc/document/admonition.rb +0 -11
- data/lib/coradoc/document/author.rb +0 -11
- data/lib/coradoc/document/base.rb +0 -17
- data/lib/coradoc/document/block.rb +0 -34
- data/lib/coradoc/document/header.rb +0 -11
- data/lib/coradoc/document/list.rb +0 -14
- data/lib/coradoc/document/paragraph.rb +0 -19
- data/lib/coradoc/document/revision.rb +0 -11
- data/lib/coradoc/document/section.rb +0 -28
- data/lib/coradoc/document/table.rb +0 -20
- data/lib/coradoc/document/text_element.rb +0 -22
- data/lib/coradoc/parser/asciidoc/bibdata.rb +0 -19
@@ -1,17 +1,13 @@
|
|
1
1
|
module Coradoc
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Element
|
3
|
+
class DocumentAttributes
|
4
4
|
attr_reader :data
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(data = {}, options = {})
|
7
|
+
@data = data
|
8
8
|
@options = options
|
9
9
|
end
|
10
10
|
|
11
|
-
def data
|
12
|
-
@data ||= @bibdata
|
13
|
-
end
|
14
|
-
|
15
11
|
def to_hash
|
16
12
|
Hash.new.tap do |hash|
|
17
13
|
data.each do |attribute|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Header
|
4
|
+
attr_reader :title, :author, :revision
|
5
|
+
|
6
|
+
def initialize(title, options = {})
|
7
|
+
@title = title
|
8
|
+
@author = options.fetch(:author, nil)
|
9
|
+
@revision = options.fetch(:revision, nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
adoc = "= #{title}\n"
|
14
|
+
adoc << @author.to_adoc if @author
|
15
|
+
adoc << @revision.to_adoc if @revision
|
16
|
+
adoc
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Image
|
4
|
+
class Core
|
5
|
+
attr_reader :title, :id, :src, :attributes
|
6
|
+
|
7
|
+
def initialize(title, id, src, options = ())
|
8
|
+
@title = title
|
9
|
+
@id = id
|
10
|
+
@anchor = @id.nil? ? nil : Coradoc::Element::Inline::Anchor.new(@id)
|
11
|
+
@src = src
|
12
|
+
@attributes = options.fetch(:attributes, [])
|
13
|
+
@title = options.fetch(:title, nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_adoc
|
17
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
18
|
+
title = ".#{@title}\n" unless @title.to_s.empty?
|
19
|
+
attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
|
20
|
+
[anchor, title, "image", @colons, @src, attrs].join("")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Bold
|
5
|
+
attr_accessor :content, :unconstrained
|
6
|
+
|
7
|
+
def initialize(content, unconstrained = true)
|
8
|
+
@content = content
|
9
|
+
@unconstrained = unconstrained
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
14
|
+
doubled = @unconstrained ? "*" : ""
|
15
|
+
"#{doubled}*#{content.strip}*#{doubled}#{content[/\s+$/]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class CrossReference
|
5
|
+
attr_reader :href, :name
|
6
|
+
|
7
|
+
def initialize(href, name = nil)
|
8
|
+
@href = href
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
if @name.to_s.empty?
|
14
|
+
"<<#{@href}>>"
|
15
|
+
else
|
16
|
+
"<<#{@href},#{@name}>>"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Highlight
|
5
|
+
attr_accessor :content
|
6
|
+
|
7
|
+
def initialize(content, constrained = true)
|
8
|
+
@content = content
|
9
|
+
@constrained = constrained
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
14
|
+
doubled = @constrained ? "" : "#"
|
15
|
+
"#{content[/^\s*/]}#{doubled}##{content.strip}##{doubled}#{content[/\s*$/]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "../image/"
|
2
|
+
module Coradoc
|
3
|
+
module Element
|
4
|
+
module Inline
|
5
|
+
class Image
|
6
|
+
attr_reader :title, :id, :src, :attributes
|
7
|
+
|
8
|
+
def initialize(title, id, src, options = ())
|
9
|
+
@title = title
|
10
|
+
@id = id
|
11
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
12
|
+
@src = src
|
13
|
+
@attributes = options.fetch(:attributes, [])
|
14
|
+
@title = options.fetch(:title, nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_adoc
|
18
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
19
|
+
title = ".#{@title}\n" unless @title.to_s.empty?
|
20
|
+
attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
|
21
|
+
[anchor, title, "image::", @src, attrs].join("")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Italic
|
5
|
+
attr_accessor :content, :unconstrained
|
6
|
+
|
7
|
+
def initialize(content, unconstrained = true)
|
8
|
+
@content = content
|
9
|
+
@unconstrained = unconstrained
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
14
|
+
doubled = @unconstrained ? "_" : ""
|
15
|
+
"#{content[/^\s+/]}#{doubled}_#{content.strip}_#{doubled}#{content[/\s+$/]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Link
|
5
|
+
attr_reader :path, :title, :name
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@path = options.fetch(:path, nil)
|
9
|
+
@title = options.fetch(:title, nil)
|
10
|
+
@name = options.fetch(:name, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_adoc
|
14
|
+
link = @path.to_s&.match?(URI::DEFAULT_PARSER.make_regexp) ? @path : "link:#{@path}"
|
15
|
+
link << if @name.to_s.empty?
|
16
|
+
"[#{@title}]"
|
17
|
+
else
|
18
|
+
"[#{@name}]"
|
19
|
+
end
|
20
|
+
link.prepend(" ")
|
21
|
+
link
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Monospace
|
5
|
+
attr_accessor :content, :constrained
|
6
|
+
|
7
|
+
def initialize(content, unconstrained = true)
|
8
|
+
@content = content
|
9
|
+
@unconstrained = unconstrained
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
14
|
+
doubled = @unconstrained ? "`" : ""
|
15
|
+
"#{doubled}`#{content}`#{doubled}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Quotation
|
5
|
+
attr_accessor :content
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
@content = content
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
+
"#{content[/^\s*/]}\"#{content.strip}\"#{content[/\s*$/]}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Subscript
|
5
|
+
attr_accessor :content
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
@content = content
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
+
"#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Superscript
|
5
|
+
attr_accessor :content
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
@content = content
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
+
"#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative "inline/anchor"
|
9
|
+
require_relative "inline/bold"
|
10
|
+
require_relative "inline/cross_reference"
|
11
|
+
require_relative "inline/hard_line_break"
|
12
|
+
require_relative "inline/highlight"
|
13
|
+
require_relative "inline/italic"
|
14
|
+
require_relative "inline/link"
|
15
|
+
require_relative "inline/monospace"
|
16
|
+
require_relative "inline/quotation"
|
17
|
+
require_relative "inline/subscript"
|
18
|
+
require_relative "inline/superscript"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "../inline/anchor"
|
2
|
+
require_relative "core"
|
3
|
+
|
4
|
+
module Coradoc
|
5
|
+
module Element
|
6
|
+
module List
|
7
|
+
class Core
|
8
|
+
attr_reader :items, :prefix, :id, :ol_count, :anchor
|
9
|
+
|
10
|
+
def initialize(items, options = {})
|
11
|
+
@items = items
|
12
|
+
@items = [@items] unless @items.is_a?(Array)
|
13
|
+
@id = options.fetch(:id, nil)
|
14
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
15
|
+
@ol_count = options.fetch(:ol_count, 0)
|
16
|
+
@attrs = options.fetch(:attrs, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_adoc
|
20
|
+
content = "\n"
|
21
|
+
@items.each do |item|
|
22
|
+
c = Coradoc::Generator.gen_adoc(item)
|
23
|
+
if !c.empty?
|
24
|
+
content << prefix.to_s
|
25
|
+
content << c
|
26
|
+
end
|
27
|
+
end
|
28
|
+
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
29
|
+
attrs = @attrs.nil? ? "" : @attrs.to_adoc.to_s
|
30
|
+
"\n#{anchor}#{attrs}" + content
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class ListItem
|
4
|
+
attr_reader :id
|
5
|
+
|
6
|
+
def initialize(content, options = {})
|
7
|
+
@content = content
|
8
|
+
@id = options.fetch(:id, nil)
|
9
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
14
|
+
content = Coradoc::Generator.gen_adoc(@content).chomp
|
15
|
+
" #{anchor}#{content.chomp}\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Paragraph
|
4
|
+
attr_reader :content, :anchor, :tdsinglepara
|
5
|
+
|
6
|
+
def initialize(content, options = {})
|
7
|
+
@content = content
|
8
|
+
@meta = options.fetch(:meta, nil)
|
9
|
+
id = options.fetch(:id, nil)
|
10
|
+
@anchor = Inline::Anchor.new(id) if id
|
11
|
+
@tdsinglepara = options.fetch(:tdsinglepara, nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
content&.first&.id&.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def texts
|
19
|
+
content.map(&:content)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_adoc
|
23
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
24
|
+
if @tdsinglepara
|
25
|
+
anchor.to_s << Coradoc::Generator.gen_adoc(@content).strip
|
26
|
+
else
|
27
|
+
"\n\n#{anchor}" << Coradoc::Generator.gen_adoc(@content).strip << "\n\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Revision
|
4
|
+
attr_reader :number, :date, :remark
|
5
|
+
|
6
|
+
def initialize(number, options = {})
|
7
|
+
@number = number
|
8
|
+
@date = options.fetch(:date, nil)
|
9
|
+
@remark = options.fetch(:remark, nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
if @date.nil? && @remark.nil?
|
14
|
+
"v#{@number}\n"
|
15
|
+
elsif @remark.nil?
|
16
|
+
"#{@number}, #{@date}\n"
|
17
|
+
elsif @date.nil?
|
18
|
+
"#{@number}: #{@remark}\n"
|
19
|
+
else
|
20
|
+
"#{@number}, #{@date}: #{@revision}\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Section
|
4
|
+
attr_reader :id, :title, :contents, :sections
|
5
|
+
|
6
|
+
def initialize(title, options = {})
|
7
|
+
@title = title
|
8
|
+
@id = options.fetch(:id, nil)
|
9
|
+
@contents = options.fetch(:contents, [])
|
10
|
+
@sections = options.fetch(:sections, [])
|
11
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def glossaries
|
15
|
+
@glossaries ||= extract_glossaries
|
16
|
+
end
|
17
|
+
|
18
|
+
def content
|
19
|
+
if contents.count == 1 && contents.first.is_a?(Coradoc::Element::Paragraph)
|
20
|
+
contents.first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_adoc
|
25
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
26
|
+
content = Coradoc::Generator.gen_adoc(@contents)
|
27
|
+
"\n#{anchor}" << content << "\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def extract_glossaries
|
33
|
+
contents.select { |c| c if c.is_a?(Coradoc::Element::Glossaries) }.first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Table
|
4
|
+
attr_reader :title, :rows, :content, :id
|
5
|
+
|
6
|
+
def initialize(title, rows, options = {})
|
7
|
+
@rows = rows
|
8
|
+
@title = title
|
9
|
+
@id = options.fetch(:id, nil)
|
10
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
11
|
+
@attrs = options.fetch(:attrs, "")
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_adoc
|
15
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
16
|
+
attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n"
|
17
|
+
title = Coradoc::Generator.gen_adoc(@title)
|
18
|
+
title = title.empty? ? "" : ".#{title}\n"
|
19
|
+
content = @rows.map(&:to_adoc).join
|
20
|
+
"\n\n#{anchor}#{attrs}#{title}|===\n" << content << "\n|===\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
class Row
|
24
|
+
attr_reader :columns, :header
|
25
|
+
|
26
|
+
def initialize(columns, header = false)
|
27
|
+
@columns = columns
|
28
|
+
@header = header
|
29
|
+
end
|
30
|
+
|
31
|
+
def table_header_row?
|
32
|
+
@header
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_adoc
|
36
|
+
content = Coradoc::Generator.gen_adoc(@columns).rstrip
|
37
|
+
result = "#{content}\n"
|
38
|
+
table_header_row? ? result + underline_for : result
|
39
|
+
end
|
40
|
+
|
41
|
+
def underline_for
|
42
|
+
"\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Cell
|
47
|
+
attr_reader :anchor
|
48
|
+
|
49
|
+
def initialize(options = {})
|
50
|
+
@id = options.fetch(:id, nil)
|
51
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
52
|
+
@colrowattr = options.fetch(:colrowattr, "")
|
53
|
+
@alignattr = options.fetch(:alignattr, "")
|
54
|
+
@style = options.fetch(:style, "")
|
55
|
+
@content = options.fetch(:content, "")
|
56
|
+
@delim = options.fetch(:delim, "")
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_adoc
|
60
|
+
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
61
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
62
|
+
"#{@colrowattr}#{@alignattr}#{@style}| #{anchor}#{content}#{@delim}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|