coradoc 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +35 -0
  3. data/{.docker/readme.md → README.Docker.adoc} +21 -25
  4. data/README.adoc +121 -0
  5. data/coradoc.gemspec +4 -0
  6. data/docker-compose.yml +14 -0
  7. data/exe/coradoc +5 -0
  8. data/exe/reverse_adoc +24 -34
  9. data/exe/w2a +16 -28
  10. data/lib/coradoc/cli.rb +105 -0
  11. data/lib/coradoc/converter.rb +145 -0
  12. data/lib/coradoc/document.rb +13 -0
  13. data/lib/coradoc/element/admonition.rb +5 -0
  14. data/lib/coradoc/element/attribute_list.rb +1 -1
  15. data/lib/coradoc/element/author.rb +4 -4
  16. data/lib/coradoc/element/bibliography.rb +24 -0
  17. data/lib/coradoc/element/bibliography_entry.rb +24 -0
  18. data/lib/coradoc/element/block/core.rb +6 -4
  19. data/lib/coradoc/element/block/example.rb +1 -0
  20. data/lib/coradoc/element/block/pass.rb +21 -0
  21. data/lib/coradoc/element/block/quote.rb +1 -1
  22. data/lib/coradoc/element/block/reviewer_comment.rb +19 -0
  23. data/lib/coradoc/element/block/side.rb +4 -2
  24. data/lib/coradoc/element/block/sourcecode.rb +1 -0
  25. data/lib/coradoc/element/block.rb +2 -0
  26. data/lib/coradoc/element/comment_block.rb +22 -0
  27. data/lib/coradoc/element/comment_line.rb +18 -0
  28. data/lib/coradoc/element/document_attributes.rb +8 -1
  29. data/lib/coradoc/element/header.rb +1 -1
  30. data/lib/coradoc/element/image/block_image.rb +8 -0
  31. data/lib/coradoc/element/image/core.rb +6 -5
  32. data/lib/coradoc/element/include.rb +18 -0
  33. data/lib/coradoc/element/inline/citation.rb +24 -0
  34. data/lib/coradoc/element/inline/cross_reference.rb +29 -8
  35. data/lib/coradoc/element/inline.rb +1 -0
  36. data/lib/coradoc/element/list/core.rb +10 -2
  37. data/lib/coradoc/element/list_item.rb +7 -5
  38. data/lib/coradoc/element/paragraph.rb +8 -5
  39. data/lib/coradoc/element/revision.rb +1 -1
  40. data/lib/coradoc/element/section.rb +6 -4
  41. data/lib/coradoc/element/table.rb +2 -2
  42. data/lib/coradoc/element/tag.rb +19 -0
  43. data/lib/coradoc/element/term.rb +21 -0
  44. data/lib/coradoc/element/text_element.rb +9 -1
  45. data/lib/coradoc/element/title.rb +1 -1
  46. data/lib/coradoc/generator.rb +2 -0
  47. data/lib/coradoc/input/adoc.rb +28 -0
  48. data/lib/coradoc/input/docx.rb +35 -0
  49. data/lib/coradoc/{reverse_adoc → input/html}/README.adoc +9 -9
  50. data/lib/coradoc/{reverse_adoc → input/html}/cleaner.rb +18 -4
  51. data/lib/coradoc/input/html/config.rb +75 -0
  52. data/lib/coradoc/{reverse_adoc → input/html}/converters/a.rb +1 -1
  53. data/lib/coradoc/{reverse_adoc → input/html}/converters/aside.rb +1 -1
  54. data/lib/coradoc/{reverse_adoc → input/html}/converters/audio.rb +1 -1
  55. data/lib/coradoc/{reverse_adoc → input/html}/converters/base.rb +7 -7
  56. data/lib/coradoc/{reverse_adoc → input/html}/converters/blockquote.rb +2 -2
  57. data/lib/coradoc/{reverse_adoc → input/html}/converters/br.rb +1 -1
  58. data/lib/coradoc/{reverse_adoc → input/html}/converters/bypass.rb +1 -1
  59. data/lib/coradoc/{reverse_adoc → input/html}/converters/code.rb +1 -1
  60. data/lib/coradoc/{reverse_adoc → input/html}/converters/div.rb +1 -1
  61. data/lib/coradoc/{reverse_adoc → input/html}/converters/dl.rb +1 -1
  62. data/lib/coradoc/{reverse_adoc → input/html}/converters/drop.rb +1 -1
  63. data/lib/coradoc/{reverse_adoc → input/html}/converters/em.rb +1 -1
  64. data/lib/coradoc/{reverse_adoc → input/html}/converters/figure.rb +1 -1
  65. data/lib/coradoc/{reverse_adoc → input/html}/converters/h.rb +8 -6
  66. data/lib/coradoc/{reverse_adoc → input/html}/converters/head.rb +1 -1
  67. data/lib/coradoc/{reverse_adoc → input/html}/converters/hr.rb +1 -1
  68. data/lib/coradoc/{reverse_adoc → input/html}/converters/ignore.rb +1 -1
  69. data/lib/coradoc/{reverse_adoc → input/html}/converters/img.rb +7 -7
  70. data/lib/coradoc/{reverse_adoc → input/html}/converters/li.rb +1 -1
  71. data/lib/coradoc/{reverse_adoc → input/html}/converters/mark.rb +1 -1
  72. data/lib/coradoc/{reverse_adoc → input/html}/converters/markup.rb +1 -1
  73. data/lib/coradoc/{reverse_adoc → input/html}/converters/math.rb +3 -3
  74. data/lib/coradoc/{reverse_adoc → input/html}/converters/ol.rb +1 -1
  75. data/lib/coradoc/{reverse_adoc → input/html}/converters/p.rb +1 -1
  76. data/lib/coradoc/{reverse_adoc → input/html}/converters/pass_through.rb +1 -1
  77. data/lib/coradoc/{reverse_adoc → input/html}/converters/pre.rb +1 -1
  78. data/lib/coradoc/{reverse_adoc → input/html}/converters/q.rb +1 -1
  79. data/lib/coradoc/{reverse_adoc → input/html}/converters/strong.rb +1 -1
  80. data/lib/coradoc/{reverse_adoc → input/html}/converters/sub.rb +1 -1
  81. data/lib/coradoc/{reverse_adoc → input/html}/converters/sup.rb +1 -1
  82. data/lib/coradoc/{reverse_adoc → input/html}/converters/table.rb +4 -4
  83. data/lib/coradoc/{reverse_adoc → input/html}/converters/td.rb +1 -1
  84. data/lib/coradoc/{reverse_adoc → input/html}/converters/text.rb +2 -2
  85. data/lib/coradoc/{reverse_adoc → input/html}/converters/th.rb +1 -1
  86. data/lib/coradoc/{reverse_adoc → input/html}/converters/tr.rb +1 -1
  87. data/lib/coradoc/{reverse_adoc → input/html}/converters/video.rb +1 -1
  88. data/lib/coradoc/input/html/converters.rb +57 -0
  89. data/lib/coradoc/input/html/errors.rb +12 -0
  90. data/lib/coradoc/{reverse_adoc → input/html}/html_converter.rb +37 -22
  91. data/lib/coradoc/{reverse_adoc → input/html}/plugin.rb +6 -6
  92. data/lib/coradoc/{reverse_adoc → input/html}/plugins/plateau.rb +3 -3
  93. data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +3 -3
  94. data/lib/coradoc/input/html.rb +59 -0
  95. data/lib/coradoc/input.rb +12 -0
  96. data/lib/coradoc/output/adoc.rb +17 -0
  97. data/lib/coradoc/output/coradoc_tree_debug.rb +19 -0
  98. data/lib/coradoc/output.rb +11 -0
  99. data/lib/coradoc/parser/asciidoc/admonition.rb +24 -0
  100. data/lib/coradoc/parser/asciidoc/attribute_list.rb +67 -0
  101. data/lib/coradoc/parser/asciidoc/base.rb +101 -13
  102. data/lib/coradoc/parser/asciidoc/bibliography.rb +30 -0
  103. data/lib/coradoc/parser/asciidoc/block.rb +82 -0
  104. data/lib/coradoc/parser/asciidoc/citation.rb +48 -0
  105. data/lib/coradoc/parser/asciidoc/content.rb +15 -120
  106. data/lib/coradoc/parser/asciidoc/document_attributes.rb +12 -5
  107. data/lib/coradoc/parser/asciidoc/header.rb +1 -4
  108. data/lib/coradoc/parser/asciidoc/inline.rb +72 -0
  109. data/lib/coradoc/parser/asciidoc/list.rb +81 -0
  110. data/lib/coradoc/parser/asciidoc/paragraph.rb +33 -0
  111. data/lib/coradoc/parser/asciidoc/section.rb +36 -31
  112. data/lib/coradoc/parser/asciidoc/table.rb +32 -0
  113. data/lib/coradoc/parser/asciidoc/term.rb +23 -0
  114. data/lib/coradoc/parser/base.rb +39 -4
  115. data/lib/coradoc/reverse_adoc.rb +16 -28
  116. data/lib/coradoc/transformer.rb +353 -82
  117. data/lib/coradoc/util.rb +1 -1
  118. data/lib/coradoc/version.rb +1 -1
  119. data/lib/coradoc.rb +8 -5
  120. data/lib/reverse_adoc.rb +6 -6
  121. data/utils/parser_analyzer.rb +66 -0
  122. data/utils/round_trip.rb +37 -0
  123. metadata +112 -53
  124. data/.docker/Makefile +0 -35
  125. data/.docker/docker-compose.yml +0 -14
  126. data/Makefile +0 -1
  127. data/README.md +0 -73
  128. data/docker-compose.yml +0 -1
  129. data/lib/coradoc/reverse_adoc/config.rb +0 -73
  130. data/lib/coradoc/reverse_adoc/converters.rb +0 -55
  131. data/lib/coradoc/reverse_adoc/errors.rb +0 -10
  132. /data/{.docker/Dockerfile → Dockerfile} +0 -0
  133. /data/lib/coradoc/{reverse_adoc → input/html}/LICENSE.txt +0 -0
