review-retrovert 0.2.2 → 0.9.1

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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/retrovert.yml +39 -0
  3. data/.gitignore +2 -2
  4. data/.ruby-version +1 -0
  5. data/Gemfile +1 -0
  6. data/Gemfile.lock +68 -2
  7. data/README.md +6 -3
  8. data/lib/review/retrovert/cli.rb +2 -0
  9. data/lib/review/retrovert/converter.rb +255 -16
  10. data/lib/review/retrovert/version.rb +1 -1
  11. data/review-retrovert.gemspec +1 -1
  12. data/testdata/mybook/.gitignore +7 -0
  13. data/testdata/mybook/README.md +43 -0
  14. data/testdata/mybook/Rakefile +16 -0
  15. data/testdata/mybook/catalog.yml +33 -0
  16. data/testdata/mybook/config-starter.yml +139 -0
  17. data/testdata/mybook/config.yml +375 -0
  18. data/testdata/mybook/contents/00-preface.re +83 -0
  19. data/testdata/mybook/contents/01-install.re +272 -0
  20. data/testdata/mybook/contents/02-tutorial.re +1008 -0
  21. data/testdata/mybook/contents/03-syntax.re +2613 -0
  22. data/testdata/mybook/contents/04-customize.re +728 -0
  23. data/testdata/mybook/contents/05-faq.re +328 -0
  24. data/testdata/mybook/contents/06-bestpractice.re +971 -0
  25. data/testdata/mybook/contents/91-compare.re +18 -0
  26. data/testdata/mybook/contents/92-filelist.re +119 -0
  27. data/testdata/mybook/contents/93-background.re +267 -0
  28. data/testdata/mybook/contents/99-postface.re +38 -0
  29. data/testdata/mybook/css/normalize.css +349 -0
  30. data/testdata/mybook/css/webstyle.css +514 -0
  31. data/testdata/mybook/images/03-syntax/favicon-16x16.png +0 -0
  32. data/testdata/mybook/images/03-syntax/figure_heretop.png +0 -0
  33. data/testdata/mybook/images/03-syntax/tw-icon1.jpg +0 -0
  34. data/testdata/mybook/images/03-syntax/tw-icon2.jpg +0 -0
  35. data/testdata/mybook/images/03-syntax/tw-icon3.jpg +0 -0
  36. data/testdata/mybook/images/03-syntax/tw-icon4.jpg +0 -0
  37. data/testdata/mybook/images/04-customize/caption_pagebreak.png +0 -0
  38. data/testdata/mybook/images/04-customize/chaptitlepage_sample.png +0 -0
  39. data/testdata/mybook/images/05-faq/codeblock_rpadding1.png +0 -0
  40. data/testdata/mybook/images/05-faq/codeblock_rpadding2.png +0 -0
  41. data/testdata/mybook/images/06-bestpractice/figure_heretop.png +0 -0
  42. data/testdata/mybook/images/06-bestpractice/font_beramono.png +0 -0
  43. data/testdata/mybook/images/06-bestpractice/heading_design1.png +0 -0
  44. data/testdata/mybook/images/06-bestpractice/heading_design2.png +0 -0
  45. data/testdata/mybook/images/06-bestpractice/margin_book.png +0 -0
  46. data/testdata/mybook/images/06-bestpractice/multiline-title.png +0 -0
  47. data/testdata/mybook/images/06-bestpractice/preface_numbered.png +0 -0
  48. data/testdata/mybook/images/06-bestpractice/program_border.png +0 -0
  49. data/testdata/mybook/images/06-bestpractice/sechead_design_4.png +0 -0
  50. data/testdata/mybook/images/06-bestpractice/titlepage-samples.png +0 -0
  51. data/testdata/mybook/images/93-background/bug913.png +0 -0
  52. data/testdata/mybook/images/93-background/slide2.png +0 -0
  53. data/testdata/mybook/images/cover_a5.pdf +0 -0
  54. data/testdata/mybook/images/cover_b5.pdf +0 -0
  55. data/testdata/mybook/images/tw-icon.jpg +0 -0
  56. data/testdata/mybook/layouts/layout.epub.erb +29 -0
  57. data/testdata/mybook/layouts/layout.html5.erb +106 -0
  58. data/testdata/mybook/layouts/layout.tex.erb +546 -0
  59. data/testdata/mybook/lib/hooks/beforetexcompile.rb +55 -0
  60. data/testdata/mybook/lib/ruby/review-builder.rb +503 -0
  61. data/testdata/mybook/lib/ruby/review-cli.rb +58 -0
  62. data/testdata/mybook/lib/ruby/review-compiler.rb +523 -0
  63. data/testdata/mybook/lib/ruby/review-epubmaker.rb +606 -0
  64. data/testdata/mybook/lib/ruby/review-htmlbuilder.rb +661 -0
  65. data/testdata/mybook/lib/ruby/review-latexbuilder.rb +782 -0
  66. data/testdata/mybook/lib/ruby/review-maker.rb +235 -0
  67. data/testdata/mybook/lib/ruby/review-monkeypatch.rb +91 -0
  68. data/testdata/mybook/lib/ruby/review-pdfmaker.rb +468 -0
  69. data/testdata/mybook/lib/ruby/review-textbuilder.rb +36 -0
  70. data/testdata/mybook/lib/ruby/review-tocparser.rb +285 -0
  71. data/testdata/mybook/lib/ruby/review-webmaker.rb +433 -0
  72. data/testdata/mybook/lib/tasks/mytasks.rake +31 -0
  73. data/testdata/mybook/lib/tasks/review.rake +142 -0
  74. data/testdata/mybook/lib/tasks/review.rake.orig +72 -0
  75. data/testdata/mybook/lib/tasks/starter.rake +326 -0
  76. data/testdata/mybook/locale.yml +6 -0
  77. data/testdata/mybook/review-ext.rb +206 -0
  78. data/testdata/mybook/sty/jumoline.sty +310 -0
  79. data/testdata/mybook/sty/mycolophon.sty +81 -0
  80. data/testdata/mybook/sty/mystyle.sty +8 -0
  81. data/testdata/mybook/sty/mytextsize.sty +61 -0
  82. data/testdata/mybook/sty/mytitlepage.sty +103 -0
  83. data/testdata/mybook/sty/reviewmacro.sty +60 -0
  84. data/testdata/mybook/sty/starter-codeblock.sty +332 -0
  85. data/testdata/mybook/sty/starter-color.sty +79 -0
  86. data/testdata/mybook/sty/starter-font.sty +112 -0
  87. data/testdata/mybook/sty/starter-heading.sty +514 -0
  88. data/testdata/mybook/sty/starter-note.sty +127 -0
  89. data/testdata/mybook/sty/starter-section.sty +262 -0
  90. data/testdata/mybook/sty/starter-toc.sty +72 -0
  91. data/testdata/mybook/sty/starter.sty +554 -0
  92. data/testdata/mybook/style.css +597 -0
  93. metadata +100 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 973904fbc954f18f83b83e0a1cd86919956cc8870537be8adaebf24171627f29
