coradoc 1.1.8 → 2.0.12
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.
Potentially problematic release.
This version of coradoc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/Rakefile +3 -12
- data/exe/coradoc +21 -2
- data/lib/coradoc/cli.rb +185 -91
- data/lib/coradoc/configurable.rb +527 -0
- data/lib/coradoc/coradoc.rb +463 -0
- data/lib/coradoc/core_model/annotation_block.rb +57 -0
- data/lib/coradoc/core_model/base.rb +172 -0
- data/lib/coradoc/core_model/bibliography.rb +41 -0
- data/lib/coradoc/core_model/bibliography_entry.rb +48 -0
- data/lib/coradoc/core_model/block.rb +63 -0
- data/lib/coradoc/core_model/children_content.rb +53 -0
- data/lib/coradoc/core_model/comment_block.rb +10 -0
- data/lib/coradoc/core_model/definition_item.rb +46 -0
- data/lib/coradoc/core_model/definition_list.rb +28 -0
- data/lib/coradoc/core_model/element_attribute.rb +26 -0
- data/lib/coradoc/core_model/example_block.rb +10 -0
- data/lib/coradoc/core_model/footnote.rb +92 -0
- data/lib/coradoc/core_model/horizontal_rule_block.rb +10 -0
- data/lib/coradoc/core_model/id_generator.rb +16 -0
- data/lib/coradoc/core_model/image.rb +66 -0
- data/lib/coradoc/core_model/inline_element.rb +140 -0
- data/lib/coradoc/core_model/list_block.rb +135 -0
- data/lib/coradoc/core_model/list_item.rb +142 -0
- data/lib/coradoc/core_model/listing_block.rb +13 -0
- data/lib/coradoc/core_model/literal_block.rb +10 -0
- data/lib/coradoc/core_model/metadata.rb +79 -0
- data/lib/coradoc/core_model/open_block.rb +10 -0
- data/lib/coradoc/core_model/paragraph_block.rb +10 -0
- data/lib/coradoc/core_model/pass_block.rb +10 -0
- data/lib/coradoc/core_model/quote_block.rb +12 -0
- data/lib/coradoc/core_model/reviewer_block.rb +10 -0
- data/lib/coradoc/core_model/sidebar_block.rb +10 -0
- data/lib/coradoc/core_model/source_block.rb +10 -0
- data/lib/coradoc/core_model/structural_element.rb +94 -0
- data/lib/coradoc/core_model/table.rb +148 -0
- data/lib/coradoc/core_model/term.rb +53 -0
- data/lib/coradoc/core_model/text_content.rb +22 -0
- data/lib/coradoc/core_model/toc.rb +105 -0
- data/lib/coradoc/core_model/toc_generator.rb +151 -0
- data/lib/coradoc/core_model/verse_block.rb +12 -0
- data/lib/coradoc/core_model.rb +77 -0
- data/lib/coradoc/document_builder.rb +184 -0
- data/lib/coradoc/document_manipulator.rb +203 -0
- data/lib/coradoc/errors.rb +312 -0
- data/lib/coradoc/format_module.rb +49 -0
- data/lib/coradoc/hooks.rb +176 -0
- data/lib/coradoc/input.rb +17 -7
- data/lib/coradoc/logger.rb +54 -0
- data/lib/coradoc/output.rb +17 -6
- data/lib/coradoc/performance_regression.rb +109 -0
- data/lib/coradoc/processor_registry.rb +50 -0
- data/lib/coradoc/query.rb +455 -0
- data/lib/coradoc/registry.rb +156 -0
- data/lib/coradoc/serializer/registry.rb +150 -0
- data/lib/coradoc/transform.rb +11 -0
- data/lib/coradoc/validation.rb +646 -0
- data/lib/coradoc/version.rb +1 -1
- data/lib/coradoc/visitor.rb +283 -0
- data/lib/coradoc.rb +40 -19
- metadata +67 -277
- data/.editorconfig +0 -15
- data/.envrc +0 -1
- data/.irbrc +0 -1
- data/.pryrc.sample +0 -1
- data/.rubocop.yml +0 -14
- data/.rubocop_todo.yml +0 -179
- data/CHANGELOG.md +0 -9
- data/CODE_OF_CONDUCT.md +0 -84
- data/Dockerfile +0 -19
- data/Gemfile +0 -16
- data/LICENSE.txt +0 -21
- data/Makefile +0 -35
- data/README.Docker.adoc +0 -57
- data/README.adoc +0 -119
- data/coradoc.gemspec +0 -40
- data/docker-compose.yml +0 -14
- data/exe/reverse_adoc +0 -81
- data/exe/w2a +0 -60
- data/flake.lock +0 -114
- data/flake.nix +0 -135
- data/lib/coradoc/converter.rb +0 -144
- data/lib/coradoc/document.rb +0 -77
- data/lib/coradoc/element/admonition.rb +0 -18
- data/lib/coradoc/element/attribute.rb +0 -36
- data/lib/coradoc/element/attribute_list.rb +0 -138
- data/lib/coradoc/element/audio.rb +0 -33
- data/lib/coradoc/element/author.rb +0 -24
- data/lib/coradoc/element/base.rb +0 -92
- data/lib/coradoc/element/bibliography.rb +0 -24
- data/lib/coradoc/element/bibliography_entry.rb +0 -24
- data/lib/coradoc/element/block/core.rb +0 -76
- data/lib/coradoc/element/block/example.rb +0 -23
- data/lib/coradoc/element/block/listing.rb +0 -21
- data/lib/coradoc/element/block/literal.rb +0 -21
- data/lib/coradoc/element/block/open.rb +0 -22
- data/lib/coradoc/element/block/pass.rb +0 -21
- data/lib/coradoc/element/block/quote.rb +0 -19
- data/lib/coradoc/element/block/reviewer_comment.rb +0 -19
- data/lib/coradoc/element/block/side.rb +0 -19
- data/lib/coradoc/element/block/sourcecode.rb +0 -21
- data/lib/coradoc/element/block.rb +0 -17
- data/lib/coradoc/element/break.rb +0 -11
- data/lib/coradoc/element/comment_block.rb +0 -22
- data/lib/coradoc/element/comment_line.rb +0 -18
- data/lib/coradoc/element/document_attributes.rb +0 -33
- data/lib/coradoc/element/header.rb +0 -22
- data/lib/coradoc/element/image/block_image.rb +0 -32
- data/lib/coradoc/element/image/core.rb +0 -58
- data/lib/coradoc/element/image/inline_image.rb +0 -12
- data/lib/coradoc/element/image.rb +0 -10
- data/lib/coradoc/element/include.rb +0 -18
- data/lib/coradoc/element/inline/anchor.rb +0 -19
- data/lib/coradoc/element/inline/attribute_reference.rb +0 -19
- data/lib/coradoc/element/inline/bold.rb +0 -25
- data/lib/coradoc/element/inline/cross_reference.rb +0 -46
- data/lib/coradoc/element/inline/footnote.rb +0 -24
- data/lib/coradoc/element/inline/hard_line_break.rb +0 -11
- data/lib/coradoc/element/inline/highlight.rb +0 -25
- data/lib/coradoc/element/inline/italic.rb +0 -25
- data/lib/coradoc/element/inline/link.rb +0 -42
- data/lib/coradoc/element/inline/monospace.rb +0 -25
- data/lib/coradoc/element/inline/quotation.rb +0 -20
- data/lib/coradoc/element/inline/small.rb +0 -19
- data/lib/coradoc/element/inline/span.rb +0 -37
- data/lib/coradoc/element/inline/subscript.rb +0 -20
- data/lib/coradoc/element/inline/superscript.rb +0 -20
- data/lib/coradoc/element/inline/underline.rb +0 -19
- data/lib/coradoc/element/inline.rb +0 -23
- data/lib/coradoc/element/list/core.rb +0 -51
- data/lib/coradoc/element/list/definition.rb +0 -29
- data/lib/coradoc/element/list/ordered.rb +0 -17
- data/lib/coradoc/element/list/unordered.rb +0 -17
- data/lib/coradoc/element/list.rb +0 -13
- data/lib/coradoc/element/list_item.rb +0 -98
- data/lib/coradoc/element/list_item_definition.rb +0 -32
- data/lib/coradoc/element/paragraph.rb +0 -37
- data/lib/coradoc/element/revision.rb +0 -27
- data/lib/coradoc/element/section.rb +0 -62
- data/lib/coradoc/element/table.rb +0 -91
- data/lib/coradoc/element/tag.rb +0 -19
- data/lib/coradoc/element/term.rb +0 -22
- data/lib/coradoc/element/text_element.rb +0 -92
- data/lib/coradoc/element/title.rb +0 -62
- data/lib/coradoc/element/video.rb +0 -50
- data/lib/coradoc/generator.rb +0 -19
- data/lib/coradoc/input/adoc.rb +0 -30
- data/lib/coradoc/input/docx.rb +0 -64
- data/lib/coradoc/input/html/LICENSE.txt +0 -25
- data/lib/coradoc/input/html/README.adoc +0 -308
- data/lib/coradoc/input/html/cleaner.rb +0 -142
- data/lib/coradoc/input/html/config.rb +0 -77
- data/lib/coradoc/input/html/converters/a.rb +0 -52
- data/lib/coradoc/input/html/converters/aside.rb +0 -16
- data/lib/coradoc/input/html/converters/audio.rb +0 -29
- data/lib/coradoc/input/html/converters/base.rb +0 -108
- data/lib/coradoc/input/html/converters/blockquote.rb +0 -22
- data/lib/coradoc/input/html/converters/br.rb +0 -15
- data/lib/coradoc/input/html/converters/bypass.rb +0 -81
- data/lib/coradoc/input/html/converters/code.rb +0 -23
- data/lib/coradoc/input/html/converters/div.rb +0 -19
- data/lib/coradoc/input/html/converters/dl.rb +0 -62
- data/lib/coradoc/input/html/converters/drop.rb +0 -26
- data/lib/coradoc/input/html/converters/em.rb +0 -21
- data/lib/coradoc/input/html/converters/figure.rb +0 -25
- data/lib/coradoc/input/html/converters/h.rb +0 -42
- data/lib/coradoc/input/html/converters/head.rb +0 -23
- data/lib/coradoc/input/html/converters/hr.rb +0 -15
- data/lib/coradoc/input/html/converters/ignore.rb +0 -20
- data/lib/coradoc/input/html/converters/img.rb +0 -110
- data/lib/coradoc/input/html/converters/li.rb +0 -17
- data/lib/coradoc/input/html/converters/mark.rb +0 -19
- data/lib/coradoc/input/html/converters/markup.rb +0 -31
- data/lib/coradoc/input/html/converters/math.rb +0 -38
- data/lib/coradoc/input/html/converters/ol.rb +0 -65
- data/lib/coradoc/input/html/converters/p.rb +0 -23
- data/lib/coradoc/input/html/converters/pass_through.rb +0 -17
- data/lib/coradoc/input/html/converters/pre.rb +0 -55
- data/lib/coradoc/input/html/converters/q.rb +0 -16
- data/lib/coradoc/input/html/converters/strong.rb +0 -20
- data/lib/coradoc/input/html/converters/sub.rb +0 -22
- data/lib/coradoc/input/html/converters/sup.rb +0 -22
- data/lib/coradoc/input/html/converters/table.rb +0 -319
- data/lib/coradoc/input/html/converters/td.rb +0 -81
- data/lib/coradoc/input/html/converters/text.rb +0 -32
- data/lib/coradoc/input/html/converters/th.rb +0 -18
- data/lib/coradoc/input/html/converters/tr.rb +0 -22
- data/lib/coradoc/input/html/converters/video.rb +0 -29
- data/lib/coradoc/input/html/converters.rb +0 -59
- data/lib/coradoc/input/html/errors.rb +0 -14
- data/lib/coradoc/input/html/html_converter.rb +0 -168
- data/lib/coradoc/input/html/plugin.rb +0 -131
- data/lib/coradoc/input/html/plugins/plateau.rb +0 -213
- data/lib/coradoc/input/html/postprocessor.rb +0 -220
- data/lib/coradoc/input/html.rb +0 -61
- data/lib/coradoc/legacy_parser.rb +0 -200
- data/lib/coradoc/oscal.rb +0 -99
- data/lib/coradoc/output/adoc.rb +0 -19
- data/lib/coradoc/output/coradoc_tree_debug.rb +0 -21
- data/lib/coradoc/parser/asciidoc/admonition.rb +0 -24
- data/lib/coradoc/parser/asciidoc/attribute_list.rb +0 -89
- data/lib/coradoc/parser/asciidoc/base.rb +0 -87
- data/lib/coradoc/parser/asciidoc/bibliography.rb +0 -29
- data/lib/coradoc/parser/asciidoc/block.rb +0 -94
- data/lib/coradoc/parser/asciidoc/citation.rb +0 -30
- data/lib/coradoc/parser/asciidoc/content.rb +0 -64
- data/lib/coradoc/parser/asciidoc/document_attributes.rb +0 -25
- data/lib/coradoc/parser/asciidoc/header.rb +0 -29
- data/lib/coradoc/parser/asciidoc/inline.rb +0 -195
- data/lib/coradoc/parser/asciidoc/list.rb +0 -115
- data/lib/coradoc/parser/asciidoc/paragraph.rb +0 -54
- data/lib/coradoc/parser/asciidoc/section.rb +0 -61
- data/lib/coradoc/parser/asciidoc/table.rb +0 -32
- data/lib/coradoc/parser/asciidoc/term.rb +0 -41
- data/lib/coradoc/parser/asciidoc/text.rb +0 -158
- data/lib/coradoc/parser/base.rb +0 -40
- data/lib/coradoc/parser.rb +0 -11
- data/lib/coradoc/reverse_adoc.rb +0 -18
- data/lib/coradoc/transformer.rb +0 -476
- data/lib/coradoc/util.rb +0 -12
- data/lib/reverse_adoc.rb +0 -20
- data/utils/inspect_asciidoc.rb +0 -29
- data/utils/parser_analyzer.rb +0 -66
- data/utils/round_trip.rb +0 -53
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Revision < Base
|
|
4
|
-
attr_accessor :number, :date, :remark
|
|
5
|
-
|
|
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
|
|
13
|
-
|
|
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}: #{@remark}\n"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Section < Base
|
|
4
|
-
attr_accessor :id, :title, :attrs, :contents, :sections, :anchor
|
|
5
|
-
|
|
6
|
-
declare_children :id, :title, :contents, :sections
|
|
7
|
-
|
|
8
|
-
def initialize(title, options = {})
|
|
9
|
-
@title = title
|
|
10
|
-
@id = options.fetch(:id, nil)
|
|
11
|
-
@id = nil if @id == ""
|
|
12
|
-
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
|
13
|
-
@attrs = options.fetch(:attribute_list, "")
|
|
14
|
-
@contents = options.fetch(:contents, [])
|
|
15
|
-
@sections = options.fetch(:sections, [])
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def glossaries
|
|
19
|
-
@glossaries ||= extract_glossaries
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def content
|
|
23
|
-
if contents.count == 1 && contents.first.is_a?(Coradoc::Element::Paragraph)
|
|
24
|
-
contents.first
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def to_adoc
|
|
29
|
-
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
|
30
|
-
title = Coradoc::Generator.gen_adoc(@title)
|
|
31
|
-
attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n"
|
|
32
|
-
content = Coradoc::Generator.gen_adoc(@contents)
|
|
33
|
-
sections = Coradoc::Generator.gen_adoc(@sections)
|
|
34
|
-
|
|
35
|
-
# A block of " +\n"s isn't parsed correctly. It needs to start
|
|
36
|
-
# with something.
|
|
37
|
-
content = " #{content}" if content.start_with?(" +\n")
|
|
38
|
-
|
|
39
|
-
# Only try to postprocess elements that are text,
|
|
40
|
-
# otherwise we could strip markup.
|
|
41
|
-
if Coradoc.a_single?(@contents, Coradoc::Element::TextElement)
|
|
42
|
-
content = Coradoc.strip_unicode(content)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
"\n#{anchor}" << attrs << title << content << sections << "\n"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Check for cases when Section is simply an equivalent of an empty <DIV>
|
|
49
|
-
# HTML element and if it happens inside some other block element, can be
|
|
50
|
-
# safely collapsed.
|
|
51
|
-
def safe_to_collapse?
|
|
52
|
-
@title.nil? && @sections.empty?
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def extract_glossaries
|
|
58
|
-
contents.grep(Coradoc::Element::Glossaries).first
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Table < Base
|
|
4
|
-
attr_accessor :title, :rows, :content, :id
|
|
5
|
-
|
|
6
|
-
declare_children :title, :rows, :id
|
|
7
|
-
|
|
8
|
-
def initialize(title, rows, options = {})
|
|
9
|
-
@rows = rows
|
|
10
|
-
@title = title
|
|
11
|
-
@id = options.fetch(:id, nil)
|
|
12
|
-
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
|
13
|
-
@attrs = options.fetch(:attributes, nil)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def to_adoc
|
|
17
|
-
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
|
18
|
-
attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n"
|
|
19
|
-
title = Coradoc::Generator.gen_adoc(@title)
|
|
20
|
-
title = title.empty? ? "" : ".#{title}\n"
|
|
21
|
-
content = @rows.map(&:to_adoc).join
|
|
22
|
-
"\n\n#{anchor}#{attrs}#{title}|===\n" << content << "\n|===\n"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class Row < Base
|
|
26
|
-
attr_accessor :columns, :header
|
|
27
|
-
|
|
28
|
-
declare_children :columns
|
|
29
|
-
|
|
30
|
-
def initialize(columns, header = false)
|
|
31
|
-
@columns = columns
|
|
32
|
-
@header = header
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def table_header_row?
|
|
36
|
-
@header
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def asciidoc?
|
|
40
|
-
@columns.any? { |c| c.respond_to?(:asciidoc?) && c.asciidoc? }
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def to_adoc
|
|
44
|
-
delim = asciidoc? ? "\n" : " "
|
|
45
|
-
content = @columns.map do |col|
|
|
46
|
-
Coradoc::Generator.gen_adoc(col)
|
|
47
|
-
end.join(delim)
|
|
48
|
-
result = "#{content}\n"
|
|
49
|
-
result << "\n" if asciidoc?
|
|
50
|
-
table_header_row? ? result + underline_for : result
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def underline_for
|
|
54
|
-
"\n"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
class Cell < Base
|
|
59
|
-
attr_accessor :content, :anchor, :id, :colrowattr, :alignattr, :style
|
|
60
|
-
|
|
61
|
-
declare_children :content, :anchor, :id
|
|
62
|
-
|
|
63
|
-
def initialize(options = {})
|
|
64
|
-
super()
|
|
65
|
-
@id = options.fetch(:id, nil)
|
|
66
|
-
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
|
67
|
-
@colrowattr = options.fetch(:colrowattr, "")
|
|
68
|
-
@alignattr = options.fetch(:alignattr, "")
|
|
69
|
-
@style = options.fetch(:style, "")
|
|
70
|
-
@content = options.fetch(:content, "")
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def asciidoc?
|
|
74
|
-
@style.include?("a")
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def to_adoc
|
|
78
|
-
anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
|
|
79
|
-
content = simplify_block_content(@content)
|
|
80
|
-
content = Coradoc::Generator.gen_adoc(content)
|
|
81
|
-
# Only try to postprocess elements that are text,
|
|
82
|
-
# otherwise we could strip markup.
|
|
83
|
-
if Coradoc.a_single?(@content, Coradoc::Element::TextElement)
|
|
84
|
-
content = Coradoc.strip_unicode(content)
|
|
85
|
-
end
|
|
86
|
-
"#{@colrowattr}#{@alignattr}#{@style}| #{anchor}#{content}"
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
data/lib/coradoc/element/tag.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Tag < Base
|
|
4
|
-
attr_accessor :name, :prefix, :attrs, :line_break
|
|
5
|
-
|
|
6
|
-
def initialize(name, options = {})
|
|
7
|
-
@name = name
|
|
8
|
-
@prefix = options.fetch(:prefix, "tag")
|
|
9
|
-
@attrs = options.fetch(:attribute_list, AttributeList.new)
|
|
10
|
-
@line_break = options.fetch(:line_break, "\n")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def to_adoc
|
|
14
|
-
attrs = @attrs.to_adoc
|
|
15
|
-
"// #{@prefix}::#{@name}#{attrs}#{@line_break}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
data/lib/coradoc/element/term.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Term < Base
|
|
4
|
-
attr_accessor :term, :options
|
|
5
|
-
|
|
6
|
-
declare_children :term, :options
|
|
7
|
-
|
|
8
|
-
def initialize(term, options = {})
|
|
9
|
-
@term = term
|
|
10
|
-
@type = options.fetch(:type, nil)
|
|
11
|
-
@lang = options.fetch(:lang, :en)
|
|
12
|
-
@line_break = options.fetch(:line_break, "")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def to_adoc
|
|
16
|
-
return "#{@type}:[#{@term}]#{@line_break}" if @lang == :en
|
|
17
|
-
|
|
18
|
-
"[#{@type}]##{@term}##{@line_break}"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class TextElement < Base
|
|
4
|
-
attr_accessor :id, :content, :line_break
|
|
5
|
-
|
|
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
|
-
@html_cleanup = options.fetch(:html_cleanup, false)
|
|
13
|
-
if @html_cleanup
|
|
14
|
-
@content = treat_text_to_adoc(@content)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def inspect
|
|
19
|
-
str = "TextElement"
|
|
20
|
-
str += "(#{@id})" if @id
|
|
21
|
-
str += ": "
|
|
22
|
-
str += @content.inspect
|
|
23
|
-
str += " + #{@line_break.inspect}" unless line_break.to_s.empty?
|
|
24
|
-
str
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def to_adoc
|
|
28
|
-
str = ""
|
|
29
|
-
str += "[[#{@id}]] " if @id
|
|
30
|
-
str += Coradoc::Generator.gen_adoc(@content) + @line_break.to_s
|
|
31
|
-
str
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def treat_text_to_adoc(text)
|
|
35
|
-
text = preserve_nbsp(text)
|
|
36
|
-
text = remove_border_newlines(text)
|
|
37
|
-
text = remove_inner_newlines(text)
|
|
38
|
-
text = self.class.escape_keychars(text)
|
|
39
|
-
|
|
40
|
-
text = preserve_keychars_within_backticks(text)
|
|
41
|
-
escape_links(text)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def preserve_nbsp(text)
|
|
45
|
-
text.gsub(/\u00A0/, " ")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def escape_links(text)
|
|
49
|
-
text.gsub(/<<([^ ][^>]*)>>/, "\\<<\\1>>")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def remove_border_newlines(text)
|
|
53
|
-
text.gsub(/\A\n+/, "").gsub(/\n+\z/, "")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def remove_inner_newlines(text)
|
|
57
|
-
text.tr("\n\t", " ").squeeze(" ")
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def preserve_keychars_within_backticks(text)
|
|
61
|
-
text.gsub(/`.*?`/) do |match|
|
|
62
|
-
match.gsub('\_', "_").gsub('\*', "*")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def self.escape_keychars(string)
|
|
67
|
-
subs = { "*" => '\*', "_" => '\_' }
|
|
68
|
-
string
|
|
69
|
-
.gsub(/((?<=\s)[\*_]+)|[\*_]+(?=\s)/) do |n|
|
|
70
|
-
n.chars.map do |char|
|
|
71
|
-
subs[char]
|
|
72
|
-
end.join
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
class LineBreak < Base
|
|
78
|
-
attr_reader :line_break
|
|
79
|
-
|
|
80
|
-
def initialize(line_break)
|
|
81
|
-
@line_break = line_break
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def to_adoc
|
|
85
|
-
@line_break
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
class Highlight < Element::TextElement
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Title < Base
|
|
4
|
-
attr_accessor :id, :content, :line_break, :style, :level_int
|
|
5
|
-
|
|
6
|
-
declare_children :id, :content
|
|
7
|
-
|
|
8
|
-
def initialize(content, level, options = {})
|
|
9
|
-
@level_int = level
|
|
10
|
-
# @level_int = level.length - 1 if level.is_a?(String)
|
|
11
|
-
@content = content
|
|
12
|
-
@id = options.fetch(:id, nil)
|
|
13
|
-
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
|
14
|
-
@line_break = options.fetch(:line_break, "")
|
|
15
|
-
@style = options.fetch(:style, nil)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def level
|
|
19
|
-
@level ||= level_from_string
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def to_adoc
|
|
23
|
-
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
|
24
|
-
content = Coradoc.strip_unicode(Coradoc::Generator.gen_adoc(@content))
|
|
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?
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
alias :text :content
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def level_from_string
|
|
52
|
-
case @level_int
|
|
53
|
-
when 2 then :heading_two
|
|
54
|
-
when 3 then :heading_three
|
|
55
|
-
when 4 then :heading_four
|
|
56
|
-
when 5 then :heading_five
|
|
57
|
-
else :unknown
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Video < Base
|
|
4
|
-
attr_accessor :id, :title, :src, :options
|
|
5
|
-
|
|
6
|
-
declare_children :id, :anchor, :attributes
|
|
7
|
-
|
|
8
|
-
def initialize(title, options = {})
|
|
9
|
-
@title = title
|
|
10
|
-
@id = options.fetch(:id, nil)
|
|
11
|
-
@anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
|
|
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
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def to_adoc
|
|
21
|
-
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
|
22
|
-
title = ".#{@title}\n" unless @title.empty?
|
|
23
|
-
attrs = @attributes.to_adoc
|
|
24
|
-
[anchor, title, "video::", @src, attrs].join("")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
extend AttributeList::Matchers
|
|
28
|
-
VALIDATORS_POSITIONAL = [
|
|
29
|
-
[:alt, String],
|
|
30
|
-
[:width, Integer],
|
|
31
|
-
[:height, Integer],
|
|
32
|
-
].freeze
|
|
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
|
-
}.freeze
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
data/lib/coradoc/generator.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
elsif content.is_a?(Parslet::Slice)
|
|
15
|
-
content.to_s
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
data/lib/coradoc/input/adoc.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require "coradoc/input"
|
|
2
|
-
|
|
3
|
-
module Coradoc
|
|
4
|
-
module Input
|
|
5
|
-
module Adoc
|
|
6
|
-
def self.processor_id
|
|
7
|
-
:adoc
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.processor_match?(filename)
|
|
11
|
-
%w[.adoc].any? { |i| filename.downcase.end_with?(i) }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.processor_execute(input, _options = {})
|
|
15
|
-
ast = Coradoc::Parser::Base.new.parse(input)
|
|
16
|
-
Coradoc::Transformer.transform(ast[:document])
|
|
17
|
-
end
|
|
18
|
-
|
|
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
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
Coradoc::Input.define(self)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
data/lib/coradoc/input/docx.rb
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require "coradoc/input/html"
|
|
2
|
-
require "fileutils"
|
|
3
|
-
|
|
4
|
-
module Coradoc
|
|
5
|
-
module Input
|
|
6
|
-
module Docx
|
|
7
|
-
WORD_TO_MARKDOWN_MISSING_MSG =
|
|
8
|
-
"DOCX input requires the 'word-to-markdown' gem, " \
|
|
9
|
-
"which is unavailable on this platform. " \
|
|
10
|
-
"See https://github.com/metanorma/coradoc/issues/192".freeze
|
|
11
|
-
|
|
12
|
-
def self.windows_ruby4?
|
|
13
|
-
Gem.win_platform? &&
|
|
14
|
-
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("4.0")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
WORD_TO_MARKDOWN_AVAILABLE = if windows_ruby4?
|
|
18
|
-
false
|
|
19
|
-
else
|
|
20
|
-
begin
|
|
21
|
-
require "word-to-markdown"
|
|
22
|
-
true
|
|
23
|
-
rescue LoadError
|
|
24
|
-
false
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def self.processor_id
|
|
29
|
-
:docx
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def self.processor_match?(filename)
|
|
33
|
-
%w[.docx .doc].any? { |i| filename.downcase.end_with?(i) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def self.assert_word_to_markdown!
|
|
37
|
-
return if WORD_TO_MARKDOWN_AVAILABLE
|
|
38
|
-
|
|
39
|
-
raise LoadError, WORD_TO_MARKDOWN_MISSING_MSG
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def self.processor_execute(input, options = {})
|
|
43
|
-
assert_word_to_markdown!
|
|
44
|
-
image_dir = Dir.mktmpdir
|
|
45
|
-
options = options.merge(sourcedir: image_dir)
|
|
46
|
-
doc = WordToMarkdown.new(input, image_dir)
|
|
47
|
-
doc = Coradoc::Input::Html.cleaner.preprocess_word_html(doc.document.html)
|
|
48
|
-
options = WordToMarkdown::REVERSE_MARKDOWN_OPTIONS.merge(options)
|
|
49
|
-
Coradoc::Input::Html.to_coradoc(doc, options)
|
|
50
|
-
ensure
|
|
51
|
-
FileUtils.rm_rf(image_dir)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def self.processor_postprocess(data, options)
|
|
55
|
-
Coradoc::Input::Html.processor_postprocess(data, options)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# This processor prefers to work on original files.
|
|
59
|
-
def self.processor_wants_filenames; true; end
|
|
60
|
-
|
|
61
|
-
Coradoc::Input.define(self)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
BSD 2-Clause License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018, Ribose
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions are met:
|
|
8
|
-
|
|
9
|
-
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
-
list of conditions and the following disclaimer.
|
|
11
|
-
|
|
12
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
-
this list of conditions and the following disclaimer in the documentation
|
|
14
|
-
and/or other materials provided with the distribution.
|
|
15
|
-
|
|
16
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
20
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
22
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
23
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|