coradoc 0.1.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 (126) 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/.pryrc.sample +1 -0
  6. data/CHANGELOG.md +4 -0
  7. data/Rakefile +10 -0
  8. data/coradoc.gemspec +11 -2
  9. data/exe/reverse_adoc +70 -0
  10. data/exe/w2a +72 -0
  11. data/lib/coradoc/document.rb +40 -23
  12. data/lib/coradoc/element/admonition.rb +13 -0
  13. data/lib/coradoc/{document → element}/attribute.rb +1 -1
  14. data/lib/coradoc/element/attribute_list.rb +46 -0
  15. data/lib/coradoc/element/audio.rb +22 -0
  16. data/lib/coradoc/element/author.rb +22 -0
  17. data/lib/coradoc/element/base.rb +15 -0
  18. data/lib/coradoc/element/block/core.rb +69 -0
  19. data/lib/coradoc/element/block/example.rb +22 -0
  20. data/lib/coradoc/element/block/literal.rb +19 -0
  21. data/lib/coradoc/element/block/quote.rb +19 -0
  22. data/lib/coradoc/element/block/side.rb +17 -0
  23. data/lib/coradoc/element/block/sourcecode.rb +20 -0
  24. data/lib/coradoc/element/block.rb +13 -0
  25. data/lib/coradoc/element/break.rb +11 -0
  26. data/lib/coradoc/{document/bibdata.rb → element/document_attributes.rb} +4 -8
  27. data/lib/coradoc/element/header.rb +20 -0
  28. data/lib/coradoc/element/image/block_image.rb +12 -0
  29. data/lib/coradoc/element/image/core.rb +25 -0
  30. data/lib/coradoc/element/image/inline_image.rb +12 -0
  31. data/lib/coradoc/element/image.rb +10 -0
  32. data/lib/coradoc/element/inline/anchor.rb +17 -0
  33. data/lib/coradoc/element/inline/bold.rb +20 -0
  34. data/lib/coradoc/element/inline/cross_reference.rb +22 -0
  35. data/lib/coradoc/element/inline/hard_line_break.rb +11 -0
  36. data/lib/coradoc/element/inline/highlight.rb +20 -0
  37. data/lib/coradoc/element/inline/image.rb +26 -0
  38. data/lib/coradoc/element/inline/italic.rb +20 -0
  39. data/lib/coradoc/element/inline/link.rb +26 -0
  40. data/lib/coradoc/element/inline/monospace.rb +20 -0
  41. data/lib/coradoc/element/inline/quotation.rb +18 -0
  42. data/lib/coradoc/element/inline/subscript.rb +18 -0
  43. data/lib/coradoc/element/inline/superscript.rb +18 -0
  44. data/lib/coradoc/element/inline.rb +18 -0
  45. data/lib/coradoc/element/list/core.rb +35 -0
  46. data/lib/coradoc/element/list/definition.rb +8 -0
  47. data/lib/coradoc/element/list/ordered.rb +15 -0
  48. data/lib/coradoc/element/list/unordered.rb +15 -0
  49. data/lib/coradoc/element/list.rb +12 -0
  50. data/lib/coradoc/element/list_item.rb +19 -0
  51. data/lib/coradoc/element/paragraph.rb +32 -0
  52. data/lib/coradoc/element/revision.rb +25 -0
  53. data/lib/coradoc/element/section.rb +37 -0
  54. data/lib/coradoc/element/table.rb +67 -0
  55. data/lib/coradoc/element/text_element.rb +32 -0
  56. data/lib/coradoc/{document → element}/title.rb +14 -5
  57. data/lib/coradoc/element/video.rb +23 -0
  58. data/lib/coradoc/generator.rb +17 -0
  59. data/lib/coradoc/legacy_parser.rb +48 -48
  60. data/lib/coradoc/oscal.rb +6 -5
  61. data/lib/coradoc/parser/asciidoc/base.rb +17 -17
  62. data/lib/coradoc/parser/asciidoc/content.rb +55 -29
  63. data/lib/coradoc/parser/asciidoc/document_attributes.rb +19 -0
  64. data/lib/coradoc/parser/asciidoc/header.rb +13 -10
  65. data/lib/coradoc/parser/asciidoc/section.rb +6 -6
  66. data/lib/coradoc/parser/base.rb +5 -5
  67. data/lib/coradoc/parser.rb +1 -1
  68. data/lib/coradoc/reverse_adoc/LICENSE.txt +25 -0
  69. data/lib/coradoc/reverse_adoc/README.adoc +302 -0
  70. data/lib/coradoc/reverse_adoc/cleaner.rb +113 -0
  71. data/lib/coradoc/reverse_adoc/config.rb +54 -0
  72. data/lib/coradoc/reverse_adoc/converters/a.rb +42 -0
  73. data/lib/coradoc/reverse_adoc/converters/aside.rb +16 -0
  74. data/lib/coradoc/reverse_adoc/converters/audio.rb +29 -0
  75. data/lib/coradoc/reverse_adoc/converters/base.rb +100 -0
  76. data/lib/coradoc/reverse_adoc/converters/blockquote.rb +27 -0
  77. data/lib/coradoc/reverse_adoc/converters/br.rb +15 -0
  78. data/lib/coradoc/reverse_adoc/converters/bypass.rb +81 -0
  79. data/lib/coradoc/reverse_adoc/converters/code.rb +56 -0
  80. data/lib/coradoc/reverse_adoc/converters/div.rb +18 -0
  81. data/lib/coradoc/reverse_adoc/converters/drop.rb +22 -0
  82. data/lib/coradoc/reverse_adoc/converters/em.rb +55 -0
  83. data/lib/coradoc/reverse_adoc/converters/figure.rb +25 -0
  84. data/lib/coradoc/reverse_adoc/converters/h.rb +42 -0
  85. data/lib/coradoc/reverse_adoc/converters/head.rb +23 -0
  86. data/lib/coradoc/reverse_adoc/converters/hr.rb +15 -0
  87. data/lib/coradoc/reverse_adoc/converters/ignore.rb +16 -0
  88. data/lib/coradoc/reverse_adoc/converters/img.rb +93 -0
  89. data/lib/coradoc/reverse_adoc/converters/li.rb +17 -0
  90. data/lib/coradoc/reverse_adoc/converters/mark.rb +21 -0
  91. data/lib/coradoc/reverse_adoc/converters/math.rb +31 -0
  92. data/lib/coradoc/reverse_adoc/converters/ol.rb +64 -0
  93. data/lib/coradoc/reverse_adoc/converters/p.rb +23 -0
  94. data/lib/coradoc/reverse_adoc/converters/pass_through.rb +13 -0
  95. data/lib/coradoc/reverse_adoc/converters/pre.rb +55 -0
  96. data/lib/coradoc/reverse_adoc/converters/q.rb +16 -0
  97. data/lib/coradoc/reverse_adoc/converters/strong.rb +52 -0
  98. data/lib/coradoc/reverse_adoc/converters/sub.rb +16 -0
  99. data/lib/coradoc/reverse_adoc/converters/sup.rb +16 -0
  100. data/lib/coradoc/reverse_adoc/converters/table.rb +69 -0
  101. data/lib/coradoc/reverse_adoc/converters/td.rb +83 -0
  102. data/lib/coradoc/reverse_adoc/converters/text.rb +65 -0
  103. data/lib/coradoc/reverse_adoc/converters/th.rb +14 -0
  104. data/lib/coradoc/reverse_adoc/converters/tr.rb +22 -0
  105. data/lib/coradoc/reverse_adoc/converters/video.rb +29 -0
  106. data/lib/coradoc/reverse_adoc/converters.rb +32 -0
  107. data/lib/coradoc/reverse_adoc/errors.rb +10 -0
  108. data/lib/coradoc/reverse_adoc/html_converter.rb +61 -0
  109. data/lib/coradoc/reverse_adoc.rb +27 -0
  110. data/lib/coradoc/transformer.rb +59 -46
  111. data/lib/coradoc/version.rb +1 -1
  112. data/lib/coradoc.rb +6 -4
  113. data/lib/reverse_adoc.rb +20 -0
  114. metadata +231 -23
  115. data/lib/coradoc/document/admonition.rb +0 -11
  116. data/lib/coradoc/document/author.rb +0 -11
  117. data/lib/coradoc/document/base.rb +0 -17
  118. data/lib/coradoc/document/block.rb +0 -34
  119. data/lib/coradoc/document/header.rb +0 -11
  120. data/lib/coradoc/document/list.rb +0 -14
  121. data/lib/coradoc/document/paragraph.rb +0 -19
  122. data/lib/coradoc/document/revision.rb +0 -11
  123. data/lib/coradoc/document/section.rb +0 -28
  124. data/lib/coradoc/document/table.rb +0 -20
  125. data/lib/coradoc/document/text_element.rb +0 -22
  126. data/lib/coradoc/parser/asciidoc/bibdata.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1808574d50d22e93126d258859b0a7156015dae5e1830332b70a705643c3ab50
