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,81 @@
1
+ module Coradoc
2
+ module Parser
3
+ module Asciidoc
4
+ module List
5
+
6
+ def list
7
+ (
8
+ unordered_list |
9
+ ordered_list # definition_list |
10
+ ).as(:list)
11
+ end
12
+
13
+ def ordered_list(nesting_level = 1)
14
+ attrs = (attribute_list >> newline).maybe
15
+ r = olist_item(nesting_level)
16
+ if nesting_level <= 8
17
+ r = r | ordered_list(nesting_level + 1)
18
+ end
19
+ attrs >> r.repeat(1).as(:ordered)
20
+ end
21
+
22
+ def unordered_list(nesting_level = 1)
23
+ attrs = (attribute_list >> newline).maybe
24
+ r = ulist_item(nesting_level)
25
+ if nesting_level <= 8
26
+ r = r | unordered_list(nesting_level + 1)
27
+ end
28
+ attrs >> r.repeat(1).as(:unordered)
29
+ end
30
+
31
+ def definition_list(delimiter = "::")
32
+ (attribute_list >> newline).maybe >>
33
+ dlist_item(delimiter).as(:definition_list).repeat(1) >>
34
+ dlist_item(delimiter).absent?
35
+ end
36
+
37
+ def olist_item(nesting_level = 1)
38
+ nl2 = nesting_level - 1
39
+ marker = match(/^\./)
40
+ marker = marker >> str(".").repeat(nl2, nl2) if nl2 > 0
41
+ str("").as(:list_item) >>
42
+ marker.as(:marker) >> str(".").absent? >>
43
+ match("\n").absent? >> space >> text_line(true)
44
+ end
45
+
46
+ def ulist_item(nesting_level = 1)
47
+ nl2 = nesting_level - 1
48
+ marker = match(/^\*/)
49
+ marker = marker >> str("*").repeat(nl2, nl2) if nl2 > 0
50
+ str("").as(:list_item) >>
51
+ marker.as(:marker) >> str("*").absent? >>
52
+ str(' [[[').absent? >>
53
+ match("\n").absent? >> space >> text_line(true)
54
+ end
55
+
56
+ def dlist_delimiter
57
+ (str("::") | str(":::") | str("::::") | str(";;")
58
+ ).as(:delimiter)
59
+ end
60
+
61
+ def dlist_term(delimiter)
62
+ (match("[^\n:]").repeat(1) #>> empty_line.repeat(0)
63
+ ).as(:term) >> dlist_delimiter
64
+ end
65
+
66
+ def dlist_definition
67
+ (text #>> empty_line.repeat(0)
68
+ ).as(:definition) >> line_ending >> empty_line.repeat(0)
69
+ end
70
+
71
+ def dlist_item(delimiter)
72
+ (((dlist_term(delimiter).as(:terms).repeat(1) >> line_ending >>
73
+ empty_line.repeat(0)).repeat(1) >>
74
+ dlist_definition) |
75
+ (dlist_term(delimiter).repeat(1,1).as(:terms) >> space >> dlist_definition)
76
+ ).as(:definition_list_item).repeat(1)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,33 @@
1
+ module Coradoc
2
+ module Parser
3
+ module Asciidoc
4
+ module Paragraph
5
+
6
+ def paragraph_text_line
7
+ (asciidoc_char_with_id.absent? | text_id ) >>
8
+ literal_space? >>
9
+ (text_formatted.as(:text) # >>
10
+ ) | term | term2
11
+ end
12
+
13
+ def paragraph
14
+ ( block_id.maybe >>
15
+ block_title.maybe >>
16
+ (attribute_list >> newline).maybe >>
17
+ (paragraph_text_line.repeat(1,1) >> any.absent? |
18
+ (paragraph_text_line >> newline_single.as(:line_break)).repeat(1) >>
19
+ (paragraph_text_line.repeat(1,1)).repeat(0,1)
20
+ ).as(:lines) >>
21
+ newline.repeat(0)
22
+ ).as(:paragraph)
23
+ end
24
+
25
+ def paragraph_attributes
26
+ str("[") >>
27
+ keyword.as(:key) >> str("=") >>
28
+ word.as(:value) >> str("]") >> newline
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,15 +1,34 @@
1
- require_relative "base"
2
- require_relative "content"
3
-
4
1
  module Coradoc
5
2
  module Parser
6
3
  module Asciidoc
7
4
  module Section
