coradoc 0.3.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/README.md +4 -0
- data/exe/reverse_adoc +24 -3
- data/lib/coradoc/document.rb +1 -0
- data/lib/coradoc/element/admonition.rb +2 -2
- data/lib/coradoc/element/attribute.rb +2 -2
- data/lib/coradoc/element/attribute_list.rb +94 -15
- data/lib/coradoc/element/audio.rb +13 -2
- data/lib/coradoc/element/author.rb +4 -2
- data/lib/coradoc/element/base.rb +70 -7
- data/lib/coradoc/element/block/core.rb +8 -4
- data/lib/coradoc/element/block/quote.rb +1 -1
- 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 +34 -5
- data/lib/coradoc/element/image/inline_image.rb +2 -2
- data/lib/coradoc/element/inline/anchor.rb +4 -2
- data/lib/coradoc/element/inline/bold.rb +9 -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 +11 -6
- data/lib/coradoc/element/inline/italic.rb +9 -4
- data/lib/coradoc/element/inline/link.rb +22 -6
- data/lib/coradoc/element/inline/monospace.rb +9 -4
- data/lib/coradoc/element/inline/quotation.rb +3 -1
- data/lib/coradoc/element/inline/subscript.rb +4 -2
- data/lib/coradoc/element/inline/superscript.rb +4 -2
- data/lib/coradoc/element/list/core.rb +9 -6
- 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 -0
- data/lib/coradoc/element/list_item.rb +8 -3
- data/lib/coradoc/element/list_item_definition.rb +32 -0
- data/lib/coradoc/element/paragraph.rb +4 -2
- data/lib/coradoc/element/revision.rb +4 -2
- data/lib/coradoc/element/section.rb +21 -4
- data/lib/coradoc/element/table.rb +27 -10
- data/lib/coradoc/element/text_element.rb +48 -8
- data/lib/coradoc/element/title.rb +26 -6
- data/lib/coradoc/element/video.rb +32 -5
- data/lib/coradoc/reverse_adoc/README.adoc +14 -8
- data/lib/coradoc/reverse_adoc/cleaner.rb +20 -8
- data/lib/coradoc/reverse_adoc/config.rb +35 -16
- data/lib/coradoc/reverse_adoc/converters/a.rb +17 -12
- data/lib/coradoc/reverse_adoc/converters/aside.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/audio.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/base.rb +48 -44
- data/lib/coradoc/reverse_adoc/converters/blockquote.rb +2 -11
- data/lib/coradoc/reverse_adoc/converters/br.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/bypass.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/code.rb +5 -42
- data/lib/coradoc/reverse_adoc/converters/div.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/dl.rb +55 -0
- data/lib/coradoc/reverse_adoc/converters/em.rb +5 -43
- data/lib/coradoc/reverse_adoc/converters/figure.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/h.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/head.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/hr.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/img.rb +21 -16
- data/lib/coradoc/reverse_adoc/converters/li.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/mark.rb +5 -11
- data/lib/coradoc/reverse_adoc/converters/markup.rb +27 -0
- data/lib/coradoc/reverse_adoc/converters/ol.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/p.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/pre.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/q.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/strong.rb +5 -41
- data/lib/coradoc/reverse_adoc/converters/sub.rb +6 -4
- data/lib/coradoc/reverse_adoc/converters/sup.rb +7 -5
- data/lib/coradoc/reverse_adoc/converters/table.rb +215 -4
- data/lib/coradoc/reverse_adoc/converters/td.rb +1 -7
- data/lib/coradoc/reverse_adoc/converters/text.rb +1 -38
- data/lib/coradoc/reverse_adoc/converters/tr.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters/video.rb +0 -4
- data/lib/coradoc/reverse_adoc/converters.rb +21 -0
- data/lib/coradoc/reverse_adoc/html_converter.rb +109 -20
- 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 +3 -0
- data/lib/coradoc/version.rb +1 -1
- data/lib/reverse_adoc.rb +1 -1
- metadata +8 -3
- data/lib/coradoc/element/inline/image.rb +0 -26
@@ -1,18 +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
|
-
|
7
|
+
declare_children :content
|
8
|
+
|
9
|
+
def initialize(content, unconstrained: true)
|
8
10
|
@content = content
|
9
11
|
@unconstrained = unconstrained
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_adoc
|
13
15
|
content = Coradoc::Generator.gen_adoc(@content)
|
14
|
-
|
15
|
-
|
16
|
+
if @unconstrained
|
17
|
+
"__#{content}__"
|
18
|
+
else
|
19
|
+
"_#{content}_"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
18
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
12
|
@path = options.fetch(:path, nil)
|
9
13
|
@title = options.fetch(:title, nil)
|
10
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
|
-
|
19
|
+
link = @path
|
20
|
+
unless @path.to_s&.match?(URI::DEFAULT_PARSER.make_regexp)
|
21
|
+
link = "link:#{link}"
|
22
|
+
end
|
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
|
16
29
|
"[#{@title}]"
|
17
|
-
|
30
|
+
elsif !name_empty
|
18
31
|
"[#{@name}]"
|
32
|
+
elsif valid_empty_name_link && !right_constrain
|
33
|
+
""
|
34
|
+
else
|
35
|
+
"[]"
|
19
36
|
end
|
20
|
-
link.prepend(" ")
|
21
37
|
link
|
22
38
|
end
|
23
39
|
end
|
@@ -1,18 +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
|
-
|
7
|
+
declare_children :content
|
8
|
+
|
9
|
+
def initialize(content, unconstrained: true)
|
8
10
|
@content = content
|
9
11
|
@unconstrained = unconstrained
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_adoc
|
13
15
|
content = Coradoc::Generator.gen_adoc(@content)
|
14
|
-
|
15
|
-
|
16
|
+
if @unconstrained
|
17
|
+
"``#{content}``"
|
18
|
+
else
|
19
|
+
"`#{content}`"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -1,16 +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
6
|
|
7
|
+
declare_children :content
|
8
|
+
|
7
9
|
def initialize(content)
|
8
10
|
@content = content
|
9
11
|
end
|
10
12
|
|
11
13
|
def to_adoc
|
12
14
|
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
-
"
|
15
|
+
"~#{content}~"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -1,16 +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
6
|
|
7
|
+
declare_children :content
|
8
|
+
|
7
9
|
def initialize(content)
|
8
10
|
@content = content
|
9
11
|
end
|
10
12
|
|
11
13
|
def to_adoc
|
12
14
|
content = Coradoc::Generator.gen_adoc(@content)
|
13
|
-
"
|
15
|
+
"^#{content}^"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -4,29 +4,32 @@ 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
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.to_s
|
29
|
-
attrs = @attrs.nil? ? "" : @attrs.to_adoc.to_s
|
30
33
|
"\n#{anchor}#{attrs}" + content
|
31
34
|
end
|
32
35
|
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
|
@@ -11,7 +13,10 @@ module Coradoc
|
|
11
13
|
|
12
14
|
def to_adoc
|
13
15
|
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
14
|
-
content =
|
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
|
@@ -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
|
@@ -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,7 +1,9 @@
|
|
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
|
@@ -20,8 +22,10 @@ module Coradoc
|
|
20
22
|
"\n\n#{anchor}#{attrs}#{title}|===\n" << content << "\n|===\n"
|
21
23
|
end
|
22
24
|
|
23
|
-
class Row
|
24
|
-
|
25
|
+
class Row < Base
|
26
|
+
attr_accessor :columns, :header
|
27
|
+
|
28
|
+
declare_children :columns
|
25
29
|
|
26
30
|
def initialize(columns, header = false)
|
27
31
|
@columns = columns
|
@@ -32,9 +36,15 @@ module Coradoc
|
|
32
36
|
@header
|
33
37
|
end
|
34
38
|
|
39
|
+
def asciidoc?
|
40
|
+
@columns.any?(&:asciidoc?)
|
41
|
+
end
|
42
|
+
|
35
43
|
def to_adoc
|
36
|
-
|
44
|
+
delim = asciidoc? ? "\n" : " "
|
45
|
+
content = @columns.map { |col| Coradoc::Generator.gen_adoc(col) }.join(delim)
|
37
46
|
result = "#{content}\n"
|
47
|
+
result << "\n" if asciidoc?
|
38
48
|
table_header_row? ? result + underline_for : result
|
39
49
|
end
|
40
50
|
|
@@ -43,23 +53,30 @@ module Coradoc
|
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
46
|
-
class Cell
|
47
|
-
|
56
|
+
class Cell < Base
|
57
|
+
attr_accessor :content, :anchor, :id, :colrowattr, :alignattr, :style
|
58
|
+
|
59
|
+
declare_children :content, :anchor, :id
|
48
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
65
|
@colrowattr = options.fetch(:colrowattr, "")
|
53
66
|
@alignattr = options.fetch(:alignattr, "")
|
54
67
|
@style = options.fetch(:style, "")
|
55
68
|
@content = options.fetch(:content, "")
|
56
|
-
|
69
|
+
end
|
70
|
+
|
71
|
+
def asciidoc?
|
72
|
+
@style.include?("a")
|
57
73
|
end
|
58
74
|
|
59
75
|
def to_adoc
|
60
76
|
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
61
|
-
content =
|
62
|
-
|
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,7 +1,9 @@
|
|
1
1
|
module Coradoc
|
2
2
|
module Element
|
3
|
-
class TextElement
|
4
|
-
|
3
|
+
class TextElement < Base
|
4
|
+
attr_accessor :id, :content, :line_break
|
5
|
+
|
6
|
+
declare_children :content
|
5
7
|
|
6
8
|
def initialize(content, options = {})
|
7
9
|
@content = content # .to_s
|
@@ -10,22 +12,60 @@ module Coradoc
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_adoc
|
13
|
-
Coradoc::Generator.gen_adoc(@content)
|
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
|
14
58
|
end
|
15
59
|
end
|
16
|
-
end
|
17
60
|
|
18
|
-
|
19
|
-
class LineBreak
|
61
|
+
class LineBreak < Base
|
20
62
|
attr_reader :line_break
|
21
63
|
|
22
64
|
def initialize(line_break)
|
23
65
|
@line_break = line_break
|
24
66
|
end
|
25
67
|
end
|
26
|
-
end
|
27
68
|
|
28
|
-
module Element
|
29
69
|
class Highlight < Element::TextElement
|
30
70
|
end
|
31
71
|
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,6 +12,7 @@ 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
|
@@ -19,21 +22,38 @@ module Coradoc
|
|
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
12
|
@src = options.fetch(:src, "")
|
11
|
-
@attributes = options.fetch(:attributes,
|
12
|
-
|
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
|