coradoc 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) 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 +7 -4
  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 +16 -3
  37. data/lib/coradoc/element/list/definition.rb +3 -1
  38. data/lib/coradoc/element/list_item.rb +15 -5
  39. data/lib/coradoc/element/paragraph.rb +8 -5
  40. data/lib/coradoc/element/revision.rb +1 -1
  41. data/lib/coradoc/element/section.rb +11 -3
  42. data/lib/coradoc/element/table.rb +6 -1
  43. data/lib/coradoc/element/tag.rb +19 -0
  44. data/lib/coradoc/element/term.rb +21 -0
  45. data/lib/coradoc/element/text_element.rb +9 -1
  46. data/lib/coradoc/element/title.rb +2 -2
  47. data/lib/coradoc/generator.rb +2 -0
  48. data/lib/coradoc/input/adoc.rb +28 -0
  49. data/lib/coradoc/input/docx.rb +35 -0
  50. data/lib/coradoc/{reverse_adoc → input/html}/README.adoc +9 -9
  51. data/lib/coradoc/{reverse_adoc → input/html}/cleaner.rb +19 -6
  52. data/lib/coradoc/input/html/config.rb +75 -0
  53. data/lib/coradoc/{reverse_adoc → input/html}/converters/a.rb +1 -1
  54. data/lib/coradoc/{reverse_adoc → input/html}/converters/aside.rb +1 -1
  55. data/lib/coradoc/{reverse_adoc → input/html}/converters/audio.rb +1 -1
  56. data/lib/coradoc/{reverse_adoc → input/html}/converters/base.rb +1 -1
  57. data/lib/coradoc/{reverse_adoc → input/html}/converters/blockquote.rb +2 -2
  58. data/lib/coradoc/{reverse_adoc → input/html}/converters/br.rb +1 -1
  59. data/lib/coradoc/{reverse_adoc → input/html}/converters/bypass.rb +1 -1
  60. data/lib/coradoc/{reverse_adoc → input/html}/converters/code.rb +1 -1
  61. data/lib/coradoc/{reverse_adoc → input/html}/converters/div.rb +1 -1
  62. data/lib/coradoc/{reverse_adoc → input/html}/converters/dl.rb +1 -1
  63. data/lib/coradoc/{reverse_adoc → input/html}/converters/drop.rb +1 -1
  64. data/lib/coradoc/{reverse_adoc → input/html}/converters/em.rb +1 -1
  65. data/lib/coradoc/{reverse_adoc → input/html}/converters/figure.rb +1 -1
  66. data/lib/coradoc/{reverse_adoc → input/html}/converters/h.rb +1 -1
  67. data/lib/coradoc/{reverse_adoc → input/html}/converters/head.rb +1 -1
  68. data/lib/coradoc/{reverse_adoc → input/html}/converters/hr.rb +1 -1
  69. data/lib/coradoc/{reverse_adoc → input/html}/converters/ignore.rb +1 -1
  70. data/lib/coradoc/{reverse_adoc → input/html}/converters/img.rb +17 -10
  71. data/lib/coradoc/{reverse_adoc → input/html}/converters/li.rb +1 -1
  72. data/lib/coradoc/{reverse_adoc → input/html}/converters/mark.rb +1 -1
  73. data/lib/coradoc/{reverse_adoc → input/html}/converters/markup.rb +1 -1
  74. data/lib/coradoc/{reverse_adoc → input/html}/converters/math.rb +3 -3
  75. data/lib/coradoc/{reverse_adoc → input/html}/converters/ol.rb +1 -1
  76. data/lib/coradoc/{reverse_adoc → input/html}/converters/p.rb +1 -1
  77. data/lib/coradoc/{reverse_adoc → input/html}/converters/pass_through.rb +1 -1
  78. data/lib/coradoc/{reverse_adoc → input/html}/converters/pre.rb +1 -1
  79. data/lib/coradoc/{reverse_adoc → input/html}/converters/q.rb +1 -1
  80. data/lib/coradoc/{reverse_adoc → input/html}/converters/strong.rb +1 -1
  81. data/lib/coradoc/{reverse_adoc → input/html}/converters/sub.rb +1 -1
  82. data/lib/coradoc/{reverse_adoc → input/html}/converters/sup.rb +1 -1
  83. data/lib/coradoc/{reverse_adoc → input/html}/converters/table.rb +36 -11
  84. data/lib/coradoc/{reverse_adoc → input/html}/converters/td.rb +1 -1
  85. data/lib/coradoc/{reverse_adoc → input/html}/converters/text.rb +2 -2
  86. data/lib/coradoc/{reverse_adoc → input/html}/converters/th.rb +1 -1
  87. data/lib/coradoc/{reverse_adoc → input/html}/converters/tr.rb +1 -1
  88. data/lib/coradoc/{reverse_adoc → input/html}/converters/video.rb +1 -1
  89. data/lib/coradoc/input/html/converters.rb +57 -0
  90. data/lib/coradoc/input/html/errors.rb +12 -0
  91. data/lib/coradoc/{reverse_adoc → input/html}/html_converter.rb +37 -22
  92. data/lib/coradoc/{reverse_adoc → input/html}/plugin.rb +6 -6
  93. data/lib/coradoc/{reverse_adoc → input/html}/plugins/plateau.rb +62 -30
  94. data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +13 -9
  95. data/lib/coradoc/input/html.rb +59 -0
  96. data/lib/coradoc/input.rb +12 -0
  97. data/lib/coradoc/output/adoc.rb +17 -0
  98. data/lib/coradoc/output/coradoc_tree_debug.rb +19 -0
  99. data/lib/coradoc/output.rb +11 -0
  100. data/lib/coradoc/parser/asciidoc/admonition.rb +24 -0
  101. data/lib/coradoc/parser/asciidoc/attribute_list.rb +67 -0
  102. data/lib/coradoc/parser/asciidoc/base.rb +101 -13
  103. data/lib/coradoc/parser/asciidoc/bibliography.rb +30 -0
  104. data/lib/coradoc/parser/asciidoc/block.rb +82 -0
  105. data/lib/coradoc/parser/asciidoc/citation.rb +48 -0
  106. data/lib/coradoc/parser/asciidoc/content.rb +15 -120
  107. data/lib/coradoc/parser/asciidoc/document_attributes.rb +12 -5
  108. data/lib/coradoc/parser/asciidoc/header.rb +1 -4
  109. data/lib/coradoc/parser/asciidoc/inline.rb +72 -0
  110. data/lib/coradoc/parser/asciidoc/list.rb +81 -0
  111. data/lib/coradoc/parser/asciidoc/paragraph.rb +33 -0
  112. data/lib/coradoc/parser/asciidoc/section.rb +36 -31
  113. data/lib/coradoc/parser/asciidoc/table.rb +32 -0
  114. data/lib/coradoc/parser/asciidoc/term.rb +23 -0
  115. data/lib/coradoc/parser/base.rb +39 -4
  116. data/lib/coradoc/transformer.rb +353 -82
  117. data/lib/coradoc/util.rb +10 -0
  118. data/lib/coradoc/version.rb +1 -1
  119. data/lib/coradoc.rb +8 -4
  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 +113 -54
  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 -53
  131. data/lib/coradoc/reverse_adoc/errors.rb +0 -10
  132. data/lib/coradoc/reverse_adoc.rb +0 -30
  133. /data/{.docker/Dockerfile → Dockerfile} +0 -0
  134. /data/lib/coradoc/{reverse_adoc → input/html}/LICENSE.txt +0 -0
