coradoc 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.docker/Dockerfile +1 -1
  3. data/.docker/docker-compose.yml +2 -2
  4. data/.editorconfig +15 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Rakefile +10 -0
  7. data/coradoc.gemspec +11 -2
  8. data/exe/reverse_adoc +70 -0
  9. data/exe/w2a +72 -0
  10. data/lib/coradoc/document.rb +5 -6
  11. data/lib/coradoc/element/admonition.rb +8 -6
  12. data/lib/coradoc/element/attribute_list.rb +2 -2
  13. data/lib/coradoc/element/audio.rb +1 -1
  14. data/lib/coradoc/element/author.rb +16 -14
  15. data/lib/coradoc/element/base.rb +0 -2
  16. data/lib/coradoc/element/block/core.rb +2 -2
  17. data/lib/coradoc/element/block/literal.rb +1 -1
  18. data/lib/coradoc/element/block/sourcecode.rb +2 -2
  19. data/lib/coradoc/element/image/core.rb +1 -0
  20. data/lib/coradoc/element/image.rb +0 -1
  21. data/lib/coradoc/element/inline/bold.rb +1 -0
  22. data/lib/coradoc/element/inline/highlight.rb +1 -0
  23. data/lib/coradoc/element/inline/image.rb +1 -0
  24. data/lib/coradoc/element/inline/italic.rb +1 -0
  25. data/lib/coradoc/element/inline/link.rb +9 -9
  26. data/lib/coradoc/element/inline/monospace.rb +1 -0
  27. data/lib/coradoc/element/inline/quotation.rb +1 -0
  28. data/lib/coradoc/element/inline/subscript.rb +1 -0
  29. data/lib/coradoc/element/inline/superscript.rb +1 -0
  30. data/lib/coradoc/element/inline.rb +0 -1
  31. data/lib/coradoc/element/list/core.rb +3 -4
  32. data/lib/coradoc/element/list.rb +0 -1
  33. data/lib/coradoc/element/list_item.rb +1 -1
  34. data/lib/coradoc/element/paragraph.rb +1 -1
  35. data/lib/coradoc/element/revision.rb +18 -16
  36. data/lib/coradoc/element/table.rb +10 -10
  37. data/lib/coradoc/element/text_element.rb +21 -15
  38. data/lib/coradoc/element/title.rb +2 -2
  39. data/lib/coradoc/element/video.rb +1 -1
  40. data/lib/coradoc/generator.rb +2 -2
  41. data/lib/coradoc/legacy_parser.rb +41 -41
  42. data/lib/coradoc/oscal.rb +2 -4
  43. data/lib/coradoc/parser/asciidoc/content.rb +15 -15
  44. data/lib/coradoc/parser/asciidoc/document_attributes.rb +1 -1
  45. data/lib/coradoc/parser/asciidoc/header.rb +6 -6
  46. data/lib/coradoc/parser/asciidoc/section.rb +1 -1
  47. data/lib/coradoc/reverse_adoc/LICENSE.txt +25 -0
  48. data/lib/coradoc/reverse_adoc/README.adoc +302 -0
  49. data/lib/coradoc/reverse_adoc/cleaner.rb +113 -0
  50. data/lib/coradoc/reverse_adoc/config.rb +54 -0
  51. data/lib/coradoc/reverse_adoc/converters/a.rb +42 -0
  52. data/lib/coradoc/reverse_adoc/converters/aside.rb +16 -0
  53. data/lib/coradoc/reverse_adoc/converters/audio.rb +29 -0
  54. data/lib/coradoc/reverse_adoc/converters/base.rb +100 -0
  55. data/lib/coradoc/reverse_adoc/converters/blockquote.rb +27 -0
  56. data/lib/coradoc/reverse_adoc/converters/br.rb +15 -0
  57. data/lib/coradoc/reverse_adoc/converters/bypass.rb +81 -0
  58. data/lib/coradoc/reverse_adoc/converters/code.rb +56 -0
  59. data/lib/coradoc/reverse_adoc/converters/div.rb +18 -0
  60. data/lib/coradoc/reverse_adoc/converters/drop.rb +22 -0
  61. data/lib/coradoc/reverse_adoc/converters/em.rb +55 -0
  62. data/lib/coradoc/reverse_adoc/converters/figure.rb +25 -0
  63. data/lib/coradoc/reverse_adoc/converters/h.rb +42 -0
  64. data/lib/coradoc/reverse_adoc/converters/head.rb +23 -0
  65. data/lib/coradoc/reverse_adoc/converters/hr.rb +15 -0
  66. data/lib/coradoc/reverse_adoc/converters/ignore.rb +16 -0
  67. data/lib/coradoc/reverse_adoc/converters/img.rb +93 -0
  68. data/lib/coradoc/reverse_adoc/converters/li.rb +17 -0
  69. data/lib/coradoc/reverse_adoc/converters/mark.rb +21 -0
  70. data/lib/coradoc/reverse_adoc/converters/math.rb +31 -0
  71. data/lib/coradoc/reverse_adoc/converters/ol.rb +64 -0
  72. data/lib/coradoc/reverse_adoc/converters/p.rb +23 -0
  73. data/lib/coradoc/reverse_adoc/converters/pass_through.rb +13 -0
  74. data/lib/coradoc/reverse_adoc/converters/pre.rb +55 -0
  75. data/lib/coradoc/reverse_adoc/converters/q.rb +16 -0
  76. data/lib/coradoc/reverse_adoc/converters/strong.rb +52 -0
  77. data/lib/coradoc/reverse_adoc/converters/sub.rb +16 -0
  78. data/lib/coradoc/reverse_adoc/converters/sup.rb +16 -0
  79. data/lib/coradoc/reverse_adoc/converters/table.rb +69 -0
  80. data/lib/coradoc/reverse_adoc/converters/td.rb +83 -0
  81. data/lib/coradoc/reverse_adoc/converters/text.rb +65 -0
  82. data/lib/coradoc/reverse_adoc/converters/th.rb +14 -0
  83. data/lib/coradoc/reverse_adoc/converters/tr.rb +22 -0
  84. data/lib/coradoc/reverse_adoc/converters/video.rb +29 -0
  85. data/lib/coradoc/reverse_adoc/converters.rb +32 -0
  86. data/lib/coradoc/reverse_adoc/errors.rb +10 -0
  87. data/lib/coradoc/reverse_adoc/html_converter.rb +61 -0
  88. data/lib/coradoc/reverse_adoc.rb +27 -0
  89. data/lib/coradoc/transformer.rb +24 -14
  90. data/lib/coradoc/version.rb +1 -1
  91. data/lib/reverse_adoc.rb +20 -0
  92. metadata +178 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09284ec8117d3052ad45275f82328e45e600fabc4f86379093af0dbe4ee9ebc4'