@@ -0,0 +1,145 @@
1
+ require "fileutils"
2
+
3
+ module Coradoc
4
+ class Converter
5
+ attr_accessor :input, :output, :config
6
+
7
+ def initialize(input = nil, output = nil, **config)
8
+ @input = input || $stdin
9
+ @output = output || $stdout
10
+
11
+ @config = {
12
+ input_options: {},
13
+ output_options: {},
14
+ }.merge(config)
15
+
16
+ yield if block_given?
17
+ end
18
+
19
+ def self.call(*args, **kwargs, &block)
20
+ new(*args, **kwargs, &block).convert
21
+ end
22
+
23
+ def input_processor
24
+ if config[:input_processor]
25
+ Input[config[:input_processor]]
26
+ else
27
+ Input.select_processor(input)
28
+ end
29
+ end
30
+
31
+ def output_processor
32
+ if config[:output_processor]
33
+ Output[config[:output_processor]]
34
+ else
35
+ Output.select_processor(output)
36
+ end
37
+ end
38
+
39
+ def convert(data = nil)
40
+ input_id = input_processor.processor_id
41
+ output_id = output_processor.processor_id
42
+
43
+ unless data
44
+ input = self.input
45
+ input = File.open(input, "rb") if input.is_a? String
46
+ data = input.read
47
+ input_path = input.path if input.respond_to? :path
48
+ end
49
+
50
+ # Some input processors may prefer filenames
51
+ if input_processor.respond_to? :processor_wants_filenames
52
+ unless input.respond_to? :path
53
+ raise NoInputPathError,
54
+ "no input path given, but #{input_processor} wants that " +
55
+ "form. Ensure you don't read from standard input."
56
+ end
57
+
58
+ data = input.path
59
+ end
60
+
61
+ # We may need to configure destination path.
62
+ output = self.output
63
+ if output.is_a? String
64
+ FileUtils.mkdir_p(File.dirname(output))
65
+ output = File.open(output, "wb")
66
+ end
67
+ output_path = output.path if output.respond_to?(:path)
68
+
69
+ input_options = config[:input_options]
70
+ input_options = input_options.merge(destination: output_path) if output_path
71
+ input_options = input_options.merge(sourcedir: File.dirname(input_path)) if input_path
72
+
73
+ data = input_processor.processor_execute(data, input_options)
74
+
75
+ # Two options are possible at this point:
76
+ # Either we have a document we want to write to some output, or
77
+ # we have a Hash, that contains a list of files and their
78
+ # documents (where a nil key denotes the main file). Let's normalize
79
+ # those cases.
80
+ data = { nil => data } unless data.is_a? Hash
81
+
82
+ # Let's check an edge case of non-nil keys and no output path
83
+ if !output_path && data.keys.any? { |i| !i.nil? }
84
+ raise NoOutputPathError,
85
+ "no output path given, while wanting to write multiple files"
86
+ end
87
+
88
+ data = output_processor.processor_execute(data, config[:output_options])
89
+
90
+ if input_processor.respond_to?(:processor_postprocess)
91
+ data = input_processor.processor_postprocess(
92
+ data, input_options.merge(output_processor: output_id)
93
+ )
94
+ end
95
+
96
+ # Now we have all, let's write.
97
+ data.each do |filename, content|
98
+ if filename.nil?
99
+ file = output
100
+ else
101
+ dirname = File.dirname(output_path)
102
+ file = "#{dirname}/#{filename}"
103
+ FileUtils.mkdir_p(File.dirname(file))
104
+ file = File.open(file, "wb")
105
+ end
106
+
107
+ file.write(content)
108
+ file.close
109
+ end
110
+ end
111
+
112
+ class ConverterArgumentError < ArgumentError; end
113
+
114
+ class NoInputPathError < ConverterArgumentError; end
115
+ class NoOutputPathError < ConverterArgumentError; end
116
+ class NoProcessorError < ConverterArgumentError; end
117
+
118
+ module CommonInputOutputMethods
119
+ def define(const)
120
+ @processors[const.processor_id] = const
121
+ end
122
+
123
+ def [](id)
124
+ @processors[id.to_sym]
125
+ end
126
+
127
+ def keys
128
+ @processors.keys
129
+ end
130
+
131
+ def select_processor(filename)
132
+ filename = filename.path if filename.respond_to? :path
133
+ unless filename.is_a? String
134
+ raise Converter::NoProcessorError,
135
+ "Can't find a path for #{filename}. You must manually select the processor."
136
+ end
137
+
138
+ @processors.values.find do |i|
139
+ i.processor_match?(filename)
140
+ end or raise Converter::NoProcessorError,
141
+ "You must manually select the processor for #{filename}"
142
+ end
143
+ end
144
+ end
145
+ end
@@ -1,6 +1,11 @@
1
1
  require_relative "element/base"
