coradoc 0.1.0 → 0.2.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/.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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09284ec8117d3052ad45275f82328e45e600fabc4f86379093af0dbe4ee9ebc4'
|
4
|
+
data.tar.gz: 8c9e2cef678a473459b091d05c303110a0caca9179d5ea89e1f4a07608d7bb9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35510139cf9cd1cf0eedaaf12b0bc80709628660d88e0178f3651d7f213c870abf68eb04de6f23a8056af4681875f7ba59804228937bc65bfb6550753a4fb769
|
7
|
+
data.tar.gz: 714c0f79bdd9bb05d58de71c6ab5bcdedddcd48a784fad4b019e168078c221ee6e477c573822a6a8f2db328fa02da5a0b9ef60542f239adb0b109c40ff309a66
|
data/.pryrc.sample
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
doc = Coradoc::Parser.parse("spec/fixtures/sample.adoc")
|
data/lib/coradoc/document.rb
CHANGED
@@ -1,22 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
require_relative "element/title"
|
2
|
+
require_relative "element/block"
|
3
|
+
require_relative "element/section"
|
4
|
+
require_relative "element/attribute"
|
5
|
+
require_relative "element/attribute_list"
|
6
|
+
require_relative "element/admonition"
|
7
|
+
require_relative "element/text_element"
|
8
|
+
require_relative "element/author"
|
9
|
+
require_relative "element/revision"
|
10
|
+
require_relative "element/header"
|
11
|
+
require_relative "element/document_attributes"
|
12
|
+
require_relative "element/paragraph"
|
13
|
+
require_relative "element/table"
|
14
|
+
require_relative "element/list"
|
15
|
+
require_relative "element/inline"
|
16
|
+
require_relative "element/image"
|
17
|
+
require_relative "element/audio"
|
18
|
+
require_relative "element/video"
|
19
|
+
require_relative "element/break"
|
14
20
|
|
15
21
|
module Coradoc
|
16
|
-
|
17
|
-
class << self
|
18
|
-
attr_reader :header, :bibdata, :sections
|
22
|
+
class Document
|
19
23
|
|
24
|
+
class << self
|
20
25
|
def from_adoc(filename)
|
21
26
|
ast = Coradoc::Parser.parse(filename)
|
22
27
|
Coradoc::Transformer.transform(ast)
|
@@ -26,21 +31,34 @@ module Coradoc
|
|
26
31
|
@sections = []
|
27
32
|
|
28
33
|
elements.each do |element|
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
case element
|
35
|
+
when Coradoc::Element::DocumentAttributes
|
36
|
+
@document_attributes = element
|
32
37
|
|
33
|
-
|
38
|
+
when Coradoc::Element::Header
|
34
39
|
@header = element
|
35
|
-
end
|
36
40
|
|
37
|
-
|
41
|
+
when Coradoc::Element::Section
|
38
42
|
@sections << element
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
|
-
self
|
46
|
+
self.new(
|
47
|
+
document_attributes: @document_attributes,
|
48
|
+
header: @header,
|
49
|
+
sections: @sections
|
50
|
+
)
|
43
51
|
end
|
44
52
|
end
|
53
|
+
|
54
|
+
attr_accessor :header, :document_attributes, :sections
|
55
|
+
|
56
|
+
def initialize(options={})
|
57
|
+
@document_attributes = options.fetch(:document_attributes, Coradoc::Element::DocumentAttributes.new)
|
58
|
+
@header = options.fetch(:header, Coradoc::Element::Header.new(""))
|
59
|
+
@sections = options.fetch(:sections, [])
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
45
63
|
end
|
46
64
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class AttributeList
|
4
|
+
attr_reader :positional, :named
|
5
|
+
|
6
|
+
def initialize(*positional, **named)
|
7
|
+
@positional = positional || []
|
8
|
+
@named = named || {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_positional(attr)
|
12
|
+
@positional << attr
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_named(name, value)
|
16
|
+
@named[name] = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def empty?
|
20
|
+
@positional.empty? && @named.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_adoc
|
24
|
+
return "[]" if [@positional, @named].all?(:empty?)
|
25
|
+
|
26
|
+
adoc = ""
|
27
|
+
adoc << @positional.join(",") if @positional.any?
|
28
|
+
adoc << "," if @positional.any? && @named.any?
|
29
|
+
adoc << @named.map do |k, v|
|
30
|
+
if v.is_a?(String)
|
31
|
+
v2 = v.to_s
|
32
|
+
v2 = v2.include?("\"") ? v2.gsub("\"","\\\"") : v2
|
33
|
+
if v2.include?(" ") || v2.include?(",") || v2.include?("\"")
|
34
|
+
v2 = "\"#{v2}\""
|
35
|
+
end
|
36
|
+
elsif v.is_a?(Array)
|
37
|
+
v2 = "\"#{v.join(",")}\""
|
38
|
+
end
|
39
|
+
[k.to_s, "=", v2].join
|
40
|
+
end.join(",")
|
41
|
+
adoc = "[#{adoc}]" if @positional.any? || @named.any?
|
42
|
+
adoc
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Audio
|
4
|
+
attr_reader :id, :title, :src, :options, :anchor
|
5
|
+
|
6
|
+
def initialize(title, options = {})
|
7
|
+
@title = title
|
8
|
+
@id = options.fetch(:id, nil)
|
9
|
+
@anchor = Inline::Anchor.new(@id) if @id
|
10
|
+
@src = options.fetch(:src, '')
|
11
|
+
@attributes = options.fetch(:attributes, [])
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_adoc
|
15
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
16
|
+
title = ".#{@title}\n" unless @title.empty?
|
17
|
+
attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
|
18
|
+
[anchor, title, "audio::", @src, attrs].join("")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
class Element::Author
|
3
|
+
attr_reader :email, :last_name, :first_name
|
4
|
+
|
5
|
+
def initialize(first_name, last_name, email, middle_name = nil)
|
6
|
+
@first_name = first_name
|
7
|
+
@last_name = last_name
|
8
|
+
@email = email
|
9
|
+
@middle_name = middle_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_adoc
|
13
|
+
adoc = "#{@first_name} "
|
14
|
+
adoc << "#{@middle_name} " if @middle_name
|
15
|
+
adoc << "#{@last_name}"
|
16
|
+
adoc << " <#{@email}>" if @email
|
17
|
+
adoc
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
class Base
|
4
|
+
# attr_reader :document_attributes
|
5
|
+
|
6
|
+
# def initialize(asciidoc)
|
7
|
+
# @document_attributes = extract_document_attributes(asciidoc)
|
8
|
+
# end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# def extract_document_attributes(asciidoc)
|
13
|
+
# @document_attributes ||= DocumentAttributes.new(asciidoc.attributes)
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative "../inline/anchor"
|
2
|
+
|
3
|
+
module Coradoc
|
4
|
+
module Element
|
5
|
+
module Block
|
6
|
+
class Core
|
7
|
+
attr_reader :title, :lines, :attributes, :lang, :id
|
8
|
+
|
9
|
+
def initialize(title, options = {})
|
10
|
+
@title = title
|
11
|
+
@lines = options.fetch(:lines, [])
|
12
|
+
@type_str = options.fetch(:type, nil)
|
13
|
+
@delimiter = options.fetch(:delimiter, "")
|
14
|
+
@attributes = options.fetch(:attributes, {})
|
15
|
+
@lang = options.fetch(:lang, nil)
|
16
|
+
@id = options.fetch(:id, nil)
|
17
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def type
|
21
|
+
@type ||= defined_type || type_from_delimiter
|
22
|
+
end
|
23
|
+
|
24
|
+
def gen_anchor
|
25
|
+
@anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
def gen_title
|
29
|
+
t = Coradoc::Generator.gen_adoc(@title)
|
30
|
+
return "" if t.empty?
|
31
|
+
".#{t}\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
def gen_attributes
|
35
|
+
@attributes.nil? ? "" : "#{@attributes.to_adoc}\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def gen_delimiter
|
39
|
+
@delimiter_char * @delimiter_len
|
40
|
+
end
|
41
|
+
|
42
|
+
def gen_lines
|
43
|
+
Coradoc::Generator.gen_adoc(@lines)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def defined_type
|
49
|
+
@type_str&.to_s&.to_sym
|
50
|
+
end
|
51
|
+
|
52
|
+
def type_from_delimiter
|
53
|
+
type_hash.fetch(@delimiter, nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
def type_hash
|
57
|
+
@type_hash ||= {
|
58
|
+
"____" => :quote,
|
59
|
+
"****" => :side,
|
60
|
+
"----" => :source,
|
61
|
+
"====" => :example,
|
62
|
+
"...." => :literal
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "core"
|
2
|
+
|
3
|
+
module Coradoc
|
4
|
+
module Element
|
5
|
+
module Block
|
6
|
+
class Example < Core
|
7
|
+
def initialize(title, options = {})
|
8
|
+
@title = title
|
9
|
+
@id = options.fetch(:id, nil)
|
10
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
11
|
+
@lines = options.fetch(:lines, [])
|
12
|
+
@delimiter_char = "="
|
13
|
+
@delimiter_len = options.fetch(:delimiter_len, 4)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_adoc
|
17
|
+
"\n\n#{gen_anchor}#{gen_title}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Block
|
4
|
+
class Literal < Core
|
5
|
+
def initialize(title, options = {})
|
6
|
+
@id = options.fetch(:id, nil)
|
7
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
8
|
+
@lines = options.fetch(:lines, [])
|
9
|
+
@delimiter_char = "."
|
10
|
+
@delimiter_len = options.fetch(:delimiter_len, 4)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_adoc
|
14
|
+
"\n\n#{gen_anchor}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Block
|
4
|
+
class Quote < Core
|
5
|
+
def initialize(title, options = {})
|
6
|
+
@title = title
|
7
|
+
@attributes = options.fetch(:attributes, {})
|
8
|
+
@lines = options.fetch(:lines, [])
|
9
|
+
@delimiter_char = "_"
|
10
|
+
@delimiter_len = options.fetch(:delimiter_len, 4)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_adoc
|
14
|
+
"\n\n#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Block
|
4
|
+
class Side < Core
|
5
|
+
def initialize(options = {})
|
6
|
+
@lines = options.fetch(:lines, [])
|
7
|
+
@delimiter_char = "*"
|
8
|
+
@delimiter_len = options.fetch(:delimiter_len, 4)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
"\n\n#{gen_delimiter}" << gen_lines << "\n#{gen_delimiter}\n\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Block
|
4
|
+
class SourceCode < Core
|
5
|
+
def initialize(title, options = {})
|
6
|
+
@id = options.fetch(:id, nil)
|
7
|
+
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
8
|
+
@lang = options.fetch(:lang, '')
|
9
|
+
@lines = options.fetch(:lines, [])
|
10
|
+
@delimiter_char = "-"
|
11
|
+
@delimiter_len = options.fetch(:delimiter_len, 4)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_adoc
|
15
|
+
"\n\n#{gen_anchor}[source,#{@lang}]\n#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Block
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative "block/core"
|
9
|
+
require_relative "block/example"
|
10
|
+
require_relative "block/literal"
|
11
|
+
require_relative "block/quote"
|
12
|
+
require_relative "block/side"
|
13
|
+
require_relative "block/sourcecode"
|
@@ -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,24 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Image
|
4
|
+
class Core
|
5
|
+
attr_reader :title, :id, :src, :attributes
|
6
|
+
def initialize(title, id, src, options = ())
|
7
|
+
@title = title
|
8
|
+
@id = id
|
9
|
+
@anchor = @id.nil? ? nil : Coradoc::Element::Inline::Anchor.new(@id)
|
10
|
+
@src = src
|
11
|
+
@attributes = options.fetch(:attributes, [])
|
12
|
+
@title = options.fetch(:title, nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_adoc
|
16
|
+
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
17
|
+
title = ".#{@title}\n" unless @title.to_s.empty?
|
18
|
+
attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
|
19
|
+
[anchor, title, "image", @colons, @src, attrs].join("")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Bold
|
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
|
+
"#{doubled}*#{content.strip}*#{doubled}#{content[/\s+$/]}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Highlight
|
5
|
+
attr_accessor :content
|
6
|
+
def initialize(content, constrained = true)
|
7
|
+
@content = content
|
8
|
+
@constrained = constrained
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_adoc
|
12
|
+
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
+
doubled = @constrained ? "" : "#"
|
14
|
+
"#{content[/^\s*/]}#{doubled}##{content.strip}##{doubled}#{content[/\s*$/]}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "../image/"
|
2
|
+
module Coradoc
|
3
|
+
module Element
|
4
|
+
module Inline
|
5
|
+
class Image
|
6
|
+
attr_reader :title, :id, :src, :attributes
|
7
|
+
def initialize(title, id, src, options = ())
|
8
|
+
@title = title
|
9
|
+
@id = id
|
10
|
+
@anchor = @id.nil? ? nil : 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::", @src, attrs].join("")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|