4
- data.tar.gz: 8c9e2cef678a473459b091d05c303110a0caca9179d5ea89e1f4a07608d7bb9c
3
+ metadata.gz: c721a05ddb985a8bde74747c3c39e47818beca7525b13115794673394d46b2ab
4
+ data.tar.gz: f45600c3b4b85877a97904f38a03d5161b0ff83e7259ad6f54da5e1711ac9e46
5
5
  SHA512:
6
- metadata.gz: 35510139cf9cd1cf0eedaaf12b0bc80709628660d88e0178f3651d7f213c870abf68eb04de6f23a8056af4681875f7ba59804228937bc65bfb6550753a4fb769
7
- data.tar.gz: 714c0f79bdd9bb05d58de71c6ab5bcdedddcd48a784fad4b019e168078c221ee6e477c573822a6a8f2db328fa02da5a0b9ef60542f239adb0b109c40ff309a66
6
+ metadata.gz: 0063e9145b1a8e46046c7397b4278a480535ee119624842fad72a8e9280def9de4af7c8335dc5f64b5a118040a8e178af800b27879d8c335a00d37d574b34bbb
7
+ data.tar.gz: 8f02e79025a941ab47c8f359a7638129ce2e7a7aa80352a38bb9004540efdbadff8cd3c0427641004ab834a346f7d39676b9ace64e47f62dcbb9c0b0a357d2ce
data/.docker/Dockerfile CHANGED
@@ -3,7 +3,7 @@ ARG RUBY_IMAGE=ruby:3.1.2-slim
3
3
  FROM ${RUBY_IMAGE}