4
- data.tar.gz: b40c3c061df07976c422af9d872e6c2da60ff7f2ee3ebad0ea09a75ef491b6e0
3
+ metadata.gz: a9311aa0fa85bd42652cbbe163b02383bb3e3ce8b82d5c10f1d85af48ecda098
4
+ data.tar.gz: cac37e6eae36803b96a0f009695ffe480a7fafe4642a1bb45a44a4bcc1eb948b
5
5
  SHA512:
6
- metadata.gz: 1d1ac6401a6c5dda48030a466568f4487ef90f0fa98496117843b89b95697227788587da3c42cedae0ff6ab02f9f9b817c21ef4a26c2aa8ad372804f52cea7de
7
- data.tar.gz: e1c1319edf9624385c3187f1cd7b2f0066fc18ea29f1a75ded426b1392dcb53c2cd30accc4c10e6e3cbc1266acf0af3336ae2f43b831bd9bc1d258b8453583ce
6
+ metadata.gz: 506fd1726a38d677b12c6641ba1f77330c332c9ec75d9d18427cedc8647ec319762df7025b8bcc65458e7bac9921fd62b6c3e7f3d6faf0447c5ad15a486ed2a9
7
+ data.tar.gz: 21dabf3b90b0d6f93183d7e48aa7a3b32614b37edc078f6c538c6e8b810fc5c5f4ae7577ca10d9f6a45cc8732867d2e12f558f7ff5d1fb4fb97ddefe547c80fa
@@ -0,0 +1,39 @@
1
+ on:
2
+ pull_request:
3
+ push:
4
+ branches:
5
+ - master
6
+
7
+ name: Retrovert
8
+ jobs:
9
+ review:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6
16
+ - run: bundle install
17
+ # spec
18
+ - name: spec
19
+ run: bundle exec rake spec
20
+ # convert
21
+ - name: convert
22
+ run: bundle exec review-retrovert convert testdata/mybook/config.yml tmp -f
23
+ # build
24
+ - name: review build
25
+ uses: docker://srzzumix/review-retrovert
26
+ with:
27
+ entrypoint: bash
28
+ args: -c "cd tmp; rake preproc all"
29
+ # artifacts
30
+ - name: artifacts
31
+ uses: actions/upload-artifact@v1
32
+ with:
33
+ name: mybook
34
+ path: tmp/mybook.pdf
35
+ - name: artifacts
36
+ uses: actions/upload-artifact@v1
37
+ with:
38
+ name: mybook
39
+ path: tmp/mybook.epub
data/.gitignore CHANGED
@@ -5,11 +5,11 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /tmp/
8
+ tmp/
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .rakeTasks
13
13
  .idea