8
- include Coradoc::Parser::Asciidoc::Base
9
- include Coradoc::Parser::Asciidoc::Content
5
+
6
+ def contents
7
+ (
8
+ citation |
9
+ term | term2 |
10
+ bib_entry |
11
+ block_image |
12
+ tag |
13
+ comment_block |
14
+ comment_line |
15
+ include_directive |
16
+ admonition_line |
17
+ block.as(:block) |
18
+ table.as(:table) |
19
+ highlight.as(:highlight) |
20
+ glossaries.as(:glossaries) |
21
+ paragraph |
22
+ list |
23
+ empty_line.as(:line_break)
24
+ ).repeat(1)
25
+ end
10
26
 
11
27
  def section_block(level = 2)
28
+ return nil if level > 8
29
+ (attribute_list >> newline).maybe >>
12
30
  section_id.maybe >>
31
+ (attribute_list >> newline).maybe >>
13
32
  section_title(level).as(:title) >>
14
33
  contents.as(:contents).maybe
15
34
  end
@@ -23,37 +42,23 @@ module Coradoc
23
42
  # Heading
24
43
  def section_title(level = 2, max_level = 8)
25
44
  match("=").repeat(level, max_level).as(:level) >>
26
- space? >> text.as(:text) >> endline.as(:break)
45
+ str('=').absent? >>
46
+ space? >> text.as(:text) >> endline.as(:line_break)
27
47
  end
28
48
 
29
49
  # section
30
- def section
31
- section_block >> second_level_section.repeat.maybe.as(:sections)
32
- end
33
-
34
- def sub_section(level)
35
- newline.maybe >> section_block(level)
36
- end
37
-
38
- def second_level_section
39
- sub_section(3) >> third_level_section.repeat.maybe.as(:sections)
50
+ def section(level = 2)
51
+ r = section_block(level)
52
+ if level < 8
53
+ r = r >> section(level + 1).as(:section).repeat(0).as(:sections)
54
+ end
55
+ if level == 2
56
+ (r).as(:section)
57
+ else
58
+ r
59
+ end
40
60
  end
41
61
 
42
- def third_level_section
43
- sub_section(4) >> fourth_level_section.repeat.maybe.as(:sections)
44
- end
45
-
46
- def fourth_level_section
47
- sub_section(5) >> fifth_level_section.repeat.maybe.as(:sections)
48
- end
49
-
50
- def fifth_level_section
51
- sub_section(6) >> sixth_level_section.repeat.maybe.as(:sections)
52
- end
53
-
54
- def sixth_level_section
55
- sub_section(7) >> sub_section(8).repeat.maybe.as(:sections)
56
- end
57
62
  end
58
63
  end
59
64
  end
@@ -0,0 +1,32 @@
1
+ module Coradoc
2
+ module Parser
3
+ module Asciidoc
4
+ module Table
5
+ # include Coradoc::Parser::Asciidoc::Base
6
+
7
+ def table
8
+ block_id.maybe >>
9
+ (attribute_list >> newline).maybe >>
10
+ block_title.maybe >>
11
+ (attribute_list >> newline).maybe >>
12
+ str("|===") >> line_ending >>
13
+ table_row.repeat(1).as(:rows) >>
14
+ str("|===") >> line_ending
15
+ end
16
+
17
+ def table_row
18
+ (literal_space? >> str("|") >> (cell_content | empty_cell_content))
19
+ .repeat(1).as(:cols) >> line_ending
20
+ end
21
+
22
+ def empty_cell_content
23
+ str("|").absent? >> literal_space.as(:text)
24
+ end
25
+
26
+ def cell_content
27
+ str("|").absent? >> literal_space? >> rich_texts.as(:text)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ module Coradoc
2
+ module Parser
3
+ module Asciidoc
4
+ module Term
5
+ def term_type
6
+ (str("alt") | str("deprecated") | str("domain")).as(:term_type)
7
+ end
8
+
9
+ def term
10
+ term_type >> str(':[') >>
11
+ match('[^\]]').repeat(1).as(:term) >>
12
+ str("]") >> str("\n").repeat(1).as(:line_break)
13
+ end
14
+
15
+ def term2
16
+ match('^\[') >> term_type >> str(']#') >>
17
+ match('[^\#]').repeat(1).as(:term2) >> str('#') >>
18
+ str("\n").repeat(1).as(:line_break)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,22 +1,55 @@
1
1
  require "parslet"
2
2
  require "parslet/convenience"
3
3
 