2
2
  require_relative "element/title"
3
3
  require_relative "element/block"
4
+ require_relative "element/bibliography"
5
+ require_relative "element/bibliography_entry"
6
+ require_relative "element/comment_block"
7
+ require_relative "element/comment_line"
8
+ require_relative "element/include"
4
9
  require_relative "element/section"
5
10
  require_relative "element/attribute"
6
11
  require_relative "element/attribute_list"
@@ -12,12 +17,14 @@ require_relative "element/header"
12
17
  require_relative "element/document_attributes"
13
18
  require_relative "element/paragraph"
14
19
  require_relative "element/table"
20
+ require_relative "element/tag"
15
21
  require_relative "element/list"
16
22
  require_relative "element/inline"
17
23
  require_relative "element/image"
18
24
  require_relative "element/audio"
19
25
  require_relative "element/video"
20
26
  require_relative "element/break"
27
+ require_relative "element/term"
21
28
 
22
29
  module Coradoc
23
30
  class Document
@@ -60,5 +67,11 @@ module Coradoc
60
67
  @sections = options.fetch(:sections, [])
61
68
  self
62
69
  end
70
+
71
+ def to_adoc
72
+ Coradoc::Generator.gen_adoc(@header) +
73
+ Coradoc::Generator.gen_adoc(@document_attributes) +
74
+ Coradoc::Generator.gen_adoc(@sections)
75
+ end
63
76
  end
