coradoc 0.1.0 → 0.2.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/.pryrc.sample +1 -0
  3. data/lib/coradoc/document.rb +41 -23
  4. data/lib/coradoc/{document → element}/admonition.rb +1 -1
  5. data/lib/coradoc/{document → element}/attribute.rb +1 -1
  6. data/lib/coradoc/element/attribute_list.rb +46 -0
  7. data/lib/coradoc/element/audio.rb +22 -0
  8. data/lib/coradoc/element/author.rb +20 -0
  9. data/lib/coradoc/element/base.rb +17 -0
  10. data/lib/coradoc/element/block/core.rb +69 -0
  11. data/lib/coradoc/element/block/example.rb +22 -0
  12. data/lib/coradoc/element/block/literal.rb +19 -0
  13. data/lib/coradoc/element/block/quote.rb +19 -0
  14. data/lib/coradoc/element/block/side.rb +17 -0
  15. data/lib/coradoc/element/block/sourcecode.rb +20 -0
  16. data/lib/coradoc/element/block.rb +13 -0
  17. data/lib/coradoc/element/break.rb +11 -0
  18. data/lib/coradoc/{document/bibdata.rb → element/document_attributes.rb} +4 -8
  19. data/lib/coradoc/element/header.rb +20 -0
  20. data/lib/coradoc/element/image/block_image.rb +12 -0
  21. data/lib/coradoc/element/image/core.rb +24 -0
  22. data/lib/coradoc/element/image/inline_image.rb +12 -0
  23. data/lib/coradoc/element/image.rb +11 -0
  24. data/lib/coradoc/element/inline/anchor.rb +17 -0
  25. data/lib/coradoc/element/inline/bold.rb +19 -0
  26. data/lib/coradoc/element/inline/cross_reference.rb +22 -0
  27. data/lib/coradoc/element/inline/hard_line_break.rb +11 -0
  28. data/lib/coradoc/element/inline/highlight.rb +19 -0
  29. data/lib/coradoc/element/inline/image.rb +25 -0
  30. data/lib/coradoc/element/inline/italic.rb +19 -0
  31. data/lib/coradoc/element/inline/link.rb +26 -0
  32. data/lib/coradoc/element/inline/monospace.rb +19 -0
  33. data/lib/coradoc/element/inline/quotation.rb +17 -0
  34. data/lib/coradoc/element/inline/subscript.rb +17 -0
  35. data/lib/coradoc/element/inline/superscript.rb +17 -0
  36. data/lib/coradoc/element/inline.rb +19 -0
  37. data/lib/coradoc/element/list/core.rb +36 -0
  38. data/lib/coradoc/element/list/definition.rb +8 -0
  39. data/lib/coradoc/element/list/ordered.rb +15 -0
  40. data/lib/coradoc/element/list/unordered.rb +15 -0
  41. data/lib/coradoc/element/list.rb +13 -0
  42. data/lib/coradoc/element/list_item.rb +19 -0
  43. data/lib/coradoc/element/paragraph.rb +32 -0
  44. data/lib/coradoc/element/revision.rb +23 -0
  45. data/lib/coradoc/element/section.rb +37 -0
  46. data/lib/coradoc/element/table.rb +67 -0
  47. data/lib/coradoc/{document → element}/text_element.rb +8 -4
  48. data/lib/coradoc/element/title.rb +42 -0
  49. data/lib/coradoc/element/video.rb +23 -0
  50. data/lib/coradoc/generator.rb +17 -0
  51. data/lib/coradoc/legacy_parser.rb +8 -8
  52. data/lib/coradoc/oscal.rb +5 -2
  53. data/lib/coradoc/parser/asciidoc/base.rb +17 -17
  54. data/lib/coradoc/parser/asciidoc/content.rb +46 -20
  55. data/lib/coradoc/parser/asciidoc/{bibdata.rb → document_attributes.rb} +5 -5
  56. data/lib/coradoc/parser/asciidoc/header.rb +13 -10
  57. data/lib/coradoc/parser/asciidoc/section.rb +5 -5
  58. data/lib/coradoc/parser/base.rb +5 -5
  59. data/lib/coradoc/parser.rb +1 -1
  60. data/lib/coradoc/transformer.rb +39 -36
  61. data/lib/coradoc/version.rb +1 -1
  62. data/lib/coradoc.rb +6 -4
  63. metadata +55 -21
  64. data/lib/coradoc/document/author.rb +0 -11
  65. data/lib/coradoc/document/base.rb +0 -17
  66. data/lib/coradoc/document/block.rb +0 -34
  67. data/lib/coradoc/document/header.rb +0 -11
  68. data/lib/coradoc/document/list.rb +0 -14
  69. data/lib/coradoc/document/paragraph.rb +0 -19
  70. data/lib/coradoc/document/revision.rb +0 -11
  71. data/lib/coradoc/document/section.rb +0 -28
  72. data/lib/coradoc/document/table.rb +0 -20
  73. data/lib/coradoc/document/title.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1808574d50d22e93126d258859b0a7156015dae5e1830332b70a705643c3ab50
