coradoc 1.1.5 → 1.1.7
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/.envrc +1 -0
- data/.irbrc +1 -0
- data/.rspec +3 -0
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +179 -0
- data/Gemfile +11 -0
- data/README.adoc +5 -7
- data/coradoc.gemspec +5 -16
- data/exe/reverse_adoc +1 -1
- data/exe/w2a +1 -1
- data/flake.lock +114 -0
- data/flake.nix +135 -0
- data/lib/coradoc/cli.rb +1 -1
- data/lib/coradoc/converter.rb +4 -5
- data/lib/coradoc/element/attribute.rb +10 -1
- data/lib/coradoc/element/attribute_list.rb +4 -3
- data/lib/coradoc/element/audio.rb +1 -1
- data/lib/coradoc/element/author.rb +2 -2
- data/lib/coradoc/element/base.rb +14 -2
- data/lib/coradoc/element/bibliography.rb +1 -1
- data/lib/coradoc/element/bibliography_entry.rb +1 -1
- data/lib/coradoc/element/block/open.rb +1 -1
- data/lib/coradoc/element/block.rb +1 -1
- data/lib/coradoc/element/document_attributes.rb +8 -2
- data/lib/coradoc/element/image/block_image.rb +3 -2
- data/lib/coradoc/element/image/core.rb +5 -4
- data/lib/coradoc/element/inline/attribute_reference.rb +19 -0
- data/lib/coradoc/element/inline/cross_reference.rb +4 -3
- data/lib/coradoc/element/inline/footnote.rb +24 -0
- data/lib/coradoc/element/inline/small.rb +19 -0
- data/lib/coradoc/element/inline/span.rb +37 -0
- data/lib/coradoc/element/inline/underline.rb +19 -0
- data/lib/coradoc/element/inline.rb +5 -1
- data/lib/coradoc/element/list/core.rb +2 -2
- data/lib/coradoc/element/list/ordered.rb +1 -0
- data/lib/coradoc/element/list/unordered.rb +1 -0
- data/lib/coradoc/element/list_item.rb +19 -20
- data/lib/coradoc/element/table.rb +4 -2
- data/lib/coradoc/element/term.rb +1 -0
- data/lib/coradoc/element/text_element.rb +4 -1
- data/lib/coradoc/element/title.rb +1 -1
- data/lib/coradoc/element/video.rb +2 -2
- data/lib/coradoc/input/adoc.rb +20 -18
- data/lib/coradoc/input/docx.rb +25 -23
- data/lib/coradoc/input/html/README.adoc +1 -1
- data/lib/coradoc/input/html/cleaner.rb +121 -117
- data/lib/coradoc/input/html/config.rb +58 -56
- data/lib/coradoc/input/html/converters/a.rb +44 -39
- data/lib/coradoc/input/html/converters/aside.rb +12 -8
- data/lib/coradoc/input/html/converters/audio.rb +24 -20
- data/lib/coradoc/input/html/converters/base.rb +103 -99
- data/lib/coradoc/input/html/converters/blockquote.rb +18 -14
- data/lib/coradoc/input/html/converters/br.rb +11 -7
- data/lib/coradoc/input/html/converters/bypass.rb +77 -73
- data/lib/coradoc/input/html/converters/code.rb +18 -14
- data/lib/coradoc/input/html/converters/div.rb +15 -11
- data/lib/coradoc/input/html/converters/dl.rb +51 -44
- data/lib/coradoc/input/html/converters/drop.rb +21 -17
- data/lib/coradoc/input/html/converters/em.rb +16 -12
- data/lib/coradoc/input/html/converters/figure.rb +19 -15
- data/lib/coradoc/input/html/converters/h.rb +32 -30
- data/lib/coradoc/input/html/converters/head.rb +17 -13
- data/lib/coradoc/input/html/converters/hr.rb +11 -7
- data/lib/coradoc/input/html/converters/ignore.rb +15 -11
- data/lib/coradoc/input/html/converters/img.rb +98 -93
- data/lib/coradoc/input/html/converters/li.rb +13 -9
- data/lib/coradoc/input/html/converters/mark.rb +14 -10
- data/lib/coradoc/input/html/converters/markup.rb +22 -18
- data/lib/coradoc/input/html/converters/math.rb +26 -19
- data/lib/coradoc/input/html/converters/ol.rb +55 -50
- data/lib/coradoc/input/html/converters/p.rb +16 -12
- data/lib/coradoc/input/html/converters/pass_through.rb +12 -8
- data/lib/coradoc/input/html/converters/pre.rb +49 -45
- data/lib/coradoc/input/html/converters/q.rb +12 -8
- data/lib/coradoc/input/html/converters/strong.rb +15 -11
- data/lib/coradoc/input/html/converters/sub.rb +15 -11
- data/lib/coradoc/input/html/converters/sup.rb +15 -11
- data/lib/coradoc/input/html/converters/table.rb +21 -13
- data/lib/coradoc/input/html/converters/td.rb +64 -60
- data/lib/coradoc/input/html/converters/text.rb +24 -20
- data/lib/coradoc/input/html/converters/th.rb +13 -9
- data/lib/coradoc/input/html/converters/tr.rb +17 -13
- data/lib/coradoc/input/html/converters/video.rb +24 -20
- data/lib/coradoc/input/html/converters.rb +45 -43
- data/lib/coradoc/input/html/errors.rb +8 -6
- data/lib/coradoc/input/html/html_converter.rb +93 -90
- data/lib/coradoc/input/html/plugin.rb +104 -104
- data/lib/coradoc/input/html/plugins/plateau.rb +197 -190
- data/lib/coradoc/input/html/postprocessor.rb +188 -182
- data/lib/coradoc/input/html.rb +34 -32
- data/lib/coradoc/oscal.rb +18 -5
- data/lib/coradoc/output/adoc.rb +13 -11
- data/lib/coradoc/output/coradoc_tree_debug.rb +15 -13
- data/lib/coradoc/parser/asciidoc/admonition.rb +6 -6
- data/lib/coradoc/parser/asciidoc/attribute_list.rb +43 -27
- data/lib/coradoc/parser/asciidoc/base.rb +3 -6
- data/lib/coradoc/parser/asciidoc/bibliography.rb +5 -6
- data/lib/coradoc/parser/asciidoc/block.rb +30 -31
- data/lib/coradoc/parser/asciidoc/citation.rb +11 -29
- data/lib/coradoc/parser/asciidoc/content.rb +23 -33
- data/lib/coradoc/parser/asciidoc/document_attributes.rb +2 -3
- data/lib/coradoc/parser/asciidoc/header.rb +1 -2
- data/lib/coradoc/parser/asciidoc/inline.rb +165 -42
- data/lib/coradoc/parser/asciidoc/list.rb +27 -27
- data/lib/coradoc/parser/asciidoc/paragraph.rb +28 -19
- data/lib/coradoc/parser/asciidoc/section.rb +11 -17
- data/lib/coradoc/parser/asciidoc/table.rb +5 -5
- data/lib/coradoc/parser/asciidoc/term.rb +24 -8
- data/lib/coradoc/parser/asciidoc/text.rb +18 -21
- data/lib/coradoc/parser/base.rb +0 -3
- data/lib/coradoc/reverse_adoc.rb +3 -3
- data/lib/coradoc/transformer.rb +167 -137
- data/lib/coradoc/version.rb +1 -1
- data/lib/reverse_adoc.rb +1 -1
- data/utils/inspect_asciidoc.rb +29 -0
- data/utils/parser_analyzer.rb +14 -14
- data/utils/round_trip.rb +31 -15
- metadata +34 -137
- data/.hound.yml +0 -5
- data/lib/coradoc/element/inline/citation.rb +0 -24
- data/todo.md +0 -10
data/lib/coradoc/element/base.rb
CHANGED
@@ -39,18 +39,30 @@ module Coradoc
|
|
39
39
|
|
40
40
|
def self.declare_children(*children)
|
41
41
|
@children = (@children || []).dup + children
|
42
|
+
access_children
|
43
|
+
end
|
44
|
+
|
45
|
+
# Make each child available for access
|
46
|
+
def self.access_children
|
47
|
+
@children.each do |child|
|
48
|
+
attr_accessor child
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
def self.visit(element, &block)
|
53
|
+
return element if element.nil?
|
54
|
+
|
45
55
|
element = yield element, :pre
|
46
56
|
element = if element.respond_to? :visit
|
47
57
|
element.visit(&block)
|
48
58
|
elsif element.is_a? Array
|
49
59
|
element.map { |child| visit(child, &block) }.flatten.compact
|
50
60
|
elsif element.is_a? Hash
|
51
|
-
|
52
|
-
|
61
|
+
result = {}
|
62
|
+
element.each do |k, v|
|
63
|
+
result[k] = visit(v, &block)
|
53
64
|
end
|
65
|
+
result
|
54
66
|
else
|
55
67
|
element
|
56
68
|
end
|
@@ -12,13 +12,19 @@ module Coradoc
|
|
12
12
|
|
13
13
|
def to_hash
|
14
14
|
@data.to_h do |attribute|
|
15
|
-
[attribute.key
|
15
|
+
[attribute.key, attribute.value]
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_adoc
|
20
20
|
to_hash.map do |key, value|
|
21
|
-
v = value.to_s.empty?
|
21
|
+
v = if value.to_s.empty?
|
22
|
+
""
|
23
|
+
elsif value.is_a? Array
|
24
|
+
" #{value.join(',')}"
|
25
|
+
else
|
26
|
+
" #{value}"
|
27
|
+
end
|
22
28
|
":#{key}:#{v}\n"
|
23
29
|
end.join + "\n"
|
24
30
|
end
|
@@ -12,7 +12,8 @@ module Coradoc
|
|
12
12
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
13
13
|
title = ".#{@title}\n" unless @title.to_s.empty?
|
14
14
|
attrs = @attributes.to_adoc
|
15
|
-
[missing, anchor, title, "image", @colons, @src, attrs,
|
15
|
+
[missing, anchor, title, "image", @colons, @src, attrs,
|
16
|
+
@line_break].join("")
|
16
17
|
end
|
17
18
|
|
18
19
|
def validate_named
|
@@ -24,7 +25,7 @@ module Coradoc
|
|
24
25
|
caption: String,
|
25
26
|
align: one("left", "center", "right"),
|
26
27
|
float: one("left", "right"),
|
27
|
-
}
|
28
|
+
}.freeze
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -13,7 +13,7 @@ module Coradoc
|
|
13
13
|
@src = src
|
14
14
|
@attributes = options.fetch(:attributes, AttributeList.new)
|
15
15
|
@annotate_missing = options.fetch(:annotate_missing, nil)
|
16
|
-
@title
|
16
|
+
@title ||= options.fetch(:title, nil)
|
17
17
|
if @attributes.any?
|
18
18
|
@attributes.validate_positional(VALIDATORS_POSITIONAL)
|
19
19
|
@attributes.validate_named(VALIDATORS_NAMED)
|
@@ -26,7 +26,8 @@ module Coradoc
|
|
26
26
|
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
27
27
|
title = ".#{@title}\n" unless @title.to_s.empty?
|
28
28
|
attrs = @attributes_macro.to_adoc
|
29
|
-
[missing, anchor, title, "image", @colons, @src, attrs,
|
29
|
+
[missing, anchor, title, "image", @colons, @src, attrs,
|
30
|
+
@line_break].join("")
|
30
31
|
end
|
31
32
|
|
32
33
|
extend AttributeList::Matchers
|
@@ -34,7 +35,7 @@ module Coradoc
|
|
34
35
|
[:alt, String],
|
35
36
|
[:width, Integer],
|
36
37
|
[:height, Integer],
|
37
|
-
]
|
38
|
+
].freeze
|
38
39
|
|
39
40
|
VALIDATORS_NAMED = {
|
40
41
|
id: String,
|
@@ -50,7 +51,7 @@ module Coradoc
|
|
50
51
|
pdfwidth: /\A[0-9]+vw\z/,
|
51
52
|
role: many(/.*/, "left", "right", "th", "thumb", "related", "rel"),
|
52
53
|
opts: many("nofollow", "noopener", "inline", "interactive"),
|
53
|
-
}
|
54
|
+
}.freeze
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class AttributeReference < Base
|
5
|
+
attr_accessor :name
|
6
|
+
|
7
|
+
declare_children :name
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_adoc
|
14
|
+
"{#{@name}}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -15,8 +15,9 @@ module Coradoc
|
|
15
15
|
|
16
16
|
def to_adoc
|
17
17
|
if @args
|
18
|
-
args = @args.map
|
19
|
-
Coradoc::Generator.gen_adoc(a)
|
18
|
+
args = @args.map do |a|
|
19
|
+
Coradoc::Generator.gen_adoc(a)
|
20
|
+
end.join(",")
|
20
21
|
if args.empty?
|
21
22
|
return "<<#{@href}>>"
|
22
23
|
else
|
@@ -37,7 +38,7 @@ module Coradoc
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def to_adoc
|
40
|
-
[@key
|
41
|
+
[@key, @delimiter, @value].join
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Footnote < Base
|
5
|
+
attr_accessor :text, :id
|
6
|
+
|
7
|
+
declare_children :text, :id
|
8
|
+
|
9
|
+
def initialize(text, id = nil)
|
10
|
+
@text = text
|
11
|
+
@id = id
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_adoc
|
15
|
+
if @id
|
16
|
+
"footnote:#{@id}[#{@text}]"
|
17
|
+
else
|
18
|
+
"footnote:[#{@text}]"
|
19
|
+
end
|
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 Small < Base
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
declare_children :text
|
8
|
+
|
9
|
+
def initialize(text, _options = {})
|
10
|
+
@text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_adoc
|
14
|
+
"[.small]##{@text}#"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Span < Base
|
5
|
+
attr_accessor :text, :role, :attributes, :unconstrained
|
6
|
+
|
7
|
+
declare_children :text, :attributes
|
8
|
+
|
9
|
+
def initialize(text, options = {})
|
10
|
+
@text = text
|
11
|
+
@role = options.fetch(:role, nil)
|
12
|
+
@attributes = options.fetch(:attributes, nil)
|
13
|
+
@unconstrained = options.fetch(:unconstrained, false)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_adoc
|
17
|
+
if @attributes
|
18
|
+
attr_string = @attributes.to_adoc
|
19
|
+
if @unconstrained
|
20
|
+
"#{attr_string}###{@text}##"
|
21
|
+
else
|
22
|
+
"#{attr_string}##{@text}#"
|
23
|
+
end
|
24
|
+
elsif @role
|
25
|
+
if @unconstrained
|
26
|
+
"[.#{@role}]###{@text}##"
|
27
|
+
else
|
28
|
+
"[.#{@role}]##{@text}#"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
@text.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Coradoc
|
2
|
+
module Element
|
3
|
+
module Inline
|
4
|
+
class Underline < Base
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
declare_children :text
|
8
|
+
|
9
|
+
def initialize(text, _options = {})
|
10
|
+
@text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_adoc
|
14
|
+
"[.underline]##{@text}#"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -6,14 +6,18 @@ module Coradoc
|
|
6
6
|
end
|
7
7
|
|
8
8
|
require_relative "inline/anchor"
|
9
|
+
require_relative "inline/attribute_reference"
|
9
10
|
require_relative "inline/bold"
|
10
11
|
require_relative "inline/cross_reference"
|
11
|
-
require_relative "inline/citation"
|
12
12
|
require_relative "inline/hard_line_break"
|
13
13
|
require_relative "inline/highlight"
|
14
14
|
require_relative "inline/italic"
|
15
15
|
require_relative "inline/link"
|
16
16
|
require_relative "inline/monospace"
|
17
17
|
require_relative "inline/quotation"
|
18
|
+
require_relative "inline/span"
|
18
19
|
require_relative "inline/subscript"
|
19
20
|
require_relative "inline/superscript"
|
21
|
+
require_relative "inline/footnote"
|
22
|
+
require_relative "inline/underline"
|
23
|
+
require_relative "inline/small"
|
@@ -16,10 +16,10 @@ module Coradoc
|
|
16
16
|
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
17
17
|
@ol_count = options.fetch(:ol_count, nil)
|
18
18
|
if @ol_count.nil?
|
19
|
-
m = @items.
|
19
|
+
m = @items.find do |i|
|
20
20
|
i.is_a?(Coradoc::Element::ListItem) &&
|
21
21
|
!i.marker.nil?
|
22
|
-
end
|
22
|
+
end&.marker.to_s
|
23
23
|
@ol_count = m.size
|
24
24
|
end
|
25
25
|
@ol_count = 1 if @ol_count.nil?
|
@@ -10,6 +10,7 @@ module Coradoc
|
|
10
10
|
@id = options.fetch(:id, nil)
|
11
11
|
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
12
12
|
@content = content
|
13
|
+
# @content = [@content] unless @content.class == Array
|
13
14
|
@attached = options.fetch(:attached, [])
|
14
15
|
@nested = options.fetch(:nested, nil)
|
15
16
|
@line_break = options.fetch(:line_break, "\n")
|
@@ -19,7 +20,7 @@ module Coradoc
|
|
19
20
|
case elem
|
20
21
|
when Inline::HardLineBreak
|
21
22
|
:hardbreak
|
22
|
-
when ->(i){ i.class.name.to_s.include? "::Inline::" }
|
23
|
+
when ->(i) { i.class.name.to_s.include? "::Inline::" }
|
23
24
|
true
|
24
25
|
when String, TextElement, Image::InlineImage
|
25
26
|
true
|
@@ -29,8 +30,8 @@ module Coradoc
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def to_adoc
|
32
|
-
anchor = @anchor.nil? ? "" : " #{@anchor.to_adoc
|
33
|
-
|
33
|
+
anchor = @anchor.nil? ? "" : " #{@anchor.to_adoc} "
|
34
|
+
|
34
35
|
content = Array(@content).flatten.compact
|
35
36
|
out = ""
|
36
37
|
prev_inline = :init
|
@@ -42,9 +43,8 @@ module Coradoc
|
|
42
43
|
|
43
44
|
content.each_with_index do |subitem, idx|
|
44
45
|
subcontent = Coradoc::Generator.gen_adoc(subitem)
|
45
|
-
|
46
46
|
inline = inline?(subitem)
|
47
|
-
next_inline = idx+1 == content.length ? :end : inline?(content[idx+1])
|
47
|
+
next_inline = idx + 1 == content.length ? :end : inline?(content[idx + 1])
|
48
48
|
|
49
49
|
# Only try to postprocess elements that are text,
|
50
50
|
# otherwise we could strip markup.
|
@@ -59,20 +59,20 @@ module Coradoc
|
|
59
59
|
|
60
60
|
case inline
|
61
61
|
when true
|
62
|
-
if prev_inline == false
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
out += if prev_inline == false
|
63
|
+
"\n+\n#{subcontent}"
|
64
|
+
else
|
65
|
+
subcontent
|
66
|
+
end
|
67
67
|
when false
|
68
|
-
case prev_inline
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
out += case prev_inline
|
69
|
+
when :hardbreak
|
70
|
+
subcontent.strip
|
71
|
+
when :init
|
72
|
+
"{empty}\n+\n#{subcontent.to_s.strip}"
|
73
|
+
else
|
74
|
+
"\n+\n#{subcontent.to_s.strip}"
|
75
|
+
end
|
76
76
|
when :hardbreak
|
77
77
|
if %i[hardbreak init].include? prev_inline
|
78
78
|
# can't have two hard breaks in a row; can't start with a hard break
|
@@ -86,9 +86,8 @@ module Coradoc
|
|
86
86
|
out += "{empty}" if prev_inline == :hardbreak
|
87
87
|
out = "{empty}" if out.empty?
|
88
88
|
|
89
|
-
# attach = Coradoc::Generator.gen_adoc(@attached)
|
90
89
|
attach = @attached.map do |elem|
|
91
|
-
"+\n
|
90
|
+
"+\n#{Coradoc::Generator.gen_adoc(elem)}"
|
92
91
|
end.join
|
93
92
|
nest = Coradoc::Generator.gen_adoc(@nested)
|
94
93
|
out = " #{anchor}#{out}#{@line_break}"
|
@@ -37,12 +37,14 @@ module Coradoc
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def asciidoc?
|
40
|
-
@columns.any?(
|
40
|
+
@columns.any? { |c| c.respond_to?(:asciidoc?) && c.asciidoc? }
|
41
41
|
end
|
42
42
|
|
43
43
|
def to_adoc
|
44
44
|
delim = asciidoc? ? "\n" : " "
|
45
|
-
content = @columns.map
|
45
|
+
content = @columns.map do |col|
|
46
|
+
Coradoc::Generator.gen_adoc(col)
|
47
|
+
end.join(delim)
|
46
48
|
result = "#{content}\n"
|
47
49
|
result << "\n" if asciidoc?
|
48
50
|
table_header_row? ? result + underline_for : result
|
data/lib/coradoc/element/term.rb
CHANGED
@@ -25,7 +25,10 @@ module Coradoc
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def to_adoc
|
28
|
-
|
28
|
+
str = ""
|
29
|
+
str += "[[#{@id}]] " if @id
|
30
|
+
str += Coradoc::Generator.gen_adoc(@content) + @line_break.to_s
|
31
|
+
str
|
29
32
|
end
|
30
33
|
|
31
34
|
def treat_text_to_adoc(text)
|
@@ -29,7 +29,7 @@ module Coradoc
|
|
29
29
|
[:alt, String],
|
30
30
|
[:width, Integer],
|
31
31
|
[:height, Integer],
|
32
|
-
]
|
32
|
+
].freeze
|
33
33
|
|
34
34
|
VALIDATORS_NAMED = {
|
35
35
|
title: String,
|
@@ -44,7 +44,7 @@ module Coradoc
|
|
44
44
|
playlist: String,
|
45
45
|
options: many("autoplay", "loop", "modest",
|
46
46
|
"nocontrols", "nofullscreen", "muted"),
|
47
|
-
}
|
47
|
+
}.freeze
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/coradoc/input/adoc.rb
CHANGED
@@ -1,28 +1,30 @@
|
|
1
1
|
require "coradoc/input"
|
2
2
|
|
3
3
|
module Coradoc
|
4
|
-
module Input
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Input
|
5
|
+
module Adoc
|
6
|
+
def self.processor_id
|
7
|
+
:adoc
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.processor_match?(filename)
|
11
|
+
%w[.adoc].any? { |i| filename.downcase.end_with?(i) }
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def self.processor_execute(input, _options = {})
|
15
|
+
ast = Coradoc::Parser::Base.new.parse(input)
|
16
|
+
Coradoc::Transformer.transform(ast[:document])
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def self.processor_postprocess(input, options)
|
20
|
+
if options[:output_processor] == :adoc
|
21
|
+
Coradoc::Input::Html::Cleaner.new.tidy(input)
|
22
|
+
else
|
23
|
+
input
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
+
Coradoc::Input.define(self)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
data/lib/coradoc/input/docx.rb
CHANGED
@@ -3,33 +3,35 @@ require "coradoc/input/html"
|
|
3
3
|
require "fileutils"
|
4
4
|
|
5
5
|
module Coradoc
|
6
|
-
module Input
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module Input
|
7
|
+
module Docx
|
8
|
+
def self.processor_id
|
9
|
+
:docx
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def self.processor_match?(filename)
|
13
|
+
%w[.docx .doc].any? { |i| filename.downcase.end_with?(i) }
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def self.processor_execute(input, options = {})
|
17
|
+
image_dir = Dir.mktmpdir
|
18
|
+
options = options.merge(sourcedir: image_dir)
|
19
|
+
doc = WordToMarkdown.new(input, image_dir)
|
20
|
+
doc = Coradoc::Input::Html.cleaner.preprocess_word_html(doc.document.html)
|
21
|
+
options = WordToMarkdown::REVERSE_MARKDOWN_OPTIONS.merge(options)
|
22
|
+
Coradoc::Input::Html.to_coradoc(doc, options)
|
23
|
+
ensure
|
24
|
+
FileUtils.rm_rf(image_dir)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def self.processor_postprocess(data, options)
|
28
|
+
Coradoc::Input::Html.processor_postprocess(data, options)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
# This processor prefers to work on original files.
|
32
|
+
def self.processor_wants_filenames; true; end
|
32
33
|
|
33
|
-
|
34
|
+
Coradoc::Input.define(self)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
@@ -293,7 +293,7 @@ end
|
|
293
293
|
require 'coradoc/input/html'
|
294
294
|
|
295
295
|
# Options can be supplied as keyword arguments
|
296
|
-
Coradoc::Input::
|
296
|
+
Coradoc::Input::Html::HtmlConverter.to_coradoc("<b><i>Some input</i></b>")
|
297
297
|
----
|
298
298
|
|
299
299
|
|