64
77
  end
@@ -8,6 +8,11 @@ module Coradoc
8
8
  @type = type.downcase.to_sym
9
9
  @line_break = options.fetch(:line_break, "")
10
10
  end
11
+
12
+ def to_adoc
13
+ content = Coradoc::Generator.gen_adoc(@content)
14
+ "#{type.to_s.upcase}: #{content}#{@line_break}"
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -71,7 +71,7 @@ module Coradoc
71
71
  adoc << @named.map do |k, v|
72
72
  if v.is_a?(String)
73
73
  v = v.gsub("\"", "\\\"")
74
- if v.include?(" ") || v.include?(",") || v.include?('"')
74
+ if v.include?(",") || v.include?('"')
75
75
  v = "\"#{v}\""
76
76
  end
77
77
  elsif v.is_a?(Array)
@@ -13,10 +13,10 @@ module Coradoc
13
13
  end
14
14
 
15
15
  def to_adoc
16
- adoc = "#{@first_name} "
17
- adoc << "#{@middle_name} " if @middle_name
18
- adoc << @last_name.to_s
19
- adoc << " <#{@email}>" if @email
16
+ adoc = "#{@first_name}"
17
+ adoc << " #{@middle_name}" if @middle_name
18
+ adoc << " #{@last_name.to_s}"
19
+ adoc << " <#{@email}>\n" if @email
20
20
  adoc