4
- data.tar.gz: e1593143645bd24b419ad84f5961335de1351599fc9e9363d40c49ddb5a1d1b9
3
+ metadata.gz: '09284ec8117d3052ad45275f82328e45e600fabc4f86379093af0dbe4ee9ebc4'
4
+ data.tar.gz: 8c9e2cef678a473459b091d05c303110a0caca9179d5ea89e1f4a07608d7bb9c
5
5
  SHA512:
6
- metadata.gz: a40e182cf07edd62e2af114fdbc752e759aef7b44a693cab17a6fba93869f999a5b2532f25e80146f30ed19b997414061b333836e4165045826e5c3853474403
7
- data.tar.gz: 51c085c1a3437ea76897568b318a10ed7cc42f3998448903c0337500455fc4712ca869cc50ce1355bcb707461fef16c825f8c5a206fd86050f8b0295e82d198c
6
+ metadata.gz: 35510139cf9cd1cf0eedaaf12b0bc80709628660d88e0178f3651d7f213c870abf68eb04de6f23a8056af4681875f7ba59804228937bc65bfb6550753a4fb769
7
+ data.tar.gz: 714c0f79bdd9bb05d58de71c6ab5bcdedddcd48a784fad4b019e168078c221ee6e477c573822a6a8f2db328fa02da5a0b9ef60542f239adb0b109c40ff309a66
data/.pryrc.sample ADDED
@@ -0,0 +1 @@
1
+ doc = Coradoc::Parser.parse("spec/fixtures/sample.adoc")
@@ -1,22 +1,27 @@
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
17
- class << self
18
- attr_reader :header, :bibdata, :sections
22
+ class Document
19
23
 
24
+ class << self
20
25
  def from_adoc(filename)
21
26
  ast = Coradoc::Parser.parse(filename)
22
27
  Coradoc::Transformer.transform(ast)
@@ -26,21 +31,34 @@ module Coradoc
26
31
  @sections = []
27
32
 
28
33
  elements.each do |element|
29
- if element.is_a?(Coradoc::Document::Bibdata)
30
- @bibdata = element
31
- end
34
+ case element
35
+ when Coradoc::Element::DocumentAttributes
36
+ @document_attributes = element
32
37
 
33
- if element.is_a?(Coradoc::Document::Header)
38
+ when Coradoc::Element::Header
34
39
  @header = element
35
- end
36
40
 
37
- if element.is_a?(Coradoc::Document::Section)
41
+ when Coradoc::Element::Section
38
42
  @sections << element
39
43
  end
40
44
  end
41
45
 
42
- self
46
+ self.new(
47
+ document_attributes: @document_attributes,
48
+ header: @header,
49
+ sections: @sections
50
+ )
43
51
  end
44
52
  end
53
+
54
+ attr_accessor :header, :document_attributes, :sections
55
+
56
+ def initialize(options={})
57
+ @document_attributes = options.fetch(:document_attributes, Coradoc::Element::DocumentAttributes.new)
58
+ @header = options.fetch(:header, Coradoc::Element::Header.new(""))
59
+ @sections = options.fetch(:sections, [])
60
+ self
61
+ end
62
+
45
63
  end
46
64
  end
@@ -1,5 +1,5 @@
1
1
  module Coradoc
2
- class Document::Admonition
2
+ class Element::Admonition
3
3
  attr_reader :type, :content, :line_break
4
4
 
5
5
  def initialize(content, type, options = {})
@@ -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,20 @@
1
+ module Coradoc
2
+ class Element::Author
3
+ attr_reader :email, :last_name, :first_name
4
+
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
11
+
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
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
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
+ private
11
+
12
+ # def extract_document_attributes(asciidoc)
13
+ # @document_attributes ||= DocumentAttributes.new(asciidoc.attributes)
14
+ # end
15
+ end
16
+ end
17
+ 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
+ ".#{t}\n"
32
+ end
33
+
34
+ def gen_attributes
35
+ @attributes.nil? ? "" : "#{@attributes.to_adoc}\n"
36
+ end
37
+
38
+ def gen_delimiter
39
+ @delimiter_char * @delimiter_len
40
+ end
41
+
42
+ def gen_lines
43
+ Coradoc::Generator.gen_adoc(@lines)
44
+ end
45
+
46
+ private
47
+
48
+ def defined_type
49
+ @type_str&.to_s&.to_sym
50
+ end
51
+
52
+ def type_from_delimiter
53
+ type_hash.fetch(@delimiter, nil)
54
+ end
55
+
56
+ def type_hash
57
+ @type_hash ||= {
58
+ "____" => :quote,
59
+ "****" => :side,
60
+ "----" => :source,
61
+ "====" => :example,
62
+ "...." => :literal
63
+ }
64
+ end
65
+
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
@@ -1,17 +1,13 @@
1
1
  module Coradoc