@@ -0,0 +1,66 @@
1
+ require "rubocop"
2
+
3
+ def ast_from(string)
4
+ RuboCop::ProcessedSource.new(string, RUBY_VERSION.to_f).ast
5
+ end
6
+
7
+ def is_def?(arr)
8
+ if Array === arr
9
+ if arr[0] == :def
10
+ $defs << arr
11
+ else
12
+ arr.each do |e|
13
+ is_def?(e)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ path = "lib/coradoc/parser/asciidoc/"
20
+ class_files = Dir.entries(path).select{|x| File.file?(path+x)}
21
+
22
+ $all_defs = {}
23
+
24
+ class_files.each do |cf|
25
+ a = ast_from(File.open(path+cf).read)
26
+ next if a.nil?
27
+ sexp = a.to_sexp_array
28
+ $defs = []
29
+ is_def?(sexp)
30
+ $all_defs[cf] = $defs
31
+ end;
32
+
33
+ relevant_names = $all_defs.map{|fn, defs| defs.map{|d| d[1]}}.flatten;
34
+
35
+ require 'graphviz'
36
+
37
+ g = GraphViz.new( :G, :type => :digraph );
38
+
39
+ g[:fontsize] = 8
40
+ g[:rankdir] = "LR"
41
+ g[:overlap] = false
42
+ g[:splines] = false
43
+
44
+ nodes = {}
45
+
46
+ $all_defs.each do |file_name, defs|
47
+
48
+ defs.each do |ast_def|
49
+ calls = ast_def[2..-1].flatten & relevant_names
50
+ node_name = ast_def[1]
51
+ nodes[node_name] = g.add_nodes( "#{node_name}\n#{file_name}" )
52
+ end
53
+ end;
54
+
55
+ $all_defs.each do |file_name, defs|
56
+ defs.each do |ast_def|
57
+ calls = ast_def[2..-1].flatten & relevant_names
58
+ node_name = ast_def[1]
59
+ calls.each do |cl|
60
+ w = g.add_edges(nodes[node_name], nodes[cl])
61
+ w[:weight] = 1.5
62
+ end
63
+ end
64
+ end;
65
+
66
+ g.output( :png => "utils/parser_graph.png_#{Time.now.to_i}" );
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift("../coradoc/lib")
2
+
3
+ require "coradoc"
4
+ require "coradoc/input/html"
5
+
6
+
7
+ rice_path = "../mn-samples-iso/sources/international-standard/rice-2023/"
8
+
9
+ if !Dir.exist?(rice_path)
10
+ puts "pleas set path to rice-2023"
11
+ exit
12
+ end
13
+
14
+ adoc_files = Dir.glob("#{rice_path}**/*adoc")
15
+
16
+ adoc_files.each do |file_path|
17
+ puts file_path
18
+ file_path_rt = "#{file_path}.roundtrip"
19
+ file_path_diff = "#{file_path}.roundtrip.diff"
20
+ FileUtils.rm(file_path_rt) if File.exist?(file_path_rt)
21
+ FileUtils.rm(file_path_diff) if File.exist?(file_path_diff)
22
+ # begin
23
+ adoc_file = File.open(file_path).read
24
+ next if adoc_file.size == 0
25
+ puts "parsing..."
26
+ ast = Coradoc::Parser::Base.new.parse(adoc_file)
27
+ puts "transforming..."
28
+ doc = Coradoc::Transformer.transform(ast[:document])
29
+ puts "generating..."
30
+ generated_adoc = Coradoc::Generator.gen_adoc(doc)
31
+ cleaned_adoc = Coradoc::Input::HTML.cleaner.tidy(generated_adoc)
32
+ File.open("#{file_path}.roundtrip","w"){|f| f.write(cleaned_adoc)}
33
+ `diff -B #{file_path} #{file_path}.roundtrip > #{file_path}.roundtrip.diff`
34
+ # rescue
35
+ # puts "unsuccessful..."
36
+ # end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coradoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-06-01 00:00:00.000000000 Z
12
+ date: 2024-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: marcel
@@ -109,6 +109,34 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: base64
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: thor
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
112
140
  - !ruby/object:Gem::Dependency
