coradoc 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pryrc.sample +1 -0
- data/lib/coradoc/document.rb +41 -23
- data/lib/coradoc/{document → element}/admonition.rb +1 -1
- 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 +20 -0
- data/lib/coradoc/element/base.rb +17 -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 +24 -0
- data/lib/coradoc/element/image/inline_image.rb +12 -0
- data/lib/coradoc/element/image.rb +11 -0
- data/lib/coradoc/element/inline/anchor.rb +17 -0
- data/lib/coradoc/element/inline/bold.rb +19 -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 +19 -0
- data/lib/coradoc/element/inline/image.rb +25 -0
- data/lib/coradoc/element/inline/italic.rb +19 -0
- data/lib/coradoc/element/inline/link.rb +26 -0
- data/lib/coradoc/element/inline/monospace.rb +19 -0
- data/lib/coradoc/element/inline/quotation.rb +17 -0
- data/lib/coradoc/element/inline/subscript.rb +17 -0
- data/lib/coradoc/element/inline/superscript.rb +17 -0
- data/lib/coradoc/element/inline.rb +19 -0
- data/lib/coradoc/element/list/core.rb +36 -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 +13 -0
- data/lib/coradoc/element/list_item.rb +19 -0
- data/lib/coradoc/element/paragraph.rb +32 -0
- data/lib/coradoc/element/revision.rb +23 -0
- data/lib/coradoc/element/section.rb +37 -0
- data/lib/coradoc/element/table.rb +67 -0
- data/lib/coradoc/{document → element}/text_element.rb +8 -4
- data/lib/coradoc/element/title.rb +42 -0
- data/lib/coradoc/element/video.rb +23 -0
- data/lib/coradoc/generator.rb +17 -0
- data/lib/coradoc/legacy_parser.rb +8 -8
- data/lib/coradoc/oscal.rb +5 -2
- data/lib/coradoc/parser/asciidoc/base.rb +17 -17
- data/lib/coradoc/parser/asciidoc/content.rb +46 -20
- data/lib/coradoc/parser/asciidoc/{bibdata.rb → document_attributes.rb} +5 -5
- data/lib/coradoc/parser/asciidoc/header.rb +13 -10
- data/lib/coradoc/parser/asciidoc/section.rb +5 -5
- data/lib/coradoc/parser/base.rb +5 -5
- data/lib/coradoc/parser.rb +1 -1
- data/lib/coradoc/transformer.rb +39 -36
- data/lib/coradoc/version.rb +1 -1
- data/lib/coradoc.rb +6 -4
- metadata +55 -21
- 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/title.rb +0 -33
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Italic
|
5
|
+
attr_accessor :content, :unconstrained
|
6
|
+
def initialize(content, unconstrained = true)
|
7
|
+
@content = content
|
8
|
+
@unconstrained = unconstrained
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
+
doubled = @unconstrained ? "_" : ""
|
14
|
+
"#{content[/^\s+/]}#{doubled}_#{content.strip}_#{doubled}#{content[/\s+$/]}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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 =~ URI::DEFAULT_PARSER.make_regexp ? @path : "link:#{@path}"
|
15
|
+
if @name.to_s.empty?
|
16
|
+
link << "[#{@title}]"
|
17
|
+
else
|
18
|
+
link << "[#{@name}]"
|
19
|
+
end
|
20
|
+
link.prepend(' ')
|
21
|
+
link
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Monospace
|
5
|
+
attr_accessor :content, :constrained
|
6
|
+
def initialize(content, unconstrained = true)
|
7
|
+
@content = content
|
8
|
+
@unconstrained = unconstrained
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
+
doubled = @unconstrained ? "`" : ""
|
14
|
+
"#{doubled}`#{content}`#{doubled}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Quotation
|
5
|
+
attr_accessor :content
|
6
|
+
def initialize(content)
|
7
|
+
@content = content
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_adoc
|
11
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
12
|
+
"#{content[/^\s*/]}\"#{content.strip}\"#{content[/\s*$/]}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Subscript
|
5
|
+
attr_accessor :content
|
6
|
+
def initialize(content)
|
7
|
+
@content = content
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_adoc
|
11
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
12
|
+
"#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Superscript
|
5
|
+
attr_accessor :content
|
6
|
+
def initialize(content)
|
7
|
+
@content = content
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_adoc
|
11
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
12
|
+
"#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require_relative "inline/anchor"
|
10
|
+
require_relative "inline/bold"
|
11
|
+
require_relative "inline/cross_reference"
|
12
|
+
require_relative "inline/hard_line_break"
|
13
|
+
require_relative "inline/highlight"
|
14
|
+
require_relative "inline/italic"
|
15
|
+
require_relative "inline/link"
|
16
|
+
require_relative "inline/monospace"
|
17
|
+
require_relative "inline/quotation"
|
18
|
+
require_relative "inline/subscript"
|
19
|
+
require_relative "inline/superscript"
|
@@ -0,0 +1,36 @@
|
|
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}"
|
25
|
+
content << c
|
26
|
+
end
|
27
|
+
end
|
28
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}"
|
29
|
+
attrs = @attrs.nil? ? "" : "#{@attrs.to_adoc}"
|
30
|
+
"\n#{anchor}#{attrs}" + content
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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}"
|
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}" << 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,23 @@
|
|
1
|
+
module Coradoc
|
2
|
+
class Element::Revision
|
3
|
+
attr_reader :number, :date, :remark
|
4
|
+
|
5
|
+
def initialize(number, options = {})
|
6
|
+
@number = number
|
7
|
+
@date = options.fetch(:date, nil)
|
8
|
+
@remark = options.fetch(:remark, nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
if @date.nil? && @remark.nil?
|
13
|
+
"v#{@number}\n"
|
14
|
+
elsif @remark.nil?
|
15
|
+
"#{@number}, #{@date}\n"
|
16
|
+
elsif @date.nil?
|
17
|
+
"#{@number}: #{@remark}\n"
|
18
|
+
else
|
19
|
+
"#{@number}, #{@date}: #{@revision}\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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
|
+
|
15
|
+
def to_adoc
|
16
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
17
|
+
attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n"
|
18
|
+
title = Coradoc::Generator.gen_adoc(@title)
|
19
|
+
title = title.empty? ? "" : ".#{title}\n"
|
20
|
+
content = @rows.map(&:to_adoc).join
|
21
|
+
"\n\n#{anchor}#{attrs}#{title}|===\n" << content << "\n|===\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
class Row
|
25
|
+
attr_reader :columns, :header
|
26
|
+
|
27
|
+
def initialize(columns, header = false)
|
28
|
+
@columns = columns
|
29
|
+
@header = header
|
30
|
+
end
|
31
|
+
|
32
|
+
def table_header_row?
|
33
|
+
@header
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_adoc
|
37
|
+
content = Coradoc::Generator.gen_adoc(@columns).rstrip
|
38
|
+
result = "#{content}\n"
|
39
|
+
table_header_row? ? result + underline_for : result
|
40
|
+
end
|
41
|
+
|
42
|
+
def underline_for
|
43
|
+
"\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
class Cell
|
48
|
+
attr_reader :anchor
|
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}"
|
61
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
62
|
+
"#{@colrowattr}#{@alignattr}#{@style}| #{anchor}#{content}#{@delim}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module Coradoc
|
2
|
-
class
|
2
|
+
class Element::TextElement
|
3
3
|
attr_reader :id, :content, :line_break
|
4
4
|
|
5
5
|
def initialize(content, options = {})
|
6
|
-
@content = content
|
6
|
+
@content = content#.to_s
|
7
7
|
@id = options.fetch(:id, nil)
|
8
8
|
@line_break = options.fetch(:line_break, "")
|
9
9
|
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
Coradoc::Generator.gen_adoc(@content)
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
|
-
class
|
16
|
+
class Element::LineBreak
|
13
17
|
attr_reader :line_break
|
14
18
|
|
15
19
|
def initialize(line_break)
|
@@ -17,6 +21,6 @@ module Coradoc
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
class
|
24
|
+
class Element::Highlight < Element::TextElement
|
21
25
|
end
|
22
26
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Title
|
4
|
+
attr_reader :id, :content, :line_break
|
5
|
+
|
6
|
+
def initialize(content, level, options = {})
|
7
|
+
@level_int = level
|
8
|
+
@level_int = level.length if level.is_a?(String)
|
9
|
+
@content = content
|
10
|
+
@id = options.fetch(:id, nil)
|
11
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
12
|
+
@line_break = options.fetch(:line_break, "")
|
13
|
+
end
|
14
|
+
|
15
|
+
def level
|
16
|
+
@level_str ||= level_from_string
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_adoc
|
20
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
21
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
22
|
+
level_str = "=" * (@level_int + 1)
|
23
|
+
content = ["\n", anchor, level_str, ' ', content, "\n"].join("")
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :text :content
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :level_str
|
31
|
+
|
32
|
+
def level_from_string
|
33
|
+
case @level_int
|
34
|
+
when 2 then :heading_two
|
35
|
+
when 3 then :heading_three
|
36
|
+
when 4 then :heading_four
|
37
|
+
else :unknown
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Video
|
4
|
+
attr_reader :id, :title, :src, :options
|
5
|
+
|
6
|
+
def initialize(title, options = {})
|
7
|
+
@title = title
|
8
|
+
@id = options.fetch(:id, nil)
|
9
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
10
|
+
@src = options.fetch(:src, '')
|
11
|
+
@attributes = options.fetch(:attributes, [])
|
12
|
+
# @attributes.add_valid_named('opts')
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_adoc
|
16
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
17
|
+
title = ".#{@title}\n" unless @title.empty?
|
18
|
+
attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
|
19
|
+
[anchor, title, "video::", @src, attrs].join("")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
class Generator
|
3
|
+
def self.gen_adoc(content)
|
4
|
+
if content.is_a?(Array)
|
5
|
+
content.map do |elem|
|
6
|
+
Coradoc::Generator.gen_adoc(elem)
|
7
|
+
end.join('')
|
8
|
+
elsif content.respond_to? :to_adoc
|
9
|
+
content.to_adoc
|
10
|
+
elsif content.is_a?(String)
|
11
|
+
content
|
12
|
+
elsif content.nil?
|
13
|
+
''
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -34,7 +34,7 @@ module Coradoc
|
|
34
34
|
# Document
|
35
35
|
rule(:document) do
|
36
36
|
(
|
37
|
-
|
37
|
+
document_attributes.repeat(1).as(:document_attributes) |
|
38
38
|
section.as(:section) |
|
39
39
|
header.as(:header) |
|
40
40
|
block_with_title.as(:block) |
|
@@ -60,8 +60,8 @@ module Coradoc
|
|
60
60
|
str(":") >> space? >> words.as(:remark) >> newline
|
61
61
|
end
|
62
62
|
|
63
|
-
#
|
64
|
-
rule(:
|
63
|
+
# DocumentAttributes
|
64
|
+
rule(:document_attributes) do
|
65
65
|
str(":") >> attribute_name.as(:key) >> str(":") >>
|
66
66
|
space? >> attribute_value.as(:value) >> endline
|
67
67
|
end
|
@@ -85,15 +85,15 @@ module Coradoc
|
|
85
85
|
|
86
86
|
# List
|
87
87
|
rule(:list) do
|
88
|
-
|
89
|
-
definition_list.as(:definition) |
|
88
|
+
unordered_list.as(:unordered) |
|
89
|
+
definition_list.as(:definition) | ordered_list.as(:ordered)
|
90
90
|
end
|
91
91
|
|
92
|
-
rule(:
|
93
|
-
rule(:
|
92
|
+
rule(:ordered_list) { olist_item.repeat(1) }
|
93
|
+
rule(:unordered_list) { ulist_item.repeat(1) }
|
94
94
|
rule(:definition_list) { dlist_item.repeat(1) }
|
95
95
|
|
96
|
-
rule(:
|
96
|
+
rule(:olist_item) { match("\.") >> space >> text_line }
|
97
97
|
rule(:ulist_item) { match("\\*") >> space >> text_line }
|
98
98
|
rule(:dlist_item) do
|
99
99
|
str("term") >> space >> digits >> str("::") >> space >> text_line
|
data/lib/coradoc/oscal.rb
CHANGED
@@ -13,7 +13,10 @@ module Coradoc
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_oscal
|
16
|
-
{
|
16
|
+
{
|
17
|
+
"metadata" => _doc.document_attributes.to_hash,
|
18
|
+
"groups" => sections_as_groups
|
19
|
+
}
|
17
20
|
end
|
18
21
|
|
19
22
|
private
|
@@ -55,7 +58,7 @@ module Coradoc
|
|
55
58
|
def build_oscal_sub_parts(contents)
|
56
59
|
if contents.length > 1
|
57
60
|
parts = contents.select do |content|
|
58
|
-
content if content.is_a?(Coradoc::
|
61
|
+
content if content.is_a?(Coradoc::Element::Paragraph)
|
59
62
|
end
|
60
63
|
|
61
64
|
parts.map do |part|
|
@@ -26,31 +26,18 @@ module Coradoc
|
|
26
26
|
match["\r\n"].repeat(1)
|
27
27
|
end
|
28
28
|
|
29
|
-
# def line_break
|
30
|
-
# match["\r\n"]
|
31
|
-
# end
|
32
|
-
|
33
29
|
def keyword
|
34
30
|
(match("[a-zA-Z0-9_-]") | str(".")).repeat(1)
|
35
31
|
end
|
36
32
|
|
37
|
-
# def text_line
|
38
|
-
# special_character.absent? >>
|
39
|
-
# match("[^\n]").repeat(1).as(:text) >>
|
40
|
-
# line_ending.as(:break)
|
41
|
-
# end
|
42
|
-
|
43
|
-
# rule(:space) { match('\s') }
|
44
|
-
# rule(:space?) { spaces.maybe }
|
45
|
-
# rule(:spaces) { space.repeat(1) }
|
46
33
|
def empty_line
|
47
34
|
match("^\n")
|
48
35
|
end
|
49
|
-
#
|
50
36
|
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
def digit
|
38
|
+
match("[0-9]")
|
39
|
+
end
|
40
|
+
|
54
41
|
def digits
|
55
42
|
match("[0-9]").repeat(1)
|
56
43
|
end
|
@@ -63,6 +50,14 @@ module Coradoc
|
|
63
50
|
word >> (space? >> word).repeat
|
64
51
|
end
|
65
52
|
|
53
|
+
def rich_texts
|
54
|
+
rich_text >> (space? >> rich_text).repeat
|
55
|
+
end
|
56
|
+
|
57
|
+
def rich_text
|
58
|
+
(match("[a-zA-Z0-9_-]") | str(".") | str("*") | match("@")).repeat(1)
|
59
|
+
end
|
60
|
+
|
66
61
|
def email
|
67
62
|
word >> str("@") >> word >> str(".") >> word
|
68
63
|
end
|
@@ -78,6 +73,11 @@ module Coradoc
|
|
78
73
|
def special_character
|
79
74
|
match("^[*_:=-]") | str("[#") | str("[[")
|
80
75
|
end
|
76
|
+
|
77
|
+
def date
|
78
|
+
digit.repeat(2, 4) >> str("-") >>
|
79
|
+
digit.repeat(1, 2) >> str("-") >> digit.repeat(1, 2)
|
80
|
+
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|