4
- data.tar.gz: e1593143645bd24b419ad84f5961335de1351599fc9e9363d40c49ddb5a1d1b9
3
+ metadata.gz: c721a05ddb985a8bde74747c3c39e47818beca7525b13115794673394d46b2ab
4
+ data.tar.gz: f45600c3b4b85877a97904f38a03d5161b0ff83e7259ad6f54da5e1711ac9e46
5
5
  SHA512:
6
- metadata.gz: a40e182cf07edd62e2af114fdbc752e759aef7b44a693cab17a6fba93869f999a5b2532f25e80146f30ed19b997414061b333836e4165045826e5c3853474403
7
- data.tar.gz: 51c085c1a3437ea76897568b318a10ed7cc42f3998448903c0337500455fc4712ca869cc50ce1355bcb707461fef16c825f8c5a206fd86050f8b0295e82d198c
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/.pryrc.sample ADDED
@@ -0,0 +1 @@
1
+ doc = Coradoc::Parser.parse("spec/fixtures/sample.adoc")
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
@@ -1,22 +1,26 @@
1
- require "coradoc/document/title"
2
- require "coradoc/document/block"
3
- require "coradoc/document/section"
4
- require "coradoc/document/attribute"
5
- require "coradoc/document/admonition"
6
- require "coradoc/document/text_element"
7
- require "coradoc/document/author"
8
- require "coradoc/document/revision"
9
- require "coradoc/document/header"
10
- require "coradoc/document/bibdata"
11
- require "coradoc/document/paragraph"
12
- require "coradoc/document/table"
13
- require "coradoc/document/list"
1
+ require_relative "element/title"
2
+ require_relative "element/block"
3
+ require_relative "element/section"
4
+ require_relative "element/attribute"
5
+ require_relative "element/attribute_list"
6
+ require_relative "element/admonition"
7
+ require_relative "element/text_element"
8
+ require_relative "element/author"
9
+ require_relative "element/revision"
10
+ require_relative "element/header"
11
+ require_relative "element/document_attributes"
12
+ require_relative "element/paragraph"
13
+ require_relative "element/table"
14
+ require_relative "element/list"
15
+ require_relative "element/inline"
16
+ require_relative "element/image"
17
+ require_relative "element/audio"
18
+ require_relative "element/video"
19
+ require_relative "element/break"
14
20
 