21
21
  end
22
22
  end
@@ -0,0 +1,24 @@
1
+ module Coradoc
2
+ module Element
3
+ class Bibliography < Base
4
+ attr_accessor :id, :title, :entries
5
+
6
+ def initialize(options = {})
7
+ @id = options.fetch(:id, nil)
8
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
9
+ @title = options.fetch(:title, nil)
10
+ @entries = options.fetch(:entries,nil)
11
+ end
12
+
13
+ def to_adoc
14
+ adoc = "#{gen_anchor}\n"
15
+ adoc << "[bibliography]"
16
+ adoc << "== #{@title}\n\n"
17
+ @entries.each do |entry|
18
+ adoc << "#{entry.to_adoc}\n"
19
+ end
20
+ adoc
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Coradoc
2
+ module Element
3
+ class BibliographyEntry < Base
4
+ attr_accessor :anchor_name, :document_id, :ref_text, :line_break
5
+
6
+ def initialize(options = {})
7
+ @anchor_name = options.fetch(:anchor_name, nil)
8
+ @document_id = options.fetch(:document_id, nil)
9
+ @ref_text = options.fetch(:ref_text, nil)
10
+ @line_break = options.fetch(:line_break, "")
11
+ end
12
+
13
+ def to_adoc
14
+ text = Coradoc::Generator.gen_adoc(@ref_text) if @ref_text
15
+ adoc = "* [[[#{@anchor_name}"
16
+ adoc << ",#{@document_id}" if @document_id
17
+ adoc << "]]]"
18
+ adoc << "#{text}" if @ref_text
19
+ adoc << @line_break
20
+ adoc
21
+ end
22
+ end
23
+ end
24
+ end
@@ -10,13 +10,13 @@ module Coradoc
10
10
 
11
11
  def initialize(title, options = {})
12
12
  @title = title
13
- @lines = options.fetch(:lines, [])
13
+ @id = options.fetch(:id, nil)
14
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
14
15
  @type_str = options.fetch(:type, nil)
15
- @delimiter = options.fetch(:delimiter, "")
16
16
  @attributes = options.fetch(:attributes, AttributeList.new)