4
- require_relative "asciidoc/header"
4
+ require_relative "asciidoc/attribute_list"
5
+ require_relative "asciidoc/base"
6
+ require_relative "asciidoc/block"
7
+ require_relative "asciidoc/citation"
8
+ require_relative "asciidoc/content"
5
9
  require_relative "asciidoc/document_attributes"
10
+ require_relative "asciidoc/header"
11
+ require_relative "asciidoc/inline"
12
+ require_relative "asciidoc/list"
13
+ require_relative "asciidoc/paragraph"
6
14
  require_relative "asciidoc/section"
15
+ require_relative "asciidoc/table"
16
+ require_relative "asciidoc/term"
7
17
 
8
18
  module Coradoc
9
19
  module Parser
10
20
  class Base < Parslet::Parser
11
- include Coradoc::Parser::Asciidoc::Header
21
+ include Coradoc::Parser::Asciidoc::AttributeList
22
+ include Coradoc::Parser::Asciidoc::Base
23
+ include Coradoc::Parser::Asciidoc::Block
24
+ include Coradoc::Parser::Asciidoc::Citation
25
+ include Coradoc::Parser::Asciidoc::Content
12
26
  include Coradoc::Parser::Asciidoc::DocumentAttributes
27
+ include Coradoc::Parser::Asciidoc::Header
28
+ include Coradoc::Parser::Asciidoc::Inline
29
+ include Coradoc::Parser::Asciidoc::List
30
+ include Coradoc::Parser::Asciidoc::Paragraph
13
31
  include Coradoc::Parser::Asciidoc::Section
32
+ include Coradoc::Parser::Asciidoc::Table
33
+ include Coradoc::Parser::Asciidoc::Term
14
34
 
15
35
  root :document
16
36
  rule(:document) do
17
37
  (
18
- document_attributess.as(:document_attributes) |
38
+ admonition_line |
39
+ bib_entry |
40
+ block_image |
41
+ term | term2 |
42
+ citation |
43
+ tag |
44
+ comment_block |
45
+ comment_line |
46
+ block.as(:block) |
19
47
  section.as(:section) |
48
+ include_directive |
49
+ document_attributes |
50
+ list |
51
+ table.as(:table) |
52
+ paragraph |
20
53
  header.as(:header) |
21
54
  empty_line.as(:line_break) |
22
55
  any.as(:unparsed)
@@ -25,7 +58,9 @@ module Coradoc
25
58
 
26
59
  def self.parse(filename)
27
60
  content = File.read(filename)
28
- new.parse_with_debug(content)
61
+ new.parse(content)
62
+ rescue Parslet::ParseFailed => e
63
+ puts e.parse_failure_cause.ascii_tree
29
64
  end
30
65
  end
31
66
  end
@@ -1,30 +1,18 @@
1
- # frozen_string_literal: true
1
+ warn <<~WARN
2
+ Deprecated: coradoc/reverse_adoc has been renamed to coradoc/input/html.
3
+ | Please update your references from:
4
+ | require 'coradoc/reverse_adoc'
5
+ | To:
6
+ | require 'coradoc/input/html'
7
+ |
8
+ | You are referencing an old require here:
9
+ | #{caller.join("\n| ")}
10
+ |
11
+ | Please also ensure that you replace all references to Coradoc::ReverseAdoc
12
+ | in your code with Coradoc::Input::HTML.
13
+ WARN
2
14
 
3
- require "digest"
4
- require "nokogiri"
5
- require_relative "../coradoc"
6
- require_relative "reverse_adoc/errors"
7
- require_relative "reverse_adoc/cleaner"
8
- require_relative "reverse_adoc/config"
9
- require_relative "reverse_adoc/converters"
10
- require_relative "reverse_adoc/converters/base"
11
- require_relative "reverse_adoc/html_converter"
12
- require_relative "reverse_adoc/plugin"
13
- require_relative "reverse_adoc/postprocessor"
15
+ require 'coradoc'
16
+ require 'coradoc/input/html'
14
17
 
15
-
16
- module Coradoc::ReverseAdoc
17
- def self.convert(input, options = {})
18
- Coradoc::ReverseAdoc::HtmlConverter.convert(input, options)
19
- end
20
-
21
- def self.config
22
- @config ||= Config.new
23
- yield @config if block_given?
24
- @config
25
- end
26
-
27
- def self.cleaner
28
- @cleaner ||= Cleaner.new
29
- end
30
- end
18
+ Coradoc::ReverseAdoc = Coradoc::Input::HTML