15
21
  module Coradoc
16
- module Document
22
+ class Document
17
23
  class << self
18
- attr_reader :header, :bibdata, :sections
19
-
20
24
  def from_adoc(filename)
21
25
  ast = Coradoc::Parser.parse(filename)
22
26
  Coradoc::Transformer.transform(ast)
@@ -26,21 +30,34 @@ module Coradoc
26
30
  @sections = []
27
31
 
28
32
  elements.each do |element|
29
- if element.is_a?(Coradoc::Document::Bibdata)
30
- @bibdata = element
31
- end
33
+ case element
34
+ when Coradoc::Element::DocumentAttributes
35
+ @document_attributes = element
32
36
 
33
- if element.is_a?(Coradoc::Document::Header)
37
+ when Coradoc::Element::Header
34
38
  @header = element
35
- end
36
39
 
37
- if element.is_a?(Coradoc::Document::Section)
40
+ when Coradoc::Element::Section
38
41
  @sections << element
39
42
  end
40
43
  end
41
44
 
42
- self
45
+ new(
46
+ document_attributes: @document_attributes,
47
+ header: @header,
48
+ sections: @sections,
49
+ )
43
50
  end
44
51
  end
52
+
53
+ attr_accessor :header, :document_attributes, :sections
54
+
55
+ def initialize(options = {})
56
+ @document_attributes = options.fetch(:document_attributes,
57
+ Coradoc::Element::DocumentAttributes.new)
58
+ @header = options.fetch(:header, Coradoc::Element::Header.new(""))
59
+ @sections = options.fetch(:sections, [])
60
+ self
61
+ end
45
62
  end