113
141
  name: codeclimate-test-reporter
114
142
  requirement: !ruby/object:Gem::Requirement
@@ -226,31 +254,33 @@ email:
226
254
  - open.source@ribose.com
227
255
  - abunashir@gmail.com
228
256
  executables:
257
+ - coradoc
229
258
  - reverse_adoc
230
259
  - w2a
231
260
  extensions: []
232
261
  extra_rdoc_files: []
233
262
  files:
234
- - ".docker/Dockerfile"
235
- - ".docker/Makefile"
236
- - ".docker/docker-compose.yml"
237
- - ".docker/readme.md"
238
263
  - ".editorconfig"
239
264
  - ".hound.yml"
240
265
  - ".pryrc.sample"
241
266
  - ".rubocop.yml"
242
267
  - CHANGELOG.md
243
268
  - CODE_OF_CONDUCT.md
269
+ - Dockerfile
244
270
  - Gemfile
245
271
  - LICENSE.txt
246
272
  - Makefile
247
- - README.md
273
+ - README.Docker.adoc
274
+ - README.adoc
248
275
  - Rakefile
249
276
  - coradoc.gemspec
250
277
  - docker-compose.yml
278
+ - exe/coradoc
251
279
  - exe/reverse_adoc
252
280
  - exe/w2a