14
14
 
15
- *.gem
15
+ *.gem
@@ -0,0 +1 @@
1
+ 2.5.5
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+ gem 'aruba', '~> 1.0.2'
@@ -1,21 +1,80 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- review-retrovert (0.2.2)
4
+ review-retrovert (0.3.4)
5
5
  review (>= 3.2.0, < 4.0)
6
6
  thor
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ activesupport (6.0.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ aruba (1.0.2)
18
+ childprocess (>= 2.0, < 5.0)
19
+ contracts (~> 0.16.0)
20
+ cucumber (>= 2.4, < 5.0)
21
+ ffi (~> 1.9)
22
+ rspec-expectations (~> 3.4)
23
+ thor (~> 1.0)
24
+ builder (3.2.4)
25
+ childprocess (4.0.0)
26
+ concurrent-ruby (1.1.6)
27
+ contracts (0.16.0)
28
+ cucumber (4.1.0)
29
+ builder (~> 3.2, >= 3.2.3)
30
+ cucumber-core (~> 7.1, >= 7.1.0)
31
+ cucumber-create-meta (~> 1.0.0, >= 1.0.0)
32
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
33
+ cucumber-gherkin (~> 14.0, >= 14.0.1)
34
+ cucumber-html-formatter (~> 7.0, >= 7.0.0)
35
+ cucumber-messages (~> 12.2, >= 12.2.0)
36
+ cucumber-wire (~> 3.1, >= 3.1.0)
37
+ diff-lcs (~> 1.3, >= 1.3, < 1.4)
38
+ multi_test (~> 0.1, >= 0.1.2)
39
+ sys-uname (~> 1.0, >= 1.0.2)
40
+ cucumber-core (7.1.0)
41
+ cucumber-gherkin (~> 14.0, >= 14.0.1)
42
+ cucumber-messages (~> 12.2, >= 12.2.0)
43
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
44
+ cucumber-create-meta (1.0.0)
45
+ cucumber-messages (~> 12.2, >= 12.2.0)
46
+ sys-uname (~> 1.2, >= 1.2.1)
47
+ cucumber-cucumber-expressions (10.2.2)
48
+ cucumber-gherkin (14.2.0)
49
+ cucumber-messages (~> 12.4, >= 12.4.0)
50
+ cucumber-html-formatter (7.2.0)
51
+ cucumber-messages (~> 12.4, >= 12.4.0)
52
+ cucumber-messages (12.4.0)
53
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
54
+ cucumber-tag-expressions (2.0.4)
55
+ cucumber-wire (3.1.0)
56
+ cucumber-core (~> 7.1, >= 7.1.0)
57
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
58
+ cucumber-messages (~> 12.2, >= 12.2.0)
11
59
  diff-lcs (1.3)
60
+ ffi (1.13.1)
61
+ i18n (1.8.5)
62
+ concurrent-ruby (~> 1.0)
12
63
  image_size (2.0.2)
64
+ middleware (0.1.0)
65
+ minitest (5.14.1)
66
+ multi_test (0.1.2)
67
+ protobuf-cucumber (3.10.8)
68
+ activesupport (>= 3.2)
69
+ middleware
70
+ thor
71
+ thread_safe
13
72
  rake (12.3.3)
14
73
  review (3.2.0)
15
74
  image_size
16
75
  rouge
17
76
  rubyzip
18
- rouge (3.20.0)
77
+ rouge (3.21.0)
19
78
  rspec (3.9.0)
20
79
  rspec-core (~> 3.9.0)
21
80
  rspec-expectations (~> 3.9.0)
@@ -30,12 +89,19 @@ GEM
30
89
  rspec-support (~> 3.9.0)
31
90
  rspec-support (3.9.2)
32
91
  rubyzip (2.3.0)
92
+ sys-uname (1.2.1)
93
+ ffi (>= 1.0.0)
33
94
  thor (1.0.1)
95
+ thread_safe (0.3.6)
96
+ tzinfo (1.2.7)
97
+ thread_safe (~> 0.1)
98
+ zeitwerk (2.4.0)
34
99
 
35
100
  PLATFORMS
36
101
  ruby
37
102
 
38
103
  DEPENDENCIES
104
+ aruba (~> 1.0.2)
39
105
  rake (~> 12.0)
40
106
  review-retrovert!
41
107
  rspec (~> 3.0)
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  # ReVIEW::Retrovert
6
6
 
7
+ [Re:VIEW Starter](https://kauplan.org/reviewstarter/) Project convert to [Re:VIEW](https://reviewml.org/ja/) 3.X
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -22,7 +24,9 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ ```sh
28
+ review-retrovert convert /path/to/dir/review-starter/config.yml <output directory>
29
+ ```
26
30
 
27
31
  ## Development
28
32
 
@@ -34,10 +38,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
38
 
35
39
  Bug reports and pull requests are welcome on GitHub at https://github.com/srz-zumix/review-retrovert.
36
40
 
37
-
38
41
  ## Develop
39
42
 
40
- docker run -it --rm -v $(pwd)/../:/github vvakame/review:3.2 bash
43
+ docker run -it --rm -v $(pwd)/:/work -w /work vvakame/review:3.2 bash
41
44
 
42
45
  ## License
43
46
 
@@ -7,6 +7,8 @@ module ReVIEW
7
7
  desc "convert {review_starter_configfile} {outdir}", "convert Re:VIEW Starter project to Re:VIEW project"
8
8
  method_option "force", aliases: "f", desc: 'Force output', type: :boolean
9
9
  method_option "strict", desc: 'Only process files registered in the catalog', type: :boolean
10
+ method_option "table-br-replace", desc: '@<br>{} in table replace string', type: :string, default: ''
11
+ method_option "table-empty-replace", desc: 'empty cell(.) in table replace string', type: :string, default: ' '
10
12
  def convert(review_starter_configfile, outdir)
11
13
  Converter.execute(review_starter_configfile, outdir, options)
12
14
  end
@@ -9,6 +9,7 @@ module ReVIEW
9
9
 
10
10
  def initialize
11
11
  @basedir = nil
12
+ @srccontentsdir = nil
12
13
  @outimagedir = nil
13
14
  @logger = ReVIEW.logger
14
15
  @configs = YamlConfig.new
@@ -37,10 +38,9 @@ module ReVIEW
37
38
  end
38
39
 
39
40
  def copy_contents(outdir)
40
- contentdir = @config['contentdir']
41
- path = File.join(@basedir, contentdir)
42
- outpath = File.join(outdir, contentdir)
43
- FileUtils.mkdir_p(outpath)
41
+ path = File.join(@basedir, @srccontentsdir)
42
+ # outpath = File.join(outdir, srccontentsdir)
43
+ # FileUtils.mkdir_p(outpath)
44
44
  # FileUtils.cp_r(Dir.glob(File.join(path, '*.re')), outpath)
45
45
  FileUtils.cp_r(Dir.glob(File.join(path, '*.re')), outdir)
46
46
  end
@@ -52,8 +52,13 @@ module ReVIEW
52
52
  outpath = File.join(outdir, outimagedir)
53
53
  FileUtils.mkdir_p(outpath)
54
54
  image_ext = @config['image_ext']
55
+ srcroot = Pathname.new(srcpath)
55
56
  image_ext.each { |ext|
56
- FileUtils.cp_r(Dir.glob(File.join(srcpath, "**/*.#{ext}")), outpath)
57
+ Dir.glob(File.join(srcpath, "**/*.#{ext}")).each { |srcimg|
58
+ outimg = File.join(outpath, Pathname.new(srcimg).relative_path_from(srcroot))
59
+ FileUtils.makedirs(File.dirname(outimg))
60
+ FileUtils.cp(srcimg, outimg)
61
+ }
57
62
  }
58
63
  @configs.rewrite_yml('imagedir', outimagedir)
59
64
  end
@@ -64,8 +69,31 @@ module ReVIEW
64
69
  @configs.rewrite_yml('texstyle', '["reviewmacro"]')
65
70
  end
66
71
 
67
- def replace_inline_command(content, command, sub)
72
+ def replace_compatible_block_command_outline(content, command, new_command, option_count)
73
+ content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}")
74
+ end
75
+
76
+ def replace_compatible_block_command_to_outside(content, command, new_command, option_count, add_options="", new_body="")
77
+ body = new_body
78
+ body += '\n' unless body.empty?
79
+ content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>#{add_options}{\n#{new_body}//}\\k<inner>")
80
+ end
81
+
82
+ def replace_block_command_outline(content, command, new_command, use_option)
83
+ if use_option
84
+ content.gsub!(/^\/\/#{command}(?<option>\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}")
85
+ else
86
+ content.gsub!(/^\/\/#{command}(?<option>\[[^\r\n]*?\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}{\\k<inner>//}")
87
+ end
88
+ end
89
+
90
+ def delete_block_command_outer(content, command)
91
+ content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\])*{(?<inner>.*?)\/\/}\R/m, '\k<inner>')
92
+ end
68
93
 