17
+ @delimiter = options.fetch(:delimiter, "")
17
18
  @lang = options.fetch(:lang, nil)
18
- @id = options.fetch(:id, nil)
19
- @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
19
+ @lines = options.fetch(:lines, [])
20
20
  end
21
21
 
22
22
  def type
@@ -37,6 +37,7 @@ module Coradoc
37
37
  def gen_attributes
38
38
  attrs = @attributes.to_adoc(false)
39
39
  return "#{attrs}\n" if !attrs.empty?
40
+
40
41
  ""
41
42
  end
42
43
 
@@ -65,6 +66,7 @@ module Coradoc
65
66
  "----" => :source,
66
67
  "====" => :example,
67
68
  "...." => :literal,
69
+ "++++" => :pass,
68
70
  }
69
71
  end
70
72
  end
@@ -8,6 +8,7 @@ module Coradoc
8
8
  @title = title
9
9
  @id = options.fetch(:id, nil)
10
10
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
11
+ @attributes = options.fetch(:attributes, AttributeList.new)
11
12
  @lines = options.fetch(:lines, [])
12
13
  @delimiter_char = "="
13
14
  @delimiter_len = options.fetch(:delimiter_len, 4)
@@ -0,0 +1,21 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ class Pass < Core
5
+ def initialize(options = {})
6
+ @id = options.fetch(:id, nil)
7
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
+ @title = options.fetch(:title, "")
9
+ @attributes = options.fetch(:attributes, AttributeList.new)
10
+ @delimiter_char = "+"
11
+ @delimiter_len = options.fetch(:delimiter_len, 4)
12
+ @lines = options.fetch(:lines, [])
13
+ end
14
+
15
+ def to_adoc
16
+ "\n\n#{gen_anchor}#{gen_title}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,7 +11,7 @@ module Coradoc
11
11
  end
12
12
 
13
13
  def to_adoc
14
- "\n\n#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
14
+ "\n\n#{gen_title}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,19 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ class ReviewerComment < Core
5
+ def initialize(options = {})
6
+ @title = options.fetch(:title, "")
7
+ @attributes = options.fetch(:attributes, AttributeList.new)
8
+ @delimiter_char = "*"
9
+ @delimiter_len = options.fetch(:delimiter_len, 4)
10
+ @lines = options.fetch(:lines, [])
11
+ end
12
+
13
+ def to_adoc
14
+ "\n\n#{gen_title}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,13 +3,15 @@ module Coradoc
3
3
  module Block
4
4
  class Side < Core
5
5
  def initialize(options = {})
6
- @lines = options.fetch(:lines, [])
6
+ @title = options.fetch(:title, "")
7
+ @attributes = options.fetch(:attributes, AttributeList.new)
7
8
  @delimiter_char = "*"
8
9
  @delimiter_len = options.fetch(:delimiter_len, 4)
10
+ @lines = options.fetch(:lines, [])
9
11
  end
10
12
 
11
13
  def to_adoc
12
- "\n\n#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
14
+ "\n\n#{gen_title}#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
13
15
  end
14
16
  end
15
17
  end
@@ -6,6 +6,7 @@ module Coradoc
6
6
  @id = options.fetch(:id, nil)
7
7
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
8
  @lang = options.fetch(:lang, "")
9
+ @attributes = options.fetch(:attributes, AttributeList.new)
9
10
  @lines = options.fetch(:lines, [])
10
11
  @delimiter_char = "-"
11
12
  @delimiter_len = options.fetch(:delimiter_len, 4)
@@ -9,5 +9,7 @@ require_relative "block/core"
9
9
  require_relative "block/example"
10
10
  require_relative "block/literal"
11
11
  require_relative "block/quote"
12
+ require_relative "block/pass"
12
13
  require_relative "block/side"
13
14
  require_relative "block/sourcecode"