253
281
  - lib/coradoc.rb
282
+ - lib/coradoc/cli.rb
283
+ - lib/coradoc/converter.rb
254
284
  - lib/coradoc/document.rb
255
285
  - lib/coradoc/element/admonition.rb
256
286
  - lib/coradoc/element/attribute.rb
@@ -258,23 +288,31 @@ files:
258
288
  - lib/coradoc/element/audio.rb
259
289
  - lib/coradoc/element/author.rb
260
290
  - lib/coradoc/element/base.rb
291
+ - lib/coradoc/element/bibliography.rb
292
+ - lib/coradoc/element/bibliography_entry.rb
261
293
  - lib/coradoc/element/block.rb
262
294
  - lib/coradoc/element/block/core.rb
263
295
  - lib/coradoc/element/block/example.rb
264
296
  - lib/coradoc/element/block/literal.rb
297
+ - lib/coradoc/element/block/pass.rb
265
298
  - lib/coradoc/element/block/quote.rb
299
+ - lib/coradoc/element/block/reviewer_comment.rb
266
300
  - lib/coradoc/element/block/side.rb
267
301
  - lib/coradoc/element/block/sourcecode.rb
268
302
  - lib/coradoc/element/break.rb
303
+ - lib/coradoc/element/comment_block.rb
304
+ - lib/coradoc/element/comment_line.rb
269
305
  - lib/coradoc/element/document_attributes.rb
270
306
  - lib/coradoc/element/header.rb
271
307
  - lib/coradoc/element/image.rb
272
308
  - lib/coradoc/element/image/block_image.rb
273
309
  - lib/coradoc/element/image/core.rb
274
310
  - lib/coradoc/element/image/inline_image.rb
311
+ - lib/coradoc/element/include.rb
275
312
  - lib/coradoc/element/inline.rb
276
313
  - lib/coradoc/element/inline/anchor.rb
277
314
  - lib/coradoc/element/inline/bold.rb
315
+ - lib/coradoc/element/inline/citation.rb
278
316
  - lib/coradoc/element/inline/cross_reference.rb
279
317
  - lib/coradoc/element/inline/hard_line_break.rb
280
318
  - lib/coradoc/element/inline/highlight.rb
@@ -295,70 +333,91 @@ files:
295
333
  - lib/coradoc/element/revision.rb
296
334
  - lib/coradoc/element/section.rb
297
335
  - lib/coradoc/element/table.rb
336
+ - lib/coradoc/element/tag.rb
337
+ - lib/coradoc/element/term.rb
298
338
  - lib/coradoc/element/text_element.rb
299
339
  - lib/coradoc/element/title.rb
300
340
  - lib/coradoc/element/video.rb
301
341
  - lib/coradoc/generator.rb