94
+ def delete_block_command(content, command)
95
+ content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\])*{.*?\/\/}\R/m, '')
96
+ content.gsub!(/^\/\/#{command}(\[.*?\])*\s*\R/, '')
69
97
  end
70
98
 
71
99
  def delete_inline_command(content, command)
@@ -73,6 +101,156 @@ module ReVIEW
73
101
  content.gsub!(/@<#{command}>(?:(\$)|(?:({)|(\|)))((?:.*@<\w*>[\|${].*?[\|$}].*?|.*?)*)(?(1)(\$)|(?(2)(})|(\|)))/){"#{$4}"}
74
102
  end
75
103
 
104
+ def replace_inline_command(content, command, new_command)
105
+ content.gsub!(/@<#{command}>/, "@<#{new_command}>")
106
+ end
107
+
108
+ def replace_block_command_nested_boxed_article(content, box)
109
+ found = false
110
+ content.dup.scan(/(^\/\/#{box})(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)).*?[\r\n]+)/m) { |m|
111
+ matched = m[0..-1].join
112
+ inner = m[5]
113
+ im = inner.match(/^\/\/(\w+)((\[.*?\])*)([$|{])/)
114
+ unless im.nil?
115
+ inner_cmd = im[1]
116
+ inner_open = im[4]
117
+ inner_opts = im[2]
118
+ first_opt = inner_opts.match(/^\[(.*?)\]/)[1]
119
+
120
+ is_commentout = true
121
+ unless first_opt.empty?
122
+ if inner.match(/@<.*?>[$|{]#{first_opt}/)
123
+ is_commentout = false
124
+ end
125
+ end
126
+ cmd_begin = m[0..4].join
127
+ cmd_end = m[6..-1].join
128
+ # check other fence inner block (block command has fence??)
129
+ if inner_open == m[2..4].join
130
+ # if same fence then cmd_end == inner_end
131
+ if is_commentout
132
+ inner.gsub!(/(^\/\/(\w+\[.*?\])*#{inner_open})/, '#@#\1')
133
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#@##{cmd_end}")
134
+ else
135
+ imb = inner.match(/(\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/\w+\[#{first_opt}\](\[.*?\])*#{inner_open}.*)\R/m)
136
+ to_out_block = imb[1]
137
+ inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '')
138
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}")
139
+ end
140
+ else
141
+ close = inner_open == '{' ? '}' : inner_open
142
+ if is_commentout
143
+ inner.gsub!(/(^\/\/(\w+\[.*?\])*#{inner_open})(.*?)(^\/\/#{close})/m, '#@#\1\2#@#\3')
144
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}")
145
+ else
146
+ imb = inner.match(/\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/(\w+)\[#{first_opt}\](\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)))/m)
147
+ to_out_block = imb[0]
148
+ inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '')
149
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}")
150
+ end
151
+ end
152
+ found = true
153
+ end
154
+ }
155
+ if found
156
+ replace_block_command_nested_boxed_article(content, box)
157
+ end
158
+ end
159
+
160
+ def replace_block_command_nested_boxed_articles(content)
161
+ replace_block_command_nested_boxed_article(content, 'note')
162
+ replace_block_command_nested_boxed_article(content, 'memo')
163
+ replace_block_command_nested_boxed_article(content, 'tip')
164
+ replace_block_command_nested_boxed_article(content, 'info')
165
+ replace_block_command_nested_boxed_article(content, 'warning')
166
+ replace_block_command_nested_boxed_article(content, 'important')
167
+ replace_block_command_nested_boxed_article(content, 'caution')
168
+ replace_block_command_nested_boxed_article(content, 'notice')
169
+ end
170
+
171
+ def replace_block_commentout(content)
172
+ d = content.dup
173
+ d.gsub!(/(^\/\/sampleoutputbegin\[)(.*?)(\])(.*?)(^\/\/sampleoutputend)/m, '')
174
+ d.scan(/(^#@)(\++)(.*?)(^#@)(-+)/m) { |m|
175
+ matched = m[0..-1].join
176
+ inner = m[2]
177
+ inner.gsub!(/(^.)/, '#@#\1')
178
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#@##{m[1]}#{inner}#@##{m[4]}")
179
+ }
180
+ end
181
+
182
+ def replace_sampleoutput(content)
183
+ replace_block_commentout(content)
184
+ content.dup.scan(/(^\/\/sampleoutputbegin\[)(.*?)(\].*?\R)(.*?)(^\/\/sampleoutputend)/m) { |m|
185
+ matched = m[0..-1].join
186
+ sampleoutputbegin = m[0..2].join
187
+ sampleoutputend = m[4]
188
+ option = m[1]
189
+ inner = m[3]
190
+ # inner.gsub!(/^\/\//, '//@<nop>{}')
191
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{option}\n#@##{sampleoutputbegin}#{inner}#@##{sampleoutputend}")
192
+ }
193
+ end
194
+
195
+ def replace_auto_ids(content, command, require_option_count)
196
+ index = -1
197
+ content.gsub!(/^\/\/#{command}\[(|\?)\]/) { |s| index += 1; "//#{command}[starter_auto_id_#{command}_#{index}]" }
198
+ if require_option_count > 0
199
+ while !content.gsub!(/(^\/\/#{command}(\[[^\[\]]*?\]){0,#{require_option_count-1}})($|{)/, '\1[]\3').nil?
200
+ end
201
+ end
202
+ end
203
+
204
+ def remove_starter_refid(content)
205
+ # note - noteref
206
+ content.dup.scan(/(@<noteref>)(?:(\$)|(?:({)|(\|)))(.*?)(?(2)(\$)|(?(3)(})|(\|)))/) { |m|
207
+ matched = m[0..-1].join
208
+ ref = m[4]
209
+ n = content.match(/^\/\/note\[#{ref}\](\[.*?\])/)
210
+ unless n.nil?
211
+ content.gsub!(/#{Regexp.escape(matched)}/, n[1])
212
+ content.gsub!(/^\/\/note\[#{ref}\](\[.*?\])/, '//note\1')
213
+ else
214
+ # content.gsub!(/#{Regexp.escape(matched)}/, "noteref<#{ref}>")
215
+ end
216
+ }
217
+ end
218
+
219
+ def remove_starter_options(content)
220
+ # image border
221
+ content.gsub!(/(^\/\/image\[.*?\]\[.*?\]\[.*?)((,|)border=[^,\]]*)(.*?\])/, '\1\4')
222
+ # list lineno
223
+ content.gsub!(/(^\/\/list\[.*?\]\[.*?\]\[.*?)((,|)lineno=[^,\]]*)(.*?\])/, '\1\4')
224
+ end
225
+
226
+ def expand_nested_inline_command(content)
227
+ found = false
228
+ content.dup.scan(/(@<.*?>)(?:(\$)|(?:({)|(\|)))(.*?)(?(2)(\$)|(?(3)(})|(\|)))/) { |m|
229
+ matched = m.join
230
+ body = m[4]
231
+ im = body.match(/(.*)(@<.*?>)(?:(\$)|(?:({)|(\|)))(.*?)(?(3)(\$)|(?(4)(})|(\|)))(.*)/)
232
+ if im.nil?
233
+ im = body.match(/(.*)(@<.*?>)#{m[1..3].join}/)
234
+ unless im.nil?
235
+ outcmd_begin = m[0] + "$|{".gsub(m[1..3].join, '')
236
+ outcmd_end = "$|}".gsub(m[5..7].join, '')
237
+ rep = "#{outcmd_begin}#{body}#{outcmd_end}"
238
+ content.gsub!(matched, rep)
239
+ found = true
240
+ end
241
+ else
242
+ outcmd_begin = m[0..3].join
243
+ outcmd_end = m[5..7].join
244
+ rep = "#{outcmd_begin}#{im[1]}#{outcmd_end}#{im[2..9].join}#{outcmd_begin}#{im[-1]}#{outcmd_end}"
245
+ content.gsub!(matched, rep)
246
+ found = true
247
+ end
248
+ }
249
+ if found
250
+ expand_nested_inline_command(content)
251
+ end
252
+ end
253
+
76
254
  def copy_embedded_contents(outdir, content)
77
255
  content.scan(/\#@mapfile\((.*?)\)/).each do |filepath|
78
256
  srcpath = File.join(@basedir, filepath)
@@ -88,13 +266,70 @@ module ReVIEW
88
266
  def update_content(outdir, contentfile)
89
267
  info contentfile
90
268
  content = File.read(contentfile)
91
- content.gsub!(/(\/\/sideimage\[.*?\]\[.*?\])\[.*?\]/, '\1')
92
- content.gsub!(/\/\/sideimage/, '//image')
269
+ content.gsub!(/@<href>{(.*?)#.*?,(.*?)}/, '@<href>{\1,\2}')
93
270
  content.gsub!(/@<href>{(.*?)#.*?}/, '@<href>{\1}')
94
- while !content.gsub!(/(\/\/table.*)@<br>(.*?\/\/})/m, '\1\2').nil? do
271
+ # table 内の @ コマンドは不安定らしい
272
+ while !content.gsub!(/(\/\/table.*)@<br>{}(.*?\/\/})/m, "\\1#{@table_br_replace}\\2").nil? do
95
273
  end
96
- delete_inline_command(content , 'xsmall')
97
- delete_inline_command(content , 'weak')
274
+ # 空セルが2行になることがあるらしい
275
+ while !content.gsub!(/(\/\/table.*\s)\.(\s.*?\/\/})/m, "\\1#{@table_empty_replace}\\2").nil? do
276
+ end
277
+ # Re:VIEW Starter commands
278
+ replace_compatible_block_command_outline(content, 'terminal', 'cmd', 1)
279
+ replace_compatible_block_command_to_outside(content, 'sideimage', 'image', 1, '[]')
280
+ replace_block_command_outline(content, 'abstract', 'lead', true)
281
+ delete_block_command(content, 'needvspace')
282
+ delete_block_command(content, 'clearpage')
283
+ delete_block_command(content, 'flushright')
284
+ delete_block_command(content, 'centering')
285
+ delete_block_command(content, 'noindent')
286
+ delete_block_command(content, 'paragraphend')
287
+
288
+ replace_inline_command(content, 'secref', 'hd')
289
+ replace_inline_command(content, 'file', 'kw')
290
+ replace_inline_command(content, 'hlink', 'href')
291
+ replace_inline_command(content, 'B', 'strong')
292
+ delete_inline_command(content, 'userinput')
293
+ delete_inline_command(content, 'weak')
294
+ delete_inline_command(content, 'cursor')
295
+ # font size
296
+ delete_inline_command(content, 'small')
297
+ delete_inline_command(content, 'xsmall')
298
+ delete_inline_command(content, 'xxsmall')
299
+ delete_inline_command(content, 'large')
300
+ delete_inline_command(content, 'xlarge')
301
+ delete_inline_command(content, 'xxlarge')
302
+
303
+ # fixed lack of options
304
+ content.gsub!(/^\/\/list{/, '//list[][]{')
305
+
306
+ # special command
307
+ replace_sampleoutput(content)
308
+
309
+ # nested command
310
+ replace_block_command_nested_boxed_articles(content)
311
+
312
+ # empty ids
313
+ replace_auto_ids(content, 'list', 2)
314
+ replace_auto_ids(content, 'listnum', 2)
315
+
316
+ # remove starter extension
317
+ remove_starter_refid(content)
318
+ remove_starter_options(content)
319
+
320
+ # special charactor
321
+ content.gsub!('@<LaTeX>{}', 'LaTeX')
322
+ content.gsub!('@<TeX>{}', 'TeX')
323
+ content.gsub!('@<hearts>{}', '!HEART!')
324
+
325
+ # nop replace must be last step
326
+ content.gsub!('@<nop>$$', '@<b>$$')
327
+ content.gsub!('@<nop>||', '@<b>||')
328
+ content.gsub!('@<nop>{}', '@<b>{}')
329
+
330
+ # expand nested inline command
331
+ expand_nested_inline_command(content)
332
+
98
333
  File.write(contentfile, content)
99
334
  copy_embedded_contents(outdir, content)
100
335
  end
@@ -104,7 +339,8 @@ module ReVIEW
104
339
  files.each do |content|
105
340
  contentpath = File.join(contentdir, content)
106
341
  unless File.exist?(contentpath)
107
- srcpath = File.join(File.join(@basedir, @config['contentdir']), content)
342
+ srcpath = File.join(File.join(@basedir, @srccontentsdir), content)
343
+ # info srcpath
108
344
  if File.exist?(srcpath)
109
345
  FileUtils.cp(srcpath, contentdir)
110
346
  end
@@ -116,9 +352,8 @@ module ReVIEW
116
352
  def update_contents(outdir, options)
117
353
  yamlfile = @config['catalogfile']
118
354
  abspath = File.absolute_path(outdir)
119
- # contentdir = File.join(abspath, @config['contentdir'])
120
355
  contentdir = abspath
121
- info 'replace //sideimage to //image'
356
+ info 'replace starter block command'
122
357
  info 'replace starter inline command'
123
358
  if options['strict']
124
359
  catalog = ReVIEW::Catalog.new(File.open(File.join(abspath, yamlfile)))
@@ -127,8 +362,9 @@ module ReVIEW
127
362
  update_content_files(outdir, contentdir, catalog.appendix())
128
363
  update_content_files(outdir, contentdir, catalog.postdef())
129
364
  else
130
- copy_contents(outdir)
131
- update_content_files(outdir, contentdir, Dir.glob(File.join(abspath, '*.re')))
365
+ # copy_contents(outdir)
366
+ contentsfiles = Pathname.glob(File.join(File.join(@basedir, @srccontentsdir), '*.re')).map(&:basename)
367
+ update_content_files(outdir, contentdir, contentsfiles)
132
368
  end
133
369
  end
134
370
 
@@ -143,6 +379,7 @@ module ReVIEW
143
379
  @configs.open(yamlfile)
144
380
  @config = @configs.config
145
381
  @basedir = @configs.basedir
382
+ @srccontentsdir = @config['contentdir']
146
383
  end
147
384
 
148
385
  def create_initial_project(outdir, options)
@@ -152,6 +389,8 @@ module ReVIEW
152
389
  end
153
390
 
154
391
  def execute(yamlfile, outdir, options)
392
+ @table_br_replace = options['table-br-replace']
393
+ @table_empty_replace = options['table-empty-replace']
155
394
  load_config(yamlfile)
156
395
  create_initial_project(outdir, options)
157
396