coradoc 0.2.0 → 1.0.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/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
@@ -0,0 +1,32 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class ListItemDefinition < Base
|
4
|
+
attr_accessor :id, :terms, :contents
|
5
|
+
|
6
|
+
declare_children :id, :terms, :contents
|
7
|
+
|
8
|
+
def initialize(terms, contents, options = {})
|
9
|
+
@terms = terms
|
10
|
+
@contents = contents
|
11
|
+
@id = options.fetch(:id, nil)
|
12
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_adoc(delimiter)
|
16
|
+
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
17
|
+
content = ""
|
18
|
+
if (@terms.is_a?(Array) && @terms.size == 1) || !@terms.is_a?(Array)
|
19
|
+
t = Coradoc::Generator.gen_adoc(@terms)
|
20
|
+
content << "#{anchor}#{t}#{delimiter} "
|
21
|
+
else
|
22
|
+
@terms.map do |term|
|
23
|
+
t = Coradoc::Generator.gen_adoc(term)
|
24
|
+
content << "#{t}#{delimiter}\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
d = Coradoc::Generator.gen_adoc(@contents)
|
28
|
+
content << "#{d}\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Coradoc
|
2
2
|
module Element
|
3
|
-
class Paragraph
|
4
|
-
|
3
|
+
class Paragraph < Base
|
4
|
+
attr_accessor :content, :anchor, :tdsinglepara
|
5
|
+
|
6
|
+
declare_children :content, :anchor
|
5
7
|
|
6
8
|
def initialize(content, options = {})
|
7
9
|
@content = content
|
@@ -22,7 +24,7 @@ module Coradoc
|
|
22
24
|
def to_adoc
|
23
25
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
24
26
|
if @tdsinglepara
|
25
|
-
|
27
|
+
anchor.to_s << Coradoc::Generator.gen_adoc(@content).strip
|
26
28
|
else
|
27
29
|
"\n\n#{anchor}" << Coradoc::Generator.gen_adoc(@content).strip << "\n\n"
|
28
30
|
end
|
@@ -1,22 +1,26 @@
|
|
1
1
|
module Coradoc
|
2
|
-
|
3
|
-
|
2
|
+
module Element
|
3
|
+
class Revision < Base
|
4
|
+
attr_accessor :number, :date, :remark
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
declare_children :number, :date, :remark
|
7
|
+
|
8
|
+
def initialize(number, options = {})
|
9
|
+
@number = number
|
10
|
+
@date = options.fetch(:date, nil)
|
11
|
+
@remark = options.fetch(:remark, nil)
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def to_adoc
|
15
|
+
if @date.nil? && @remark.nil?
|
16
|
+
"v#{@number}\n"
|
17
|
+
elsif @remark.nil?
|
18
|
+
"#{@number}, #{@date}\n"
|
19
|
+
elsif @date.nil?
|
20
|
+
"#{@number}: #{@remark}\n"
|
21
|
+
else
|
22
|
+
"#{@number}, #{@date}: #{@revision}\n"
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module Coradoc
|
2
2
|
module Element
|
3
|
-
class Section
|
4
|
-
|
3
|
+
class Section < Base
|
4
|
+
attr_accessor :id, :title, :contents, :sections
|
5
|
+
|
6
|
+
declare_children :id, :title, :contents, :sections
|
5
7
|
|
6
8
|
def initialize(title, options = {})
|
7
9
|
@title = title
|
8
10
|
@id = options.fetch(:id, nil)
|
11
|
+
@id = nil if @id == ""
|
9
12
|
@contents = options.fetch(:contents, [])
|
10
13
|
@sections = options.fetch(:sections, [])
|
11
14
|
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
@@ -23,14 +26,28 @@ module Coradoc
|
|
23
26
|
|
24
27
|
def to_adoc
|
25
28
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
29
|
+
title = Coradoc::Generator.gen_adoc(@title)
|
26
30
|
content = Coradoc::Generator.gen_adoc(@contents)
|
27
|
-
|
31
|
+
sections = Coradoc::Generator.gen_adoc(@sections)
|
32
|
+
|
33
|
+
# A block of " +\n"s isn't parsed correctly. It needs to start
|
34
|
+
# with something.
|
35
|
+
content = " #{content}" if content.start_with?(" +\n")
|
36
|
+
|
37
|
+
"\n#{anchor}" << title << content << sections << "\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Check for cases when Section is simply an equivalent of an empty <DIV>
|
41
|
+
# HTML element and if it happens inside some other block element, can be
|
42
|
+
# safely collapsed.
|
43
|
+
def safe_to_collapse?
|
44
|
+
@title.nil? && @id.nil? && @sections.empty?
|
28
45
|
end
|
29
46
|
|
30
47
|
private
|
31
48
|
|
32
49
|
def extract_glossaries
|
33
|
-
contents.
|
50
|
+
contents.grep(Coradoc::Element::Glossaries).first
|
34
51
|
end
|
35
52
|
end
|
36
53
|
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module Coradoc
|
2
2
|
module Element
|
3
|
-
class Table
|
4
|
-
|
3
|
+
class Table < Base
|
4
|
+
attr_accessor :title, :rows, :content, :id
|
5
|
+
|
6
|
+
declare_children :title, :rows, :id
|
5
7
|
|
6
8
|
def initialize(title, rows, options = {})
|
7
9
|
@rows = rows
|
8
10
|
@title = title
|
9
11
|
@id = options.fetch(:id, nil)
|
10
12
|
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
11
|
-
@attrs = options.fetch(:attrs,
|
13
|
+
@attrs = options.fetch(:attrs, "")
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
16
|
def to_adoc
|
16
17
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
17
18
|
attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n"
|
@@ -21,45 +22,61 @@ module Coradoc
|
|
21
22
|
"\n\n#{anchor}#{attrs}#{title}|===\n" << content << "\n|===\n"
|
22
23
|
end
|
23
24
|
|
24
|
-
class Row
|
25
|
-
|
25
|
+
class Row < Base
|
26
|
+
attr_accessor :columns, :header
|
27
|
+
|
28
|
+
declare_children :columns
|
26
29
|
|
27
30
|
def initialize(columns, header = false)
|
28
31
|
@columns = columns
|
29
32
|
@header = header
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
def table_header_row?
|
33
36
|
@header
|
34
37
|
end
|
35
38
|
|
39
|
+
def asciidoc?
|
40
|
+
@columns.any?(&:asciidoc?)
|
41
|
+
end
|
42
|
+
|
36
43
|
def to_adoc
|
37
|
-
|
44
|
+
delim = asciidoc? ? "\n" : " "
|
45
|
+
content = @columns.map { |col| Coradoc::Generator.gen_adoc(col) }.join(delim)
|
38
46
|
result = "#{content}\n"
|
47
|
+
result << "\n" if asciidoc?
|
39
48
|
table_header_row? ? result + underline_for : result
|
40
49
|
end
|
41
50
|
|
42
51
|
def underline_for
|
43
52
|
"\n"
|
44
53
|
end
|
45
|
-
|
46
54
|
end
|
47
|
-
|
48
|
-
|
55
|
+
|
56
|
+
class Cell < Base
|
57
|
+
attr_accessor :content, :anchor, :id, :colrowattr, :alignattr, :style
|
58
|
+
|
59
|
+
declare_children :content, :anchor, :id
|
60
|
+
|
49
61
|
def initialize(options = {})
|
62
|
+
super()
|
50
63
|
@id = options.fetch(:id, nil)
|
51
64
|
@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
|
-
|
65
|
+
@colrowattr = options.fetch(:colrowattr, "")
|
66
|
+
@alignattr = options.fetch(:alignattr, "")
|
67
|
+
@style = options.fetch(:style, "")
|
68
|
+
@content = options.fetch(:content, "")
|
69
|
+
end
|
70
|
+
|
71
|
+
def asciidoc?
|
72
|
+
@style.include?("a")
|
57
73
|
end
|
58
74
|
|
59
75
|
def to_adoc
|
60
|
-
anchor = @anchor.nil? ? "" :
|
61
|
-
content =
|
62
|
-
|
76
|
+
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
77
|
+
content = simplify_block_content(@content)
|
78
|
+
content = Coradoc::Generator.gen_adoc(content)
|
79
|
+
"#{@colrowattr}#{@alignattr}#{@style}| #{anchor}#{content}"
|
63
80
|
end
|
64
81
|
end
|
65
82
|
end
|
@@ -1,26 +1,72 @@
|
|
1
1
|
module Coradoc
|
2
|
-
|
3
|
-
|
2
|
+
module Element
|
3
|
+
class TextElement < Base
|
4
|
+
attr_accessor :id, :content, :line_break
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
declare_children :content
|
7
|
+
|
8
|
+
def initialize(content, options = {})
|
9
|
+
@content = content # .to_s
|
10
|
+
@id = options.fetch(:id, nil)
|
11
|
+
@line_break = options.fetch(:line_break, "")
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_adoc
|
15
|
+
Coradoc::Generator.gen_adoc(treat_text_to_adoc(@content))
|
16
|
+
end
|
17
|
+
|
18
|
+
def treat_text_to_adoc(text)
|
19
|
+
text = preserve_nbsp(text)
|
20
|
+
text = remove_border_newlines(text)
|
21
|
+
text = remove_inner_newlines(text)
|
22
|
+
text = self.class.escape_keychars(text)
|
23
|
+
|
24
|
+
text = preserve_keychars_within_backticks(text)
|
25
|
+
escape_links(text)
|
26
|
+
end
|
27
|
+
|
28
|
+
def preserve_nbsp(text)
|
29
|
+
text.gsub(/\u00A0/, " ")
|
30
|
+
end
|
31
|
+
|
32
|
+
def escape_links(text)
|
33
|
+
text.gsub(/<<([^ ][^>]*)>>/, "\\<<\\1>>")
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove_border_newlines(text)
|
37
|
+
text.gsub(/\A\n+/, "").gsub(/\n+\z/, "")
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_inner_newlines(text)
|
41
|
+
text.tr("\n\t", " ").squeeze(" ")
|
42
|
+
end
|
43
|
+
|
44
|
+
def preserve_keychars_within_backticks(text)
|
45
|
+
text.gsub(/`.*?`/) do |match|
|
46
|
+
match.gsub('\_', "_").gsub('\*', "*")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.escape_keychars(string)
|
51
|
+
subs = { "*" => '\*', "_" => '\_' }
|
52
|
+
string
|
53
|
+
.gsub(/((?<=\s)[\*_]+)|[\*_]+(?=\s)/) do |n|
|
54
|
+
n.chars.map do |char|
|
55
|
+
subs[char]
|
56
|
+
end.join
|
57
|
+
end
|
58
|
+
end
|
13
59
|
end
|
14
|
-
end
|
15
60
|
|
16
|
-
|
17
|
-
|
61
|
+
class LineBreak < Base
|
62
|
+
attr_reader :line_break
|
18
63
|
|
19
|
-
|
20
|
-
|
64
|
+
def initialize(line_break)
|
65
|
+
@line_break = line_break
|
66
|
+
end
|
21
67
|
end
|
22
|
-
end
|
23
68
|
|
24
|
-
|
69
|
+
class Highlight < Element::TextElement
|
70
|
+
end
|
25
71
|
end
|
26
72
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Coradoc
|
2
2
|
module Element
|
3
|
-
class Title
|
4
|
-
|
3
|
+
class Title < Base
|
4
|
+
attr_accessor :id, :content, :line_break, :style, :level_int
|
5
|
+
|
6
|
+
declare_children :id, :content
|
5
7
|
|
6
8
|
def initialize(content, level, options = {})
|
7
9
|
@level_int = level
|
@@ -10,30 +12,48 @@ module Coradoc
|
|
10
12
|
@id = options.fetch(:id, nil)
|
11
13
|
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
12
14
|
@line_break = options.fetch(:line_break, "")
|
15
|
+
@style = options.fetch(:style, nil)
|
13
16
|
end
|
14
17
|
|
15
18
|
def level
|
16
|
-
@
|
19
|
+
@level ||= level_from_string
|
17
20
|
end
|
18
21
|
|
19
22
|
def to_adoc
|
20
23
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
21
24
|
content = Coradoc::Generator.gen_adoc(@content)
|
22
|
-
|
23
|
-
|
25
|
+
<<~HERE
|
26
|
+
|
27
|
+
#{anchor}#{style_str}#{level_str} #{content}
|
28
|
+
HERE
|
29
|
+
end
|
30
|
+
|
31
|
+
def level_str
|
32
|
+
if @level_int <= 5
|
33
|
+
"=" * (@level_int + 1)
|
34
|
+
else
|
35
|
+
"======"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def style_str
|
40
|
+
style = [@style]
|
41
|
+
style << "level=#{@level_int}" if @level_int > 5
|
42
|
+
style = style.compact.join(",")
|
43
|
+
|
44
|
+
"[#{style}]\n" unless style.empty?
|
24
45
|
end
|
25
46
|
|
26
47
|
alias :text :content
|
27
48
|
|
28
49
|
private
|
29
50
|
|
30
|
-
attr_reader :level_str
|
31
|
-
|
32
51
|
def level_from_string
|
33
52
|
case @level_int
|
34
53
|
when 2 then :heading_two
|
35
54
|
when 3 then :heading_three
|
36
55
|
when 4 then :heading_four
|
56
|
+
when 5 then :heading_five
|
37
57
|
else :unknown
|
38
58
|
end
|
39
59
|
end
|
@@ -1,23 +1,50 @@
|
|
1
1
|
module Coradoc
|
2
2
|
module Element
|
3
|
-
class Video
|
4
|
-
|
3
|
+
class Video < Base
|
4
|
+
attr_accessor :id, :title, :src, :options
|
5
|
+
|
6
|
+
declare_children :id, :anchor, :attributes
|
5
7
|
|
6
8
|
def initialize(title, options = {})
|
7
9
|
@title = title
|
8
10
|
@id = options.fetch(:id, nil)
|
9
11
|
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
10
|
-
@src = options.fetch(:src,
|
11
|
-
@attributes = options.fetch(:attributes,
|
12
|
-
|
12
|
+
@src = options.fetch(:src, "")
|
13
|
+
@attributes = options.fetch(:attributes, AttributeList.new)
|
14
|
+
if @attributes.any?
|
15
|
+
@attributes.validate_positional(VALIDATORS_POSITIONAL)
|
16
|
+
@attributes.validate_named(VALIDATORS_NAMED)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
def to_adoc
|
16
21
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
17
22
|
title = ".#{@title}\n" unless @title.empty?
|
18
|
-
attrs = @attributes.
|
23
|
+
attrs = @attributes.to_adoc
|
19
24
|
[anchor, title, "video::", @src, attrs].join("")
|
20
25
|
end
|
26
|
+
|
27
|
+
extend AttributeList::Matchers
|
28
|
+
VALIDATORS_POSITIONAL = [
|
29
|
+
[:alt, String],
|
30
|
+
[:width, Integer],
|
31
|
+
[:height, Integer],
|
32
|
+
]
|
33
|
+
|
34
|
+
VALIDATORS_NAMED = {
|
35
|
+
title: String,
|
36
|
+
poster: String,
|
37
|
+
width: Integer,
|
38
|
+
height: Integer,
|
39
|
+
start: Integer,
|
40
|
+
end: Integer,
|
41
|
+
theme: one("dark", "light"),
|
42
|
+
lang: /[a-z]{2,3}(?:-[A-Z]{2})?/,
|
43
|
+
list: String,
|
44
|
+
playlist: String,
|
45
|
+
options: many("autoplay", "loop", "modest",
|
46
|
+
"nocontrols", "nofullscreen", "muted"),
|
47
|
+
}
|
21
48
|
end
|
22
49
|
end
|
23
50
|
end
|
data/lib/coradoc/generator.rb
CHANGED
@@ -4,13 +4,13 @@ module Coradoc
|
|
4
4
|
if content.is_a?(Array)
|
5
5
|
content.map do |elem|
|
6
6
|
Coradoc::Generator.gen_adoc(elem)
|
7
|
-
end.join(
|
7
|
+
end.join("")
|
8
8
|
elsif content.respond_to? :to_adoc
|
9
9
|
content.to_adoc
|
10
10
|
elsif content.is_a?(String)
|
11
11
|
content
|
12
12
|
elsif content.nil?
|
13
|
-
|
13
|
+
""
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -23,8 +23,8 @@ module Coradoc
|
|
23
23
|
|
24
24
|
rule(:text_line) do
|
25
25
|
special_character.absent? >>
|
26
|
-
|
27
|
-
|
26
|
+
match("[^\n]").repeat(1).as(:text) >>
|
27
|
+
line_ending.as(:break)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Common Helpers
|
@@ -33,52 +33,52 @@ module Coradoc
|
|
33
33
|
|
34
34
|
# Document
|
35
35
|
rule(:document) do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
(
|
37
|
+
document_attributes.repeat(1).as(:document_attributes) |
|
38
|
+
section.as(:section) |
|
39
|
+
header.as(:header) |
|
40
|
+
block_with_title.as(:block) |
|
41
|
+
empty_line.repeat(1) |
|
42
|
+
any.as(:unparsed)
|
43
|
+
).repeat(1).as(:document)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Header
|
47
47
|
rule(:header) do
|
48
48
|
match("=") >> space? >> text.as(:title) >> newline >>
|
49
|
-
|
49
|
+
author.maybe.as(:author) >> revision.maybe.as(:revision)
|
50
50
|
end
|
51
51
|
|
52
52
|
rule(:author) do
|
53
53
|
words.as(:first_name) >> str(",") >> space? >> words.as(:last_name) >>
|
54
|
-
|
54
|
+
space? >> str("<") >> email.as(:email) >> str(">") >> endline
|
55
55
|
end
|
56
56
|
|
57
57
|
rule(:revision) do
|
58
58
|
(word >> (str(".") >> word).maybe).as(:number) >>
|
59
|
-
|
60
|
-
|
59
|
+
str(",") >> space? >> word.as(:date) >>
|
60
|
+
str(":") >> space? >> words.as(:remark) >> newline
|
61
61
|
end
|
62
62
|
|
63
63
|
# DocumentAttributes
|
64
64
|
rule(:document_attributes) do
|
65
65
|
str(":") >> attribute_name.as(:key) >> str(":") >>
|
66
|
-
|
66
|
+
space? >> attribute_value.as(:value) >> endline
|
67
67
|
end
|
68
68
|
|
69
69
|
# Section
|
70
70
|
rule(:section) do
|
71
71
|
heading.as(:title) >>
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
(list.as(:list) |
|
73
|
+
blocks.as(:blocks) |
|
74
|
+
paragraphs.as(:paragraphs)).maybe
|
75
75
|
end
|
76
76
|
|
77
77
|
# Heading
|
78
78
|
rule(:heading) do
|
79
79
|
(anchor_name >> newline).maybe >>
|
80
|
-
|
81
|
-
|
80
|
+
match("=").repeat(2, 8).as(:level) >>
|
81
|
+
space? >> text.as(:text) >> endline.as(:break)
|
82
82
|
end
|
83
83
|
|
84
84
|
rule(:anchor_name) { str("[#") >> keyword.as(:name) >> str("]") }
|
@@ -110,51 +110,51 @@ module Coradoc
|
|
110
110
|
rule(:block_type) { str("[") >> keyword.as(:type) >> str("]") >> newline }
|
111
111
|
|
112
112
|
rule(:block_attribute) do
|
113
|
-
str("[")
|
114
|
-
|
113
|
+
str("[") >> keyword.as(:key) >>
|
114
|
+
str("=") >> keyword.as(:value) >> str("]")
|
115
115
|
end
|
116
116
|
|
117
117
|
rule(:simple_block) do
|
118
118
|
block_attribute.as(:attributes) >> newline >>
|
119
|
-
|
119
|
+
text_line.repeat(1).as(:lines)
|
120
120
|
end
|
121
121
|
|
122
122
|
rule(:open_block) do
|
123
123
|
block_title >>
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
124
|
+
block_type >>
|
125
|
+
str("--").as(:delimiter) >> newline >>
|
126
|
+
text_line.repeat.as(:lines) >>
|
127
|
+
str("--") >> line_ending
|
128
128
|
end
|
129
129
|
|
130
130
|
rule(:example_block) do
|
131
131
|
block_title >>
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
132
|
+
block_type >>
|
133
|
+
str("====").as(:delimiter) >> newline >>
|
134
|
+
text_line.repeat(1).as(:lines) >>
|
135
|
+
str("====") >> newline
|
136
136
|
end
|
137
137
|
|
138
138
|
rule(:sidebar_block) do
|
139
139
|
block_title >>
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
140
|
+
block_type.maybe >>
|
141
|
+
str("****").as(:delimiter) >> newline >>
|
142
|
+
text_line.repeat(1).as(:lines) >>
|
143
|
+
str("****") >> newline
|
144
144
|
end
|
145
145
|
|
146
146
|
rule(:source_block) do
|
147
147
|
block_title >>
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
str("----").as(:delimiter) >> newline >>
|
149
|
+
text_line.repeat(1).as(:lines) >>
|
150
|
+
str("----") >> newline
|
151
151
|
end
|
152
152
|
|
153
153
|
rule(:quote_block) do
|
154
154
|
block_title >>
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
str("____").as(:delimiter) >> newline >>
|
156
|
+
text_line.repeat.as(:lines) >>
|
157
|
+
str("____") >> newline
|
158
158
|
end
|
159
159
|
|
160
160
|
rule(:block_with_title) do
|
data/lib/coradoc/oscal.rb
CHANGED
@@ -15,7 +15,7 @@ module Coradoc
|
|
15
15
|
def to_oscal
|
16
16
|
{
|
17
17
|
"metadata" => _doc.document_attributes.to_hash,
|
18
|
-
"groups" => sections_as_groups
|
18
|
+
"groups" => sections_as_groups,
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
@@ -80,9 +80,7 @@ module Coradoc
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def build_oscal_prose(paragraph)
|
83
|
-
|
84
|
-
paragraph.texts.join(" ")
|
85
|
-
end
|
83
|
+
paragraph&.texts&.join(" ")
|
86
84
|
end
|
87
85
|
end
|
88
86
|
end
|