342
+ - lib/coradoc/input.rb
343
+ - lib/coradoc/input/adoc.rb
344
+ - lib/coradoc/input/docx.rb
345
+ - lib/coradoc/input/html.rb
346
+ - lib/coradoc/input/html/LICENSE.txt
347
+ - lib/coradoc/input/html/README.adoc
348
+ - lib/coradoc/input/html/cleaner.rb
349
+ - lib/coradoc/input/html/config.rb
350
+ - lib/coradoc/input/html/converters.rb
351
+ - lib/coradoc/input/html/converters/a.rb
352
+ - lib/coradoc/input/html/converters/aside.rb
353
+ - lib/coradoc/input/html/converters/audio.rb
354
+ - lib/coradoc/input/html/converters/base.rb
355
+ - lib/coradoc/input/html/converters/blockquote.rb
356
+ - lib/coradoc/input/html/converters/br.rb
357
+ - lib/coradoc/input/html/converters/bypass.rb
358
+ - lib/coradoc/input/html/converters/code.rb
359
+ - lib/coradoc/input/html/converters/div.rb
360
+ - lib/coradoc/input/html/converters/dl.rb
361
+ - lib/coradoc/input/html/converters/drop.rb
362
+ - lib/coradoc/input/html/converters/em.rb
363
+ - lib/coradoc/input/html/converters/figure.rb
364
+ - lib/coradoc/input/html/converters/h.rb
365
+ - lib/coradoc/input/html/converters/head.rb
366
+ - lib/coradoc/input/html/converters/hr.rb
367
+ - lib/coradoc/input/html/converters/ignore.rb
368
+ - lib/coradoc/input/html/converters/img.rb
369
+ - lib/coradoc/input/html/converters/li.rb
370
+ - lib/coradoc/input/html/converters/mark.rb
371
+ - lib/coradoc/input/html/converters/markup.rb
372
+ - lib/coradoc/input/html/converters/math.rb
373
+ - lib/coradoc/input/html/converters/ol.rb
374
+ - lib/coradoc/input/html/converters/p.rb
375
+ - lib/coradoc/input/html/converters/pass_through.rb
376
+ - lib/coradoc/input/html/converters/pre.rb
377
+ - lib/coradoc/input/html/converters/q.rb
378
+ - lib/coradoc/input/html/converters/strong.rb
379
+ - lib/coradoc/input/html/converters/sub.rb
380
+ - lib/coradoc/input/html/converters/sup.rb
381
+ - lib/coradoc/input/html/converters/table.rb
382
+ - lib/coradoc/input/html/converters/td.rb
383
+ - lib/coradoc/input/html/converters/text.rb
384
+ - lib/coradoc/input/html/converters/th.rb
385
+ - lib/coradoc/input/html/converters/tr.rb
386
+ - lib/coradoc/input/html/converters/video.rb
387
+ - lib/coradoc/input/html/errors.rb
388
+ - lib/coradoc/input/html/html_converter.rb
389
+ - lib/coradoc/input/html/plugin.rb
390
+ - lib/coradoc/input/html/plugins/plateau.rb
391
+ - lib/coradoc/input/html/postprocessor.rb
302
392
  - lib/coradoc/legacy_parser.rb
303
393
  - lib/coradoc/oscal.rb
394
+ - lib/coradoc/output.rb
395
+ - lib/coradoc/output/adoc.rb
396
+ - lib/coradoc/output/coradoc_tree_debug.rb
304
397
  - lib/coradoc/parser.rb
398
+ - lib/coradoc/parser/asciidoc/admonition.rb
399
+ - lib/coradoc/parser/asciidoc/attribute_list.rb
305
400
  - lib/coradoc/parser/asciidoc/base.rb
401
+ - lib/coradoc/parser/asciidoc/bibliography.rb
402
+ - lib/coradoc/parser/asciidoc/block.rb
403
+ - lib/coradoc/parser/asciidoc/citation.rb
306
404
  - lib/coradoc/parser/asciidoc/content.rb
307
405
  - lib/coradoc/parser/asciidoc/document_attributes.rb
308
406
  - lib/coradoc/parser/asciidoc/header.rb
407
+ - lib/coradoc/parser/asciidoc/inline.rb
408
+ - lib/coradoc/parser/asciidoc/list.rb
409
+ - lib/coradoc/parser/asciidoc/paragraph.rb
309
410
  - lib/coradoc/parser/asciidoc/section.rb