15
+ require_relative "block/reviewer_comment"
@@ -0,0 +1,22 @@
1
+ module Coradoc
2
+ module Element
3
+ module Comment
4
+ class Block < Base
5
+ attr_accessor :text
6
+
7
+ def initialize(text, options = {})
8
+ @text = text
9
+ @line_break = options.fetch(:line_break, "\n")
10
+ end
11
+
12
+ def to_adoc
13
+ <<~ADOC.chomp
14
+ ////
15
+ #{@text}
16
+ ////#{@line_break}
17
+ ADOC
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module Coradoc
2
+ module Element
3
+ module Comment
4
+ class Line < Base
5
+ attr_accessor :text
6
+
7
+ def initialize(text, options = {})
8
+ @text = text
9
+ @line_break = options.fetch(:line_break, "\n")
10
+ end
11
+
12
+ def to_adoc
13
+ "// #{@text}#{@line_break}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -11,10 +11,17 @@ module Coradoc
11
11
  end
12
12
 
13
13
  def to_hash
14
- data.to_h do |attribute|
14
+ @data.to_h do |attribute|
15
15
  [attribute.key.to_s, attribute.value.to_s.gsub("'", "")]
16
16
  end
17
17
  end
18
+
19
+ def to_adoc
20
+ to_hash.map do |key, value|
21
+ v = value.to_s.empty? ? "" : " #{value}"
22
+ ":#{key}:#{v}\n"
23
+ end.join + "\n"
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -12,7 +12,7 @@ module Coradoc
12
12
  end
13
13
 
14
14
  def to_adoc
15
- adoc = "= #{title}\n"
15
+ adoc = "= #{@title}\n"
16
16
  adoc << @author.to_adoc if @author
17
17
  adoc << @revision.to_adoc if @revision
18
18
  adoc
@@ -7,6 +7,14 @@ module Coradoc
7
7
  @colons = "::"
8
8
  end
9
9
 
10
+ def to_adoc
11
+ missing = "// FIXME: Missing image: #{@annotate_missing}\n" if @annotate_missing
12
+ anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
13
+ title = ".#{@title}\n" unless @title.to_s.empty?
14
+ attrs = @attributes.to_adoc
15
+ [missing, anchor, title, "image", @colons, @src, attrs, @line_break].join("")
16
+ end
17
+
10
18
  def validate_named
11
19
  @attributes.validate_named(VALIDATORS_NAMED, VALIDATORS_NAMED_BLOCK)
12
20
  end
@@ -9,23 +9,24 @@ module Coradoc
9
9
  def initialize(title, id, src, options = {})
10
10
  @title = title
11
11
  @id = id
12
- @anchor = @id.nil? ? nil : Coradoc::Element::Inline::Anchor.new(@id)
12
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
13
13
  @src = src
14
14
  @attributes = options.fetch(:attributes, AttributeList.new)
15
- @annotate_missing = options.fetch(:annotate_missing)
16
- @title = options.fetch(:title, nil)
15
+ @annotate_missing = options.fetch(:annotate_missing, nil)
16
+ @title = options.fetch(:title, nil) unless @title
17
17
  if @attributes.any?
18
18
  @attributes.validate_positional(VALIDATORS_POSITIONAL)
19
19
  @attributes.validate_named(VALIDATORS_NAMED)
20
20
  end
21
+ @line_break = options.fetch(:line_break, "")
21
22
  end
22
23
 
23
24
  def to_adoc
24
25
  missing = "// FIXME: Missing image: #{@annotate_missing}\n" if @annotate_missing
25
26
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
26
27
  title = ".#{@title}\n" unless @title.to_s.empty?
27
- attrs = @attributes.to_adoc
28
- [missing, anchor, title, "image", @colons, @src, attrs].join("")
28
+ attrs = @attributes_macro.to_adoc
29
+ [missing, anchor, title, "image", @colons, @src, attrs, @line_break].join("")
29
30
  end
30
31
 
31
32
  extend AttributeList::Matchers