4
4
 
5
5
  RUN apt-get update \
6
- && apt-get install -y build-essential git \
6
+ && apt-get install -y build-essential git libreoffice \
7
7
  && apt-get clean && rm -rf /var/lib/apt/lists/*
8
8
 
9
9
  # install latest bundler
@@ -7,8 +7,8 @@ services:
7
7
  dockerfile: ./.docker/Dockerfile
8
8
 
9
9
  volumes:
10
- - .:/workspace
11
- - bundle:/bundle
10
+ - .:/workspace:z
11
+ - bundle:/bundle:z
12
12
 
13
13
  volumes:
14
14
  bundle:
data/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ charset = utf-8
9
+ end_of_line = lf
10
+
11
+ [{*.adoc,*.html,*.js,*.json,*.rake,*.rb,*.rf,*.yaml,*.yml,Rakefile,rakefile}]
12
+ indent_style = space
13
+ indent_size = 2
14
+ insert_final_newline = true
15
+ trim_trailing_whitespace = true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2024-05-21
4
+
5
+ - Merge reverse_adoc into coradoc
6
+
3
7
  ## [0.1.0] - 2023-01-08
4
8
 
5
9
  - Initial release
data/Rakefile CHANGED
@@ -1,7 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+
5
+ if File.exist?(".codeclimate")
6
+ ENV["CODECLIMATE_REPO_TOKEN"] = File.read(".codeclimate").strip
7
+ end
8
+
4
9
  require "rspec/core/rake_task"
5
10
 
6
11
  RSpec::Core::RakeTask.new(:spec)
7
12
  task default: :spec
13
+
14
+ desc "Open an irb session preloaded with this library"
15
+ task :console do
16
+ sh "irb -Ilib -rcoradoc -rcoradoc/reverse_adoc"
17
+ end
data/coradoc.gemspec CHANGED
@@ -28,11 +28,20 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
  spec.required_ruby_version = ">= 2.7.0"
30
30
 
31
- spec.add_dependency "parslet"
31
+ spec.add_dependency "marcel", "~> 1.0.0"
32
+ spec.add_dependency "mathml2asciimath"
33
+ spec.add_dependency "nokogiri", "~> 1.13"
32
34
  spec.add_dependency "oscal", "~> 0.1.1"
33
-
35
+ spec.add_dependency "parslet"
36
+ spec.add_dependency "premailer", "~> 1.11.0"
37
+ spec.add_dependency "word-to-markdown"
38
+ spec.add_development_dependency "codeclimate-test-reporter"
34
39
  spec.add_development_dependency "pry"
35
40
  spec.add_development_dependency "rake"
41
+ spec.add_development_dependency "redcarpet"
36
42
  spec.add_development_dependency "rspec"
37
43
  spec.add_development_dependency "rubocop"
44
+ spec.add_development_dependency "rubocop-performance"
45
+ spec.add_development_dependency "simplecov"
46
+ # spec.add_runtime_dependency "thor"
38
47
  end
data/exe/reverse_adoc ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ # Usage: reverse_adoc [FILE]...
3
+ # Usage: cat FILE | reverse_adoc
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ require "coradoc/reverse_adoc"
8
+ require "optparse"
9
+ require "fileutils"
10
+
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: reverse_adoc [options] <file>"
13
+ opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v|
14
+ Coradoc::ReverseAdoc.config.mathml2asciimath = true
15
+ end
16
+
17
+ opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v|
18
+ Coradoc::ReverseAdoc.config.destination = File.expand_path(v)
19
+ # puts "output goes to #{Coradoc::ReverseAdoc.config.destination}"
20
+ end
21
+
22
+ opts.on("-e", "--external-images", "Export images if data URI") do |_v|
23
+ Coradoc::ReverseAdoc.config.external_images = true
24
+ end
25
+
26
+ opts.on("-u", "--unknown_tags [pass_through, drop, bypass, raise]",
27
+ "Unknown tag handling (default: pass_through)") do |v|
28
+ Coradoc::ReverseAdoc.config.unknown_tags = v
29
+ end
30
+
31
+ opts.on("-v", "--version", "Version information") do |_v|
32
+ puts "reverse_adoc: v#{Coradoc::ReverseAdoc::VERSION}"
33
+ exit
34
+ end
35
+
36
+ opts.on("-h", "--help", "Prints this help") do
37
+ puts opts
38
+ exit
39
+ end
40
+ end.parse!
41
+
42
+ if filename = ARGV.pop
43
+ input_content = IO.read(filename)
44
+ Coradoc::ReverseAdoc.config.sourcedir = File.dirname(File.expand_path(filename))
45
+ else
46
+ if Coradoc::ReverseAdoc.config.external_images
47
+ raise "The -e | --external-images feature cannot be used with STDIN input. Exiting."
48
+ end
49
+
50
+ input_content = ARGF.read
51
+ end
52
+
53
+ if Coradoc::ReverseAdoc.config.external_images && Coradoc::ReverseAdoc.config.destination.nil?
54
+ raise "The -e | --external-images feature must be used with -o | --output. Exiting."
55
+ end
56
+
57
+ # Read from STDIN
58
+ adoc_content = Coradoc::ReverseAdoc.convert(input_content)
59
+
60
+ # Print to STDOUT
61
+ unless Coradoc::ReverseAdoc.config.destination
62
+ puts adoc_content
63
+ exit
64
+ end
65
+
66
+ # Write output to Coradoc::ReverseAdoc.config.destination
67
+ FileUtils.mkdir_p(File.dirname(Coradoc::ReverseAdoc.config.destination))
68
+ File.open(Coradoc::ReverseAdoc.config.destination, "w") do |file|
69
+ file.write(adoc_content)
70
+ end
data/exe/w2a ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ require "word-to-markdown"
8
+ require "optparse"
9
+ require "coradoc/reverse_adoc"
10
+
11
+ ARGV.push("-h") if ARGV.empty?
12
+
13
+ OptionParser.new do |opts|
14
+ opts.banner = "Usage: w2a [options] <file>"
15
+ opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v|
16
+ Coradoc::ReverseAdoc.config.mathml2asciimath = true
17
+ end
18
+
19
+ opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v|
20
+ Coradoc::ReverseAdoc.config.destination = File.expand_path(v)
21
+ # puts "output goes to #{Coradoc::ReverseAdoc.config.destination}"
22
+ end
23
+
24
+ opts.on("-e", "--external-images", "Export images if data URI") do |_v|
25
+ Coradoc::ReverseAdoc.config.external_images = true
26
+ end
27
+
28
+ opts.on("-v", "--version", "Version information") do |_v|
29
+ puts "reverse_adoc: v#{Coradoc::ReverseAdoc::VERSION}"
30
+ puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
31
+ if Gem.win_platform?
32
+ puts "[dependency] LibreOffice: version not available on Windows"
33
+ else
34
+ puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
35
+ end
36
+ exit
37
+ end
38
+
39
+ opts.on("-h", "--help", "Prints this help") do
40
+ puts opts
41
+ exit
42
+ end
43
+ end.parse!
44
+
45
+ filename = ARGV.pop
46
+ raise "Please provide an input file to process. Exiting." unless filename
47
+
48
+ if Coradoc::ReverseAdoc.config.external_images && Coradoc::ReverseAdoc.config.destination.nil?
49
+ raise "The -e | --external-images feature must be used with -o | --output. Exiting."
50
+ end
51
+
52
+ Coradoc::ReverseAdoc.config.sourcedir = Dir.mktmpdir
53
+
54
+ doc = WordToMarkdown.new(filename, Coradoc::ReverseAdoc.config.sourcedir)
55
+ # File.open("test.html", "w:UTF-8") { |f| f.write doc.document.html }
56
+ adoc_content = Coradoc::ReverseAdoc.convert(
57
+ Coradoc::ReverseAdoc.cleaner.preprocess_word_html(doc.document.html),
58
+ WordToMarkdown::REVERSE_MARKDOWN_OPTIONS,
59
+ )
60
+ # puts scrub_whitespace(doc.document.html)
61
+
62
+ # Print to STDOUT
63
+ unless Coradoc::ReverseAdoc.config.destination
64
+ puts adoc_content
65
+ exit
66
+ end
67
+
68
+ # Write output to Coradoc::ReverseAdoc.config.destination
69
+ FileUtils.mkdir_p(File.dirname(Coradoc::ReverseAdoc.config.destination))
70
+ File.open(Coradoc::ReverseAdoc.config.destination, "w") do |file|
71
+ file.write(adoc_content)
72
+ end
@@ -20,7 +20,6 @@ require_relative "element/break"
20
20
 
21
21
  module Coradoc
22
22
  class Document
23
-
24
23
  class << self
25
24
  def from_adoc(filename)
26
25
  ast = Coradoc::Parser.parse(filename)
@@ -43,22 +42,22 @@ module Coradoc
43
42
  end
44
43
  end
45
44
 
46
- self.new(
45
+ new(
47
46
  document_attributes: @document_attributes,
48
47
  header: @header,
49
- sections: @sections
48
+ sections: @sections,
50
49
  )
51
50
  end
52
51
  end
53
52
 
54
53
  attr_accessor :header, :document_attributes, :sections
55
54
 
56
- def initialize(options={})
57
- @document_attributes = options.fetch(:document_attributes, Coradoc::Element::DocumentAttributes.new)
55
+ def initialize(options = {})
56
+ @document_attributes = options.fetch(:document_attributes,
57
+ Coradoc::Element::DocumentAttributes.new)
58
58
  @header = options.fetch(:header, Coradoc::Element::Header.new(""))
59
59
  @sections = options.fetch(:sections, [])
60
60
  self
61
61
  end
62
-
63
62
  end
64
63
  end
@@ -1,11 +1,13 @@
1
1
  module Coradoc
2
- class Element::Admonition
3
- attr_reader :type, :content, :line_break
2
+ module Element
3
+ class Admonition
4
+ attr_reader :type, :content, :line_break
4
5
 
5
- def initialize(content, type, options = {})
6
- @content = content
7
- @type = type.downcase.to_sym
8
- @line_break = options.fetch(:line_break, "")
6
+ def initialize(content, type, options = {})
7
+ @content = content
8
+ @type = type.downcase.to_sym
9
+ @line_break = options.fetch(:line_break, "")
10
+ end
9
11
  end
10
12
  end
11
13
  end
@@ -29,12 +29,12 @@ module Coradoc
29
29
  adoc << @named.map do |k, v|
30
30
  if v.is_a?(String)
31
31
  v2 = v.to_s
32
- v2 = v2.include?("\"") ? v2.gsub("\"","\\\"") : v2
32
+ v2 = v2.include?("\"") ? v2.gsub("\"", "\\\"") : v2
33
33
  if v2.include?(" ") || v2.include?(",") || v2.include?("\"")
34
34
  v2 = "\"#{v2}\""
35
35
  end
36
36
  elsif v.is_a?(Array)
37
- v2 = "\"#{v.join(",")}\""
37
+ v2 = "\"#{v.join(',')}\""
38
38
  end
39
39
  [k.to_s, "=", v2].join
40
40
  end.join(",")
@@ -7,7 +7,7 @@ module Coradoc
7
7
  @title = title
8
8
  @id = options.fetch(:id, nil)
9
9
  @anchor = Inline::Anchor.new(@id) if @id
10
- @src = options.fetch(:src, '')
10
+ @src = options.fetch(:src, "")
11
11
  @attributes = options.fetch(:attributes, [])
12
12
  end
13
13
 
@@ -1,20 +1,22 @@
1
1
  module Coradoc
2
- class Element::Author
3
- attr_reader :email, :last_name, :first_name
2
+ module Element
3
+ class Author
4
+ attr_reader :email, :last_name, :first_name
4
5
 
5
- def initialize(first_name, last_name, email, middle_name = nil)
6
- @first_name = first_name
7
- @last_name = last_name
8
- @email = email
9
- @middle_name = middle_name
10
- end
6
+ def initialize(first_name, last_name, email, middle_name = nil)
7
+ @first_name = first_name
8
+ @last_name = last_name
9
+ @email = email
10
+ @middle_name = middle_name
11
+ end
11
12
 
12
- def to_adoc
13
- adoc = "#{@first_name} "
14
- adoc << "#{@middle_name} " if @middle_name
15
- adoc << "#{@last_name}"
16
- adoc << " <#{@email}>" if @email
17
- adoc
13
+ def to_adoc
14
+ adoc = "#{@first_name} "
15
+ adoc << "#{@middle_name} " if @middle_name
16
+ adoc << @last_name.to_s
17
+ adoc << " <#{@email}>" if @email
18
+ adoc
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -7,8 +7,6 @@ module Coradoc
7
7
  # @document_attributes = extract_document_attributes(asciidoc)
8
8
  # end
9
9
 
10
- private
11
-
12
10
  # def extract_document_attributes(asciidoc)
13
11
  # @document_attributes ||= DocumentAttributes.new(asciidoc.attributes)
14
12
  # end
@@ -28,6 +28,7 @@ module Coradoc
28
28
  def gen_title
29
29
  t = Coradoc::Generator.gen_adoc(@title)
30
30
  return "" if t.empty?
31
+
31
32
  ".#{t}\n"
32
33
  end
33
34
 
@@ -59,10 +60,9 @@ module Coradoc
59
60
  "****" => :side,
60
61
  "----" => :source,
61
62
  "====" => :example,
62
- "...." => :literal
63
+ "...." => :literal,
63
64
  }
64
65
  end
65
-
66
66
  end
67
67
  end
68
68
  end
@@ -2,7 +2,7 @@ module Coradoc
2
2
  module Element
3
3
  module Block
4
4
  class Literal < Core
5
- def initialize(title, options = {})
5
+ def initialize(_title, options = {})
6
6
  @id = options.fetch(:id, nil)
7
7
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
8
  @lines = options.fetch(:lines, [])
@@ -2,10 +2,10 @@ module Coradoc
2
2
  module Element
3
3
  module Block
4
4
  class SourceCode < Core
5
- def initialize(title, options = {})
5
+ def initialize(_title, options = {})
6
6
  @id = options.fetch(:id, nil)
7
7
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
- @lang = options.fetch(:lang, '')
8
+ @lang = options.fetch(:lang, "")
9
9
  @lines = options.fetch(:lines, [])
10
10
  @delimiter_char = "-"
11
11
  @delimiter_len = options.fetch(:delimiter_len, 4)
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Image
4
4
  class Core
5
5
  attr_reader :title, :id, :src, :attributes
6
+
6
7
  def initialize(title, id, src, options = ())
7
8
  @title = title
8
9
  @id = id
@@ -1,7 +1,6 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Image
4
-
5
4
  end
6
5
  end
7
6
  end
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Bold
5
5
  attr_accessor :content, :unconstrained
6
+
6
7
  def initialize(content, unconstrained = true)
7
8
  @content = content
8
9
  @unconstrained = unconstrained
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Highlight
5
5
  attr_accessor :content
6
+
6
7
  def initialize(content, constrained = true)
7
8
  @content = content
8
9
  @constrained = constrained
@@ -4,6 +4,7 @@ module Coradoc
4
4
  module Inline
5
5
  class Image
6
6
  attr_reader :title, :id, :src, :attributes
7
+
7
8
  def initialize(title, id, src, options = ())
8
9
  @title = title
9
10
  @id = id
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Italic
5
5
  attr_accessor :content, :unconstrained
6
+
6
7
  def initialize(content, unconstrained = true)
7
8
  @content = content
8
9
  @unconstrained = unconstrained
@@ -5,19 +5,19 @@ module Coradoc
5
5
  attr_reader :path, :title, :name
6
6
 
7
7
  def initialize(options = {})
8
- @path = options.fetch(:path,nil)
8
+ @path = options.fetch(:path, nil)
9
9
  @title = options.fetch(:title, nil)
10
- @name = options.fetch(:name,nil)
10
+ @name = options.fetch(:name, nil)
11
11
  end
12
12
 
13
13
  def to_adoc
14
- link = @path.to_s =~ URI::DEFAULT_PARSER.make_regexp ? @path : "link:#{@path}"
15
- if @name.to_s.empty?
16
- link << "[#{@title}]"
17
- else
18
- link << "[#{@name}]"
19
- end
20
- link.prepend(' ')
14
+ link = @path.to_s&.match?(URI::DEFAULT_PARSER.make_regexp) ? @path : "link:#{@path}"
15
+ link << if @name.to_s.empty?
16
+ "[#{@title}]"
17
+ else
18
+ "[#{@name}]"
19
+ end
20
+ link.prepend(" ")
21
21
  link
22
22
  end
23
23
  end
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Monospace
5
5
  attr_accessor :content, :constrained
6
+
6
7
  def initialize(content, unconstrained = true)
7
8
  @content = content
8
9
  @unconstrained = unconstrained
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Quotation
5
5
  attr_accessor :content
6
+
6
7
  def initialize(content)
7
8
  @content = content
8
9
  end
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Subscript
5
5
  attr_accessor :content
6
+
6
7
  def initialize(content)
7
8
  @content = content
8
9
  end
@@ -3,6 +3,7 @@ module Coradoc
3
3
  module Inline
4
4
  class Superscript
5
5
  attr_accessor :content
6
+
6
7
  def initialize(content)
7
8
  @content = content
8
9
  end
@@ -1,7 +1,6 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module Inline
4
-
5
4
  end
6
5
  end
7
6
  end
@@ -21,15 +21,14 @@ module Coradoc
21
21
  @items.each do |item|
22
22
  c = Coradoc::Generator.gen_adoc(item)
23
23
  if !c.empty?
24
- content << "#{prefix}"
24
+ content << prefix.to_s
25
25
  content << c
26
26
  end
27
27
  end
28
- anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}"
29
- attrs = @attrs.nil? ? "" : "#{@attrs.to_adoc}"
28
+ anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
29
+ attrs = @attrs.nil? ? "" : @attrs.to_adoc.to_s
30
30
  "\n#{anchor}#{attrs}" + content
31
31
  end
32
-
33
32
  end
34
33
  end
35
34
  end
@@ -1,7 +1,6 @@
1
1
  module Coradoc
2
2
  module Element
3
3
  module List
4
-
5
4
  end
6
5
  end
7
6
  end
@@ -10,7 +10,7 @@ module Coradoc
10
10
  end
11
11
 
12
12
  def to_adoc
13
- anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}"
13
+ anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
14
14
  content = Coradoc::Generator.gen_adoc(@content).chomp
15
15
  " #{anchor}#{content.chomp}\n"
16
16
  end
@@ -22,7 +22,7 @@ module Coradoc
22
22
  def to_adoc
23
23
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
24
24
  if @tdsinglepara
25
- "#{anchor}" << Coradoc::Generator.gen_adoc(@content).strip
25
+ anchor.to_s << Coradoc::Generator.gen_adoc(@content).strip
26
26
  else
27
27
  "\n\n#{anchor}" << Coradoc::Generator.gen_adoc(@content).strip << "\n\n"
28
28
  end
@@ -1,22 +1,24 @@
1
1
  module Coradoc
2
- class Element::Revision
3
- attr_reader :number, :date, :remark
2
+ module Element
3
+ class Revision
4
+ attr_reader :number, :date, :remark
4
5
 
5
- def initialize(number, options = {})
6
- @number = number
7
- @date = options.fetch(:date, nil)
8
- @remark = options.fetch(:remark, nil)
9
- end
6
+ def initialize(number, options = {})
7
+ @number = number
8
+ @date = options.fetch(:date, nil)
9
+ @remark = options.fetch(:remark, nil)
10
+ end
10
11
 
11
- def to_adoc
12
- if @date.nil? && @remark.nil?
13
- "v#{@number}\n"
14
- elsif @remark.nil?
15
- "#{@number}, #{@date}\n"
16
- elsif @date.nil?
17
- "#{@number}: #{@remark}\n"
18
- else
19
- "#{@number}, #{@date}: #{@revision}\n"
12
+ def to_adoc
13
+ if @date.nil? && @remark.nil?
14
+ "v#{@number}\n"
15
+ elsif @remark.nil?
16
+ "#{@number}, #{@date}\n"
17
+ elsif @date.nil?
18
+ "#{@number}: #{@remark}\n"
19
+ else
20
+ "#{@number}, #{@date}: #{@revision}\n"
21
+ end
20
22
  end
21
23
  end
22
24
  end