411
+ - lib/coradoc/parser/asciidoc/table.rb
412
+ - lib/coradoc/parser/asciidoc/term.rb
310
413
  - lib/coradoc/parser/base.rb
311
- - lib/coradoc/reverse_adoc.rb
312
- - lib/coradoc/reverse_adoc/LICENSE.txt
313
- - lib/coradoc/reverse_adoc/README.adoc
314
- - lib/coradoc/reverse_adoc/cleaner.rb
315
- - lib/coradoc/reverse_adoc/config.rb
316
- - lib/coradoc/reverse_adoc/converters.rb
317
- - lib/coradoc/reverse_adoc/converters/a.rb
318
- - lib/coradoc/reverse_adoc/converters/aside.rb
319
- - lib/coradoc/reverse_adoc/converters/audio.rb
320
- - lib/coradoc/reverse_adoc/converters/base.rb
321
- - lib/coradoc/reverse_adoc/converters/blockquote.rb
322
- - lib/coradoc/reverse_adoc/converters/br.rb
323
- - lib/coradoc/reverse_adoc/converters/bypass.rb
324
- - lib/coradoc/reverse_adoc/converters/code.rb
325
- - lib/coradoc/reverse_adoc/converters/div.rb
326
- - lib/coradoc/reverse_adoc/converters/dl.rb
327
- - lib/coradoc/reverse_adoc/converters/drop.rb
328
- - lib/coradoc/reverse_adoc/converters/em.rb
329
- - lib/coradoc/reverse_adoc/converters/figure.rb
330
- - lib/coradoc/reverse_adoc/converters/h.rb
331
- - lib/coradoc/reverse_adoc/converters/head.rb
332
- - lib/coradoc/reverse_adoc/converters/hr.rb
333
- - lib/coradoc/reverse_adoc/converters/ignore.rb
334
- - lib/coradoc/reverse_adoc/converters/img.rb
335
- - lib/coradoc/reverse_adoc/converters/li.rb
336
- - lib/coradoc/reverse_adoc/converters/mark.rb
337
- - lib/coradoc/reverse_adoc/converters/markup.rb
338
- - lib/coradoc/reverse_adoc/converters/math.rb
339
- - lib/coradoc/reverse_adoc/converters/ol.rb
340
- - lib/coradoc/reverse_adoc/converters/p.rb
341
- - lib/coradoc/reverse_adoc/converters/pass_through.rb
342
- - lib/coradoc/reverse_adoc/converters/pre.rb
343
- - lib/coradoc/reverse_adoc/converters/q.rb
344
- - lib/coradoc/reverse_adoc/converters/strong.rb
345
- - lib/coradoc/reverse_adoc/converters/sub.rb
346
- - lib/coradoc/reverse_adoc/converters/sup.rb
347
- - lib/coradoc/reverse_adoc/converters/table.rb
348
- - lib/coradoc/reverse_adoc/converters/td.rb
349
- - lib/coradoc/reverse_adoc/converters/text.rb
350
- - lib/coradoc/reverse_adoc/converters/th.rb
351
- - lib/coradoc/reverse_adoc/converters/tr.rb
352
- - lib/coradoc/reverse_adoc/converters/video.rb
353
- - lib/coradoc/reverse_adoc/errors.rb
354
- - lib/coradoc/reverse_adoc/html_converter.rb
355
- - lib/coradoc/reverse_adoc/plugin.rb
356
- - lib/coradoc/reverse_adoc/plugins/plateau.rb
357
- - lib/coradoc/reverse_adoc/postprocessor.rb
358
414
  - lib/coradoc/transformer.rb
415
+ - lib/coradoc/util.rb
359
416
  - lib/coradoc/version.rb
360
417
  - lib/reverse_adoc.rb
361
418
  - todo.md
419
+ - utils/parser_analyzer.rb
420
+ - utils/round_trip.rb
362
421
  homepage: https://www.metanorma.org