2
- module Document
3
- class Bibdata
2
+ module Element
3
+ class DocumentAttributes
4
4
  attr_reader :data
5
5
 
6
- def initialize(bibdata, options = {})
7
- @bibdata = bibdata
6
+ def initialize(data = {}, options = {})
7
+ @data = data
8
8
  @options = options
9
9
  end
10
10
 
11
- def data
12
- @data ||= @bibdata
13
- end
14
-
15
11
  def to_hash
16
12
  Hash.new.tap do |hash|
17
13
  data.each do |attribute|
@@ -0,0 +1,20 @@
1
+ module Coradoc
2
+ module Element
3
+ class Header
4
+ attr_reader :title, :author, :revision
5
+
6
+ def initialize(title, options = {})
7
+ @title = title
8
+ @author = options.fetch(:author, nil)
9
+ @revision = options.fetch(:revision, nil)
10
+ end
11
+
12
+ def to_adoc
13
+ adoc = "= #{title}\n"
14
+ adoc << @author.to_adoc if @author
15
+ adoc << @revision.to_adoc if @revision
16
+ adoc
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Coradoc
2
+ module Element
3
+ module Image
4
+ class BlockImage < Core
5
+ def initialize(title, id, src, options = ())
6
+ super(title, id, src, options)
7
+ @colons = "::"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module Coradoc
2
+ module Element
3
+ module Image
4
+ class Core
5
+ attr_reader :title, :id, :src, :attributes
6
+ def initialize(title, id, src, options = ())
7
+ @title = title
8
+ @id = id
9
+ @anchor = @id.nil? ? nil : Coradoc::Element::Inline::Anchor.new(@id)
10
+ @src = src
11
+ @attributes = options.fetch(:attributes, [])
12
+ @title = options.fetch(:title, nil)
13
+ end
14
+
15
+ def to_adoc
16
+ anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
17
+ title = ".#{@title}\n" unless @title.to_s.empty?
18
+ attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
19
+ [anchor, title, "image", @colons, @src, attrs].join("")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module Coradoc
2
+ module Element
3
+ module Image
4
+ class InlineImage < Core
5
+ def initialize(title, id, src, options = ())
6
+ super(title, id, src, options)
7
+ @colons = ":"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Coradoc
2
+ module Element
3
+ module Image
4
+
5
+ end
6
+ end
7
+ end
8
+
9
+ require_relative "image/core"
10
+ require_relative "image/inline_image"
11
+ require_relative "image/block_image"
@@ -0,0 +1,17 @@
1
+ module Coradoc
2
+ module Element
3
+ module Inline
4
+ class Anchor
5
+ attr_reader :id
6
+
7
+ def initialize(id)
8
+ @id = id
9
+ end
10
+
11
+ def to_adoc
12
+ "[[#{@id}]]"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Coradoc
2
+ module Element
3
+ module Inline
4
+ class Bold
5
+ attr_accessor :content, :unconstrained
6
+ def initialize(content, unconstrained = true)
7
+ @content = content
8
+ @unconstrained = unconstrained
9
+ end
10
+
11
+ def to_adoc
12
+ content = Coradoc::Generator.gen_adoc(@content)
13
+ doubled = @unconstrained ? "*" : ""
14
+ "#{doubled}*#{content.strip}*#{doubled}#{content[/\s+$/]}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Coradoc
2
+ module Element
3
+ module Inline
4
+ class CrossReference
5
+ attr_reader :href, :name
6
+
7
+ def initialize(href, name = nil)
8
+ @href = href
9
+ @name = name
10
+ end
11
+
12
+ def to_adoc
13
+ if @name.to_s.empty?
14
+ "<<#{@href}>>"
15
+ else
16
+ "<<#{@href},#{@name}>>"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Coradoc
2
+ module Element
3
+ module Inline
4
+ class HardLineBreak
5
+ def to_adoc
6
+ " +\n"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Coradoc
2
+ module Element
3
+ module Inline
4
+ class Highlight
5
+ attr_accessor :content
6
+ def initialize(content, constrained = true)
7
+ @content = content
8
+ @constrained = constrained
9
+ end
10
+
11
+ def to_adoc
12
+ content = Coradoc::Generator.gen_adoc(@content)
13
+ doubled = @constrained ? "" : "#"
14
+ "#{content[/^\s*/]}#{doubled}##{content.strip}##{doubled}#{content[/\s*$/]}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../image/"
2
+ module Coradoc
3
+ module Element
4
+ module Inline
5
+ class Image
6
+ attr_reader :title, :id, :src, :attributes
7
+ def initialize(title, id, src, options = ())
8
+ @title = title
9
+ @id = id
10
+ @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
11
+ @src = src
12
+ @attributes = options.fetch(:attributes, [])
13
+ @title = options.fetch(:title, nil)
14
+ end
15
+
16
+ def to_adoc
17
+ anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
18
+ title = ".#{@title}\n" unless @title.to_s.empty?
19
+ attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
20
+ [anchor, title, "image::", @src, attrs].join("")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end