@@ -0,0 +1,18 @@
1
+ module Coradoc
2
+ module Element
3
+ class Include
4
+ attr_accessor :text
5
+
6
+ def initialize(path, options = {})
7
+ @path = path
8
+ @attributes = options.fetch(:attributes, AttributeList.new)
9
+ @line_break = options.fetch(:line_break, "\n")
10
+ end
11
+
12
+ def to_adoc
13
+ attrs = @attributes.to_adoc(true)
14
+ "include::#{@path}#{attrs}#{@line_break}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module Coradoc
2
+ module Element
3
+ module Inline
4
+ class Citation < Base
5
+ attr_accessor :cross_reference, :comment
6
+
7
+ declare_children :cross_reference, :comment
8
+
9
+ def initialize(opts = {})
10
+ @cross_reference = opts.fetch(:cross_reference, nil)
11
+ @comment = opts.fetch(:comment, nil)
12
+ end
13
+
14
+ def to_adoc
15
+ adoc = "[.source]\n"
16
+ adoc << @cross_reference.to_adoc if @cross_reference
17
+ adoc << "\n" if @cross_reference && !@comment
18
+ adoc << Coradoc::Generator.gen_adoc(@comment) if @comment
19
+ adoc
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,21 +2,42 @@ module Coradoc
2
2
  module Element
3
3
  module Inline
4
4
  class CrossReference < Base
5
- attr_accessor :href, :name
5
+ attr_accessor :href, :args
6
6
 
7
- declare_children :href, :name
7
+ declare_children :href, :args
8
8
 
9
- def initialize(href, name = nil)
9
+ def initialize(href, args = nil)
10
10
  @href = href
11
- @name = name
11
+ @args = args
12
+ @args = nil if @args == ""
13
+ @args = [@args] unless @args.is_a?(Array) || @args == nil
12
14
  end
13
15
 
14
16
  def to_adoc
15
- if @name.to_s.empty?
16
- "<<#{@href}>>"
17
- else
18
- "<<#{@href},#{@name}>>"
17
+ if @args
18
+ args = @args.map{|a|
19
+ Coradoc::Generator.gen_adoc(a)}.join(',')
20
+ if args.empty?
21
+ return "<<#{@href}>>"
22
+ else
23
+ return "<<#{@href},#{args}>>"
24
+ end
19
25
  end
26
+ "<<#{@href}>>"
27
+ end
28
+ end
29
+
30
+ class CrossReferenceArg < Base
31
+ attr_accessor :key, :delimiter, :value
32
+
33
+ def initialize(key, delimiter, value)
34
+ @key = key
35
+ @delimiter = delimiter
36
+ @value = value
37
+ end
38
+
39
+ def to_adoc
40
+ [@key,@delimiter,@value].join
20
41
  end
21
42
  end
22
43
  end
@@ -8,6 +8,7 @@ end
8
8
  require_relative "inline/anchor"
9
9
  require_relative "inline/bold"
10
10
  require_relative "inline/cross_reference"
11
+ require_relative "inline/citation"
11
12
  require_relative "inline/hard_line_break"
12
13
  require_relative "inline/highlight"
13
14
  require_relative "inline/italic"
@@ -14,7 +14,15 @@ module Coradoc
14
14
  @items = [@items] unless @items.is_a?(Array)
15
15
  @id = options.fetch(:id, nil)
16
16
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
17
- @ol_count = options.fetch(:ol_count, 1)
17
+ @ol_count = options.fetch(:ol_count, nil)
18
+ if @ol_count.nil?
19
+ m = @items.select do |i|
20
+ i.is_a?(Coradoc::Element::ListItem) &&
21
+ !i.marker.nil?
22
+ end.first&.marker
23
+ @ol_count = m.size if m.is_a?(String)
24
+ end
25
+ @ol_count = 1 if @ol_count.nil?
18
26
  @attrs = options.fetch(:attrs, AttributeList.new)
19
27
  end
20
28
 
@@ -30,7 +38,7 @@ module Coradoc
30
38
  # See: https://github.com/metanorma/coradoc/issues/96
31
39
  unless item.is_a? List::Core
32
40
  content << prefix.to_s
33
- content << " " if c[0]!=" "
41
+ content << " " if c[0] != " "
34
42
  end
35
43
  content << c
36
44
  end