363
422
  licenses:
364
423
  - MIT
data/.docker/Makefile DELETED
@@ -1,35 +0,0 @@
1
- export SPEC ?= spec
2
- SPEC_FILE = $(subst ../,, $(SPEC))
3
- export RUBY_IMAGE ?= ruby:3.1.2-slim
4
-
5
- .PHONY: up
6
- up:
7
- docker-compose up
8
-
9
- .PHONY: down
10
- down:
11
- docker-compose down
12
-
13
- .PHONY: test
14
- test: rspec
15
-
16
- .PHONY: ssh
17
- ssh:
18
- docker-compose run lib bash
19
-
20
- .PHONY: install
21
- install:
22
- docker-compose run lib bin/setup
23
-
24
- .PHONY: console
25
- console:
26
- docker-compose run lib bin/console
27
-
28
- .PHONY: rspec
29
- rspec:
30
- docker-compose run lib bin/rspec ${SPEC_FILE}
31
-
32
- .PHONY: setup
33
- setup:
34
- docker-compose build --build-arg RUBY_IMAGE=${RUBY_IMAGE}
35
- docker-compose run lib bin/setup
@@ -1,14 +0,0 @@
1
- version: "3"
2
-
3
- services:
4
- lib:
5
- build:
6
- context: .
7
- dockerfile: ./.docker/Dockerfile
8
-
9
- volumes:
10
- - .:/workspace:z
11
- - bundle:/bundle:z
12
-
13
- volumes:
14
- bundle:
data/Makefile DELETED
@@ -1 +0,0 @@
1
- .docker/Makefile
data/README.md DELETED
@@ -1,73 +0,0 @@
1
- # Coradoc
2
-
3
- Coradoc is a modern Parser for Asciidoc document. It defines a grammar for
4
- AsciiDoc, and then build the Parser for that grammar.
5
-
6
- Once the document is parsed, it provides a pure ruby object `Coradoc::Document`,
7
- which can used to customize the document in easiest way.
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- ```ruby
14
- gem "coradoc"
15
- ```
16
-
17
- And then execute:
18
-
19
- ```sh
20
- bundle install
21
- ```
22
-
23
- Or install it yourself as:
24
-
25
- ```sh
26
- gem install coradoc
27
- ```
28
-
29
- ## Development
30
-
31
- We are following Sandi Metz's Rules for this gem, you can read the
32
- [description of the rules here][sandi-metz] All new code should follow these
33
- rules. If you make changes in a pre-existing file that violates these rules you
34
- should fix the violations as part of your contribution.
35
-
36
- ### Setup
37
-
38
- Clone the repository.
39
-
40
- ```sh
41
- git clone https://github.com/metanorma/coradoc.git
42
- ```
43
-
44
- Setup your environment in docker
45
-
46
- ```sh
47
- make setup
48
- ```
49
-
50
- Run the test suite
51
-
52
- ```sh
53
- make test
54
- ```
55
-
56
-
57
- ## Usages
58
-
59
- ### Parsing a document
60
-
61
- To parse any AsciiDoc, we can use the following:
62
-
63
- ```ruby
64
- Coradoc::Parser.parse(sample_asciidoc)
65
- ```
66
-
67
- This interface will return the abstract syntax tree.
68
-
69
- ### Converting from HTML to AsciiDoc (reverse_adoc)
70
-
71
- See: [reverse_adoc README](https://github.com/metanorma/coradoc/blob/main/lib/coradoc/reverse_adoc/README.adoc)
72
-
73
- [sandi-metz]: http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers
data/docker-compose.yml DELETED
@@ -1 +0,0 @@
1
- .docker/docker-compose.yml
@@ -1,73 +0,0 @@
1
- require "tmpdir"
2
-
3
- module Coradoc::ReverseAdoc
4
- class Config
5
- def initialize
6
- @unknown_tags = :pass_through
7
- @input_format = :html
8
- @mathml2asciimath = false
9
- @external_images = false
10
-
11
- # Destination to save file and images
12
- @destination = nil
13
-
14
- # Source of HTML
15
- # @sourcedir = nil
16
-
17
- # Image counter, assuming there are max 999 images
18
- @image_counter = 1
19
- # pad with 0s
20
- @image_counter_pattern = "%03d"
21
-
22
- @em_delimiter = "_".freeze
23
- @strong_delimiter = "*".freeze
24
- @inline_options = {}
25
- @tag_border = " ".freeze
26
-
27
- @split_sections = nil
28
-
29
- # Document width - used to compute table sizes.
30
- # This is an assumption for screen size in input document.
31
- # If column widths are specified in absolute values, then we
32
- # have to convert them to relative values, as AsciiDoc only
33
- # supports those.
34
- @doc_width = 1000
35
-
36
- # Plugin system
37
- @plugins = []
38
-
39
- # Debugging options
40
- @track_time = false
41
- end
42
-
43
- def with(options = {})
44
- old_options = @inline_options
45
- @inline_options = options
46
- result = yield
47
- @inline_options = old_options
48
- result
49
- end
50
-
51
- def self.declare_option(option)
52
- define_method(option) do
53
- @inline_options[option] || instance_variable_get(:"@#{option}")
54
- end
55
-
56
- attr_writer option
57
- end
58
-
59
- declare_option :unknown_tags
60
- declare_option :tag_border
61
- declare_option :mathml2asciimath
62
- declare_option :external_images
63
- declare_option :destination
64
- declare_option :sourcedir
65
- declare_option :image_counter
66
- declare_option :image_counter_pattern
67
- declare_option :input_format
68
- declare_option :split_sections
69
- declare_option :doc_width
70
- declare_option :plugins
71
- declare_option :track_time
72
- end
73
- end
@@ -1,53 +0,0 @@
1
- module Coradoc::ReverseAdoc
2
- module Converters
3
- def self.register(tag_name, converter)
4
- @@converters ||= {}
5
- @@converters[tag_name.to_sym] = converter
6
- end
7
-
8
- def self.unregister(tag_name)
9
- @@converters.delete(tag_name.to_sym)
10
- end
11
-
12
- def self.lookup(tag_name)
13
- @@converters[tag_name.to_sym] or default_converter(tag_name)
14
- end
15
-
16
- # Note: process won't run plugin hooks
17
- def self.process(node, state)
18
- node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
19
- return node.map { |i| process(i, state) }.join if node.is_a? Array
20
-
21
- lookup(node.name).convert(node, state)
22
- end
23
-
24
- def self.process_coradoc(node, state)
25
- node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
26
- return node.map { |i| process_coradoc(i, state) } if node.is_a? Array
27
-
28
- plugins = state[:plugin_instances] || {}
29
- process = proc { lookup(node.name).to_coradoc(node, state) }
30
- plugins.each do |i|
31
- prev_process = process
32
- process = proc { i.html_tree_run_hooks(node, state, &prev_process) }
33
- end
34
- process.(node, state)
35
- end
36
-
37
- def self.default_converter(tag_name)
38
- case Coradoc::ReverseAdoc.config.unknown_tags.to_sym
39
- when :pass_through
40
- Coradoc::ReverseAdoc::Converters::PassThrough.new
41
- when :drop
42
- Coradoc::ReverseAdoc::Converters::Drop.new
43
- when :bypass
44
- Coradoc::ReverseAdoc::Converters::Bypass.new
45
- when :raise
46
- raise UnknownTagError, "unknown tag: #{tag_name}"
47
- else
48
- raise InvalidConfigurationError,
49
- "unknown value #{Coradoc::ReverseAdoc.config.unknown_tags.inspect} for Coradoc::ReverseAdoc.config.unknown_tags"
50
- end
51
- end
52
- end
53
- end
@@ -1,10 +0,0 @@
1
- module Coradoc::ReverseAdoc
2
- class Error < StandardError
3
- end
4
-
5
- class UnknownTagError < Error
6
- end
7
-
8
- class InvalidConfigurationError < Error
9
- end
10
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
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"
14
-
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
File without changes