46
63
  end
@@ -0,0 +1,13 @@
1
+ module Coradoc
2
+ module Element
3
+ class Admonition
4
+ attr_reader :type, :content, :line_break
5
+
6
+ def initialize(content, type, options = {})
7
+ @content = content
8
+ @type = type.downcase.to_sym
9
+ @line_break = options.fetch(:line_break, "")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Coradoc
2
- module Document
2
+ module Element
3
3
  class Attribute
4
4
  attr_reader :key, :value
5
5
 
@@ -0,0 +1,46 @@
1
+ module Coradoc
2
+ module Element
3
+ class AttributeList
4
+ attr_reader :positional, :named
5
+
6
+ def initialize(*positional, **named)
7
+ @positional = positional || []
8
+ @named = named || {}
9
+ end
10
+
11
+ def add_positional(attr)
12
+ @positional << attr
13
+ end
14
+
15
+ def add_named(name, value)
16
+ @named[name] = value
17
+ end
18
+
19
+ def empty?
20
+ @positional.empty? && @named.empty?
21
+ end
22
+
23
+ def to_adoc
24
+ return "[]" if [@positional, @named].all?(:empty?)
25
+
26
+ adoc = ""
27
+ adoc << @positional.join(",") if @positional.any?
28
+ adoc << "," if @positional.any? && @named.any?
29
+ adoc << @named.map do |k, v|
30
+ if v.is_a?(String)
31
+ v2 = v.to_s
32
+ v2 = v2.include?("\"") ? v2.gsub("\"", "\\\"") : v2
33
+ if v2.include?(" ") || v2.include?(",") || v2.include?("\"")
34
+ v2 = "\"#{v2}\""
35
+ end
36
+ elsif v.is_a?(Array)
37
+ v2 = "\"#{v.join(',')}\""
38
+ end
39
+ [k.to_s, "=", v2].join
40
+ end.join(",")
41
+ adoc = "[#{adoc}]" if @positional.any? || @named.any?
42
+ adoc
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module Coradoc
2
+ module Element
3
+ class Audio
4
+ attr_reader :id, :title, :src, :options, :anchor
5
+
6
+ def initialize(title, options = {})
7
+ @title = title
8
+ @id = options.fetch(:id, nil)
9
+ @anchor = Inline::Anchor.new(@id) if @id
10
+ @src = options.fetch(:src, "")
11
+ @attributes = options.fetch(:attributes, [])
12
+ end
13
+
14
+ def to_adoc
15
+ anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
16
+ title = ".#{@title}\n" unless @title.empty?
17
+ attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
18
+ [anchor, title, "audio::", @src, attrs].join("")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Coradoc
2
+ module Element
3
+ class Author
4
+ attr_reader :email, :last_name, :first_name
5
+
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
12
+
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
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Coradoc
2
+ module Element
3
+ class Base
4
+ # attr_reader :document_attributes
5
+
6
+ # def initialize(asciidoc)
7
+ # @document_attributes = extract_document_attributes(asciidoc)
8
+ # end
9
+
10
+ # def extract_document_attributes(asciidoc)
11
+ # @document_attributes ||= DocumentAttributes.new(asciidoc.attributes)
12
+ # end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,69 @@
1
+ require_relative "../inline/anchor"
2
+
3
+ module Coradoc
4
+ module Element
5
+ module Block
6
+ class Core
7
+ attr_reader :title, :lines, :attributes, :lang, :id
8
+
9
+ def initialize(title, options = {})
10
+ @title = title
11
+ @lines = options.fetch(:lines, [])
12
+ @type_str = options.fetch(:type, nil)
13
+ @delimiter = options.fetch(:delimiter, "")
14
+ @attributes = options.fetch(:attributes, {})
15
+ @lang = options.fetch(:lang, nil)
16
+ @id = options.fetch(:id, nil)
17
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
18
+ end
19
+
20
+ def type
21
+ @type ||= defined_type || type_from_delimiter
22
+ end
23
+
24
+ def gen_anchor
25
+ @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
26
+ end
27
+
28
+ def gen_title
29
+ t = Coradoc::Generator.gen_adoc(@title)
30
+ return "" if t.empty?
31
+
32
+ ".#{t}\n"
33
+ end
34
+
35
+ def gen_attributes
36
+ @attributes.nil? ? "" : "#{@attributes.to_adoc}\n"
37
+ end
38
+
39
+ def gen_delimiter
40
+ @delimiter_char * @delimiter_len
41
+ end
42
+
43
+ def gen_lines
44
+ Coradoc::Generator.gen_adoc(@lines)
45
+ end
46
+
47
+ private
48
+
49
+ def defined_type
50
+ @type_str&.to_s&.to_sym
51
+ end
52
+
53
+ def type_from_delimiter
54
+ type_hash.fetch(@delimiter, nil)
55
+ end
56
+
57
+ def type_hash
58
+ @type_hash ||= {
59
+ "____" => :quote,
60
+ "****" => :side,
61
+ "----" => :source,
62
+ "====" => :example,
63
+ "...." => :literal,
64
+ }
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "core"
2
+
3
+ module Coradoc
4
+ module Element
5
+ module Block
6
+ class Example < Core
7
+ def initialize(title, options = {})
8
+ @title = title
9
+ @id = options.fetch(:id, nil)
10
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
11
+ @lines = options.fetch(:lines, [])
12
+ @delimiter_char = "="
13
+ @delimiter_len = options.fetch(:delimiter_len, 4)
14
+ end
15
+
16
+ def to_adoc
17
+ "\n\n#{gen_anchor}#{gen_title}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ class Literal < Core
5
+ def initialize(_title, options = {})
6
+ @id = options.fetch(:id, nil)
7
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
+ @lines = options.fetch(:lines, [])
9
+ @delimiter_char = "."
10
+ @delimiter_len = options.fetch(:delimiter_len, 4)
11
+ end
12
+
13
+ def to_adoc
14
+ "\n\n#{gen_anchor}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ class Quote < Core
5
+ def initialize(title, options = {})
6
+ @title = title
7
+ @attributes = options.fetch(:attributes, {})
8
+ @lines = options.fetch(:lines, [])
9
+ @delimiter_char = "_"
10
+ @delimiter_len = options.fetch(:delimiter_len, 4)
11
+ end
12
+
13
+ def to_adoc
14
+ "\n\n#{gen_attributes}#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ class Side < Core
5
+ def initialize(options = {})
6
+ @lines = options.fetch(:lines, [])
7
+ @delimiter_char = "*"
8
+ @delimiter_len = options.fetch(:delimiter_len, 4)
9
+ end
10
+
11
+ def to_adoc
12
+ "\n\n#{gen_delimiter}" << gen_lines << "\n#{gen_delimiter}\n\n"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ class SourceCode < Core
5
+ def initialize(_title, options = {})
6
+ @id = options.fetch(:id, nil)
7
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
8
+ @lang = options.fetch(:lang, "")
9
+ @lines = options.fetch(:lines, [])
10
+ @delimiter_char = "-"
11
+ @delimiter_len = options.fetch(:delimiter_len, 4)
12
+ end
13
+
14
+ def to_adoc
15
+ "\n\n#{gen_anchor}[source,#{@lang}]\n#{gen_delimiter}\n" << gen_lines << "\n#{gen_delimiter}\n\n"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Coradoc
2
+ module Element
3
+ module Block
4
+ end
5
+ end
6
+ end
7
+
8
+ require_relative "block/core"
9
+ require_relative "block/example"
10
+ require_relative "block/literal"
11
+ require_relative "block/quote"
12
+ require_relative "block/side"
13
+ require_relative "block/sourcecode"
@@ -0,0 +1,11 @@
1
+ module Coradoc
2
+ module Element
3
+ module Break
4
+ class ThematicBreak
5
+ def to_adoc
6
+ "\n* * *\n"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end