review-retrovert 0.3.1 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/retrovert.yml +61 -0
  3. data/.gitignore +2 -2
  4. data/.ruby-version +1 -0
  5. data/Dockerfile +1 -1
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +82 -17
  8. data/README.md +6 -3
  9. data/lib/review/retrovert/cli.rb +4 -0
  10. data/lib/review/retrovert/converter.rb +375 -9
  11. data/lib/review/retrovert/version.rb +1 -1
  12. data/lib/review/retrovert/yamlconfig.rb +13 -1
  13. data/review-retrovert.gemspec +2 -2
  14. data/testdata/mybook/.gitignore +7 -0
  15. data/testdata/mybook/README.md +43 -0
  16. data/testdata/mybook/Rakefile +16 -0
  17. data/testdata/mybook/catalog.yml +33 -0
  18. data/testdata/mybook/config-starter.yml +139 -0
  19. data/testdata/mybook/config.yml +375 -0
  20. data/testdata/mybook/contents/00-preface.re +83 -0
  21. data/testdata/mybook/contents/01-install.re +272 -0
  22. data/testdata/mybook/contents/02-tutorial.re +1008 -0
  23. data/testdata/mybook/contents/03-syntax.re +2613 -0
  24. data/testdata/mybook/contents/04-customize.re +728 -0
  25. data/testdata/mybook/contents/05-faq.re +328 -0
  26. data/testdata/mybook/contents/06-bestpractice.re +971 -0
  27. data/testdata/mybook/contents/91-compare.re +18 -0
  28. data/testdata/mybook/contents/92-filelist.re +119 -0
  29. data/testdata/mybook/contents/93-background.re +267 -0
  30. data/testdata/mybook/contents/99-postface.re +38 -0
  31. data/testdata/mybook/css/normalize.css +349 -0
  32. data/testdata/mybook/css/webstyle.css +514 -0
  33. data/testdata/mybook/images/03-syntax/favicon-16x16.png +0 -0
  34. data/testdata/mybook/images/03-syntax/figure_heretop.png +0 -0
  35. data/testdata/mybook/images/03-syntax/tw-icon1.jpg +0 -0
  36. data/testdata/mybook/images/03-syntax/tw-icon2.jpg +0 -0
  37. data/testdata/mybook/images/03-syntax/tw-icon3.jpg +0 -0
  38. data/testdata/mybook/images/03-syntax/tw-icon4.jpg +0 -0
  39. data/testdata/mybook/images/04-customize/caption_pagebreak.png +0 -0
  40. data/testdata/mybook/images/04-customize/chaptitlepage_sample.png +0 -0
  41. data/testdata/mybook/images/05-faq/codeblock_rpadding1.png +0 -0
  42. data/testdata/mybook/images/05-faq/codeblock_rpadding2.png +0 -0
  43. data/testdata/mybook/images/06-bestpractice/figure_heretop.png +0 -0
  44. data/testdata/mybook/images/06-bestpractice/font_beramono.png +0 -0
  45. data/testdata/mybook/images/06-bestpractice/heading_design1.png +0 -0
  46. data/testdata/mybook/images/06-bestpractice/heading_design2.png +0 -0
  47. data/testdata/mybook/images/06-bestpractice/margin_book.png +0 -0
  48. data/testdata/mybook/images/06-bestpractice/multiline-title.png +0 -0
  49. data/testdata/mybook/images/06-bestpractice/preface_numbered.png +0 -0
  50. data/testdata/mybook/images/06-bestpractice/program_border.png +0 -0
  51. data/testdata/mybook/images/06-bestpractice/sechead_design_4.png +0 -0
  52. data/testdata/mybook/images/06-bestpractice/titlepage-samples.png +0 -0
  53. data/testdata/mybook/images/93-background/bug913.png +0 -0
  54. data/testdata/mybook/images/93-background/slide2.png +0 -0
  55. data/testdata/mybook/images/cover_a5.pdf +0 -0
  56. data/testdata/mybook/images/cover_b5.pdf +0 -0
  57. data/testdata/mybook/images/tw-icon.jpg +0 -0
  58. data/testdata/mybook/layouts/layout.epub.erb +29 -0
  59. data/testdata/mybook/layouts/layout.html5.erb +106 -0
  60. data/testdata/mybook/layouts/layout.tex.erb +546 -0
  61. data/testdata/mybook/lib/hooks/beforetexcompile.rb +55 -0
  62. data/testdata/mybook/lib/ruby/review-builder.rb +503 -0
  63. data/testdata/mybook/lib/ruby/review-cli.rb +58 -0
  64. data/testdata/mybook/lib/ruby/review-compiler.rb +523 -0
  65. data/testdata/mybook/lib/ruby/review-epubmaker.rb +606 -0
  66. data/testdata/mybook/lib/ruby/review-htmlbuilder.rb +661 -0
  67. data/testdata/mybook/lib/ruby/review-latexbuilder.rb +782 -0
  68. data/testdata/mybook/lib/ruby/review-maker.rb +235 -0
  69. data/testdata/mybook/lib/ruby/review-monkeypatch.rb +91 -0
  70. data/testdata/mybook/lib/ruby/review-pdfmaker.rb +468 -0
  71. data/testdata/mybook/lib/ruby/review-textbuilder.rb +36 -0
  72. data/testdata/mybook/lib/ruby/review-tocparser.rb +285 -0
  73. data/testdata/mybook/lib/ruby/review-webmaker.rb +433 -0
  74. data/testdata/mybook/lib/tasks/mytasks.rake +31 -0
  75. data/testdata/mybook/lib/tasks/review.rake +142 -0
  76. data/testdata/mybook/lib/tasks/review.rake.orig +72 -0
  77. data/testdata/mybook/lib/tasks/starter.rake +326 -0
  78. data/testdata/mybook/locale.yml +6 -0
  79. data/testdata/mybook/review-ext.rb +206 -0
  80. data/testdata/mybook/sty/jumoline.sty +310 -0
  81. data/testdata/mybook/sty/mycolophon.sty +81 -0
  82. data/testdata/mybook/sty/mystyle.sty +8 -0
  83. data/testdata/mybook/sty/mytextsize.sty +61 -0
  84. data/testdata/mybook/sty/mytitlepage.sty +103 -0
  85. data/testdata/mybook/sty/reviewmacro.sty +60 -0
  86. data/testdata/mybook/sty/starter-codeblock.sty +332 -0
  87. data/testdata/mybook/sty/starter-color.sty +79 -0
  88. data/testdata/mybook/sty/starter-font.sty +112 -0
  89. data/testdata/mybook/sty/starter-heading.sty +514 -0
  90. data/testdata/mybook/sty/starter-note.sty +127 -0
  91. data/testdata/mybook/sty/starter-section.sty +262 -0
  92. data/testdata/mybook/sty/starter-toc.sty +72 -0
  93. data/testdata/mybook/sty/starter.sty +554 -0
  94. data/testdata/mybook/style.css +597 -0
  95. metadata +100 -10
  96. data/.travis.yml +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9727e90e617a35a08cdbae8916f5e4cb388950fd654bb82c4c2363764850c82
4
- data.tar.gz: 964388bf53220b9f6731bf60d00a1d0a27398e774f2f010c7ae2a2d008cdefa9
3
+ metadata.gz: 978ce194146ec4de6a7ece5ac4ba182e6eff60670836f952f22578a25ec10a9e
4
+ data.tar.gz: 6889acc0183d72d30b7f87fdbd0fc4e5bd986b350d4c7fae8ba8e5895e7a476b
5
5
  SHA512:
6
- metadata.gz: 370fcb244a1037f52506ae4707288957553270acc96b005f02d97d8c6dd188753e3297244794b732cffd16406536879111f5787a0aa9ad199890979880c40112
7
- data.tar.gz: 3dbc8982c6c904ff2e5deda893e3daa41cb6f9873c05dacb112339b4b3fca80732d122a8dd0978e05347d11dbefa9f825dc3f7add8a57e6ff0076911b9837601
6
+ metadata.gz: 2246191d2e227e1c8a4d322a9d9ec4f84e85904285e4952cabc6df9a87f89f1eab761edda301aca5e950494aa341e8e9ebeb4675118450082d841eea909c982e
7
+ data.tar.gz: c8f3757ef2da91d51c5fed0954e5ef4c710bbaee3fe014e728ae16d5f3a47bc10861910dc2d121a085e8ba14a7380ccf02e664f81ee64c582b6ba3b21e750078
@@ -0,0 +1,61 @@
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
+ strategy:
12
+ matrix:
13
+ review-version: [ "3.2", "4.2", "5.0" ]
14
+ fail-fast: false
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+ - run: |
21
+ rm -f Gemfile.lock
22
+ cp Gemfile Gemfile-${{ matrix.review-version }}
23
+ echo 'gem "review", "${{ matrix.review-version }}"' >> Gemfile-${{ matrix.review-version }}
24
+ cat Gemfile-${{ matrix.review-version }}
25
+ echo "BUNDLE_GEMFILE=Gemfile-${{ matrix.review-version }}" >> $GITHUB_ENV
26
+ - run: bundle install --gemfile=Gemfile-${{ matrix.review-version }}
27
+ # spec
28
+ - name: spec
29
+ run: bundle exec rake spec
30
+ # convert
31
+ - name: convert
32
+ run: bundle exec review-retrovert convert testdata/mybook/config.yml tmp -f
33
+ # build
34
+ # - name: review build
35
+ # uses: ${{ matrix.uses }}
36
+ # with:
37
+ # entrypoint: bash
38
+ # args: -c "cd tmp; rake preproc all"
39
+ # docker login
40
+ - name: Login to DockerHub
41
+ uses: docker/login-action@v1
42
+ with:
43
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
44
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
45
+ - name: build html
46
+ run: |
47
+ docker run --rm -v "$(pwd)/tmp":/work -w /work vvakame/review:${{ matrix.review-version }} rake preproc html
48
+ - name: build pdf
49
+ run: |
50
+ docker run --rm -v "$(pwd)/tmp":/work -w /work vvakame/review:${{ matrix.review-version }} rake preproc pdf
51
+ # artifacts
52
+ - name: artifacts
53
+ uses: actions/upload-artifact@v1
54
+ with:
55
+ name: mybook
56
+ path: tmp/mybook.pdf
57
+ # - name: artifacts
58
+ # uses: actions/upload-artifact@v1
59
+ # with:
60
+ # name: mybook
61
+ # 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/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM vvakame/review:3.2
1
+ FROM vvakame/review:5.0
2
2
 
3
3
  RUN gem install review-retrovert
4
4
 
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,41 +1,106 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- review-retrovert (0.3.1)
5
- review (>= 3.2.0, < 4.0)
4
+ review-retrovert (0.9.3)
5
+ review (>= 3.2.0)
6
6
  thor
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- diff-lcs (1.3)
12
- image_size (2.0.2)
11
+ activesupport (6.1.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ aruba (1.0.4)
18
+ childprocess (>= 2.0, < 5.0)
19
+ contracts (~> 0.16.0)
20
+ cucumber (>= 2.4, < 6.0)
21
+ rspec-expectations (~> 3.4)
22
+ thor (~> 1.0)
23
+ builder (3.2.4)
24
+ childprocess (4.0.0)
25
+ concurrent-ruby (1.1.7)
26
+ contracts (0.16.0)
27
+ cucumber (5.2.0)
28
+ builder (~> 3.2, >= 3.2.4)
29
+ cucumber-core (~> 8.0, >= 8.0.1)
30
+ cucumber-create-meta (~> 2.0, >= 2.0.2)
31
+ cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
32
+ cucumber-gherkin (~> 15.0, >= 15.0.2)
33
+ cucumber-html-formatter (~> 9.0, >= 9.0.0)
34
+ cucumber-messages (~> 13.1, >= 13.1.0)
35
+ cucumber-wire (~> 4.0, >= 4.0.1)
36
+ diff-lcs (~> 1.4, >= 1.4.4)
37
+ multi_test (~> 0.1, >= 0.1.2)
38
+ sys-uname (~> 1.2, >= 1.2.1)
39
+ cucumber-core (8.0.1)
40
+ cucumber-gherkin (~> 15.0, >= 15.0.2)
41
+ cucumber-messages (~> 13.0, >= 13.0.1)
42
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
43
+ cucumber-create-meta (2.0.4)
44
+ cucumber-messages (~> 13.1, >= 13.1.0)
45
+ sys-uname (~> 1.2, >= 1.2.1)
46
+ cucumber-cucumber-expressions (10.3.0)
47
+ cucumber-gherkin (15.0.2)
48
+ cucumber-messages (~> 13.0, >= 13.0.1)
49
+ cucumber-html-formatter (9.0.0)
50
+ cucumber-messages (~> 13.0, >= 13.0.1)
51
+ cucumber-messages (13.2.1)
52
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
53
+ cucumber-tag-expressions (2.0.4)
54
+ cucumber-wire (4.0.1)
55
+ cucumber-core (~> 8.0, >= 8.0.1)
56
+ cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
57
+ cucumber-messages (~> 13.0, >= 13.0.1)
58
+ diff-lcs (1.4.4)
59
+ ffi (1.14.2)
60
+ i18n (1.8.7)
61
+ concurrent-ruby (~> 1.0)
62
+ image_size (2.1.0)
63
+ middleware (0.1.0)
64
+ minitest (5.14.3)
65
+ multi_test (0.1.2)
66
+ protobuf-cucumber (3.10.8)
67
+ activesupport (>= 3.2)
68
+ middleware
69
+ thor
70
+ thread_safe
13
71
  rake (12.3.3)
14
- review (3.2.0)
72
+ review (5.0.0)
15
73
  image_size
16
74
  rouge
17
75
  rubyzip
18
- rouge (3.20.0)
19
- rspec (3.9.0)
20
- rspec-core (~> 3.9.0)
21
- rspec-expectations (~> 3.9.0)
22
- rspec-mocks (~> 3.9.0)
23
- rspec-core (3.9.1)
24
- rspec-support (~> 3.9.1)
25
- rspec-expectations (3.9.1)
76
+ rouge (3.26.0)
77
+ rspec (3.10.0)
78
+ rspec-core (~> 3.10.0)
79
+ rspec-expectations (~> 3.10.0)
80
+ rspec-mocks (~> 3.10.0)
81
+ rspec-core (3.10.1)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-expectations (3.10.1)
26
84
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.9.0)
28
- rspec-mocks (3.9.1)
85
+ rspec-support (~> 3.10.0)
86
+ rspec-mocks (3.10.1)
29
87
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.9.0)
31
- rspec-support (3.9.2)
88
+ rspec-support (~> 3.10.0)
89
+ rspec-support (3.10.1)
32
90
  rubyzip (2.3.0)
91
+ sys-uname (1.2.2)
92
+ ffi (~> 1.1)
33
93
  thor (1.0.1)
94
+ thread_safe (0.3.6)
95
+ tzinfo (2.0.4)
96
+ concurrent-ruby (~> 1.0)
97
+ zeitwerk (2.4.2)
34
98
 
35
99
  PLATFORMS
36
100
  ruby
37
101
 
38
102
  DEPENDENCIES
103
+ aruba (~> 1.0.2)
39
104
  rake (~> 12.0)
40
105
  review-retrovert!
41
106
  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,10 @@ 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 "preproc", desc: 'Execute preproc after conversion', type: :boolean
11
+ method_option "tabwidth", desc: 'Preproc tabwidth option value', type: :numeric, default: 0
12
+ method_option "table-br-replace", desc: '@<br>{} in table replace string', type: :string, default: ''
13
+ method_option "table-empty-replace", desc: 'empty cell(.) in table replace string', type: :string, default: ' '
10
14
  def convert(review_starter_configfile, outdir)
11
15
  Converter.execute(review_starter_configfile, outdir, options)
12
16
  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
@@ -62,10 +67,40 @@ module ReVIEW
62
67
  @configs.rewrite_yml('contentdir', '.')
63
68
  @configs.rewrite_yml('hook_beforetexcompile', 'null')
64
69
  @configs.rewrite_yml('texstyle', '["reviewmacro"]')
70
+ @configs.rewrite_yml('chapterlink', 'null')
71
+ pagesize = @config['starter']['pagesize'].downcase
72
+ @configs.rewrite_yml_array('texdocumentclass', "[\"review-jsbook\", \"media=print,paper=#{pagesize}\"]")
65
73
  end
66
74
 
67
- def replace_inline_command(content, command, sub)
75
+ def replace_compatible_block_command_outline(content, command, new_command, option_count)
76
+ if option_count > 0
77
+ content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}")
78
+ else
79
+ content.gsub!(/^\/\/#{command}(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}{\\k<inner>//}")
80
+ end
81
+ end
68
82
 
83
+ def replace_compatible_block_command_to_outside(content, command, new_command, option_count, add_options="", new_body="")
84
+ body = new_body
85
+ body += '\n' unless body.empty?
86
+ content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>#{add_options}{\n#{new_body}//}\\k<inner>")
87
+ end
88
+
89
+ def replace_block_command_outline(content, command, new_command, use_option)
90
+ if use_option
91
+ content.gsub!(/^\/\/#{command}(?<option>\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}")
92
+ else
93
+ content.gsub!(/^\/\/#{command}(?<option>\[[^\r\n]*?\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}{\\k<inner>//}")
94
+ end
95
+ end
96
+
97
+ def delete_block_command_outer(content, command)
98
+ content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\])*{(?<inner>.*?)\/\/}\R/m, '\k<inner>')
99
+ end
100
+
101
+ def delete_block_command(content, command)
102
+ content.gsub!(/^\/\/#{command}(\[[^\r\n]*?\])*{.*?\/\/}\R/m, '')
103
+ content.gsub!(/^\/\/#{command}(\[.*?\])*\s*\R/, '')
69
104
  end
70
105
 
71
106
  def delete_inline_command(content, command)
@@ -73,6 +108,185 @@ module ReVIEW
73
108
  content.gsub!(/@<#{command}>(?:(\$)|(?:({)|(\|)))((?:.*@<\w*>[\|${].*?[\|$}].*?|.*?)*)(?(1)(\$)|(?(2)(})|(\|)))/){"#{$4}"}
74
109
  end
75
110
 
111
+ def replace_inline_command(content, command, new_command)
112
+ content.gsub!(/@<#{command}>/, "@<#{new_command}>")
113
+ end
114
+
115
+ def replace_block_command_nested_boxed_article_i(content, box, depth)
116
+ found = false
117
+ content.dup.scan(/(^\/\/#{box})(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)).*?[\r\n]+)/m) { |m|
118
+ matched = m[0..-1].join
119
+ inner = m[5]
120
+ # info depth
121
+ im = inner.match(/^\/\/(\w+)((\[.*?\])*)([$|{])/)
122
+ unless im.nil?
123
+ inner_cmd = im[1]
124
+ inner_open = im[4]
125
+ inner_opts = im[2]
126
+ first_opt_m = inner_opts.match(/^\[(.*?)\]/)
127
+ first_opt = ""
128
+
129
+ # is_commentout = false
130
+ is_commentout = true
131
+ if first_opt_m
132
+ first_opt_v = first_opt_m[1]
133
+ unless first_opt_v.empty?
134
+ if inner.match(/@<.*?>[$|{]#{first_opt}/)
135
+ is_commentout = false
136
+ first_opt = "\\[#{first_opt_v}\\]"
137
+ end
138
+ end
139
+ end
140
+ cmd_begin = m[0..4].join
141
+ cmd_end = m[6..-1].join
142
+ # check other fence inner block (block command has fence??)
143
+ if inner_open == m[2..4].join
144
+ # if same fence then cmd_end == inner_end
145
+ if is_commentout
146
+ inner.gsub!(/(^\/\/(\w+(\[.*?\]|))*#{inner_open})/, '#@#\1')
147
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#@##{cmd_end}")
148
+ else
149
+ imb = inner.match(/(\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/#{inner_cmd}#{first_opt}(\[.*?\])*#{inner_open}.*)\R/m)
150
+ to_out_block = imb[1]
151
+ inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '')
152
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}")
153
+ end
154
+ else
155
+ close = inner_open == '{' ? '}' : inner_open
156
+ if is_commentout
157
+ inner.gsub!(/(^\/\/(\w+(\[.*?\]|))*#{inner_open})(.*?)(^\/\/#{close})/m, '#@#\1\2#@#\3')
158
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}")
159
+ else
160
+ imb = inner.match(/\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/(#{inner_cmd})#{first_opt}(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)))/m)
161
+ to_out_block = imb[0]
162
+ inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '')
163
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}")
164
+ end
165
+ end
166
+ found = true
167
+ end
168
+ }
169
+ if found
170
+ replace_block_command_nested_boxed_article_i(content, box, depth+1)
171
+ end
172
+ end
173
+
174
+ def replace_block_command_nested_boxed_article(content, box)
175
+ replace_block_command_nested_boxed_article_i(content, box, 0)
176
+ end
177
+
178
+ def replace_block_command_nested_boxed_articles(content)
179
+ unless Gem::Version.new(ReVIEW::VERSION) >= Gem::Version.new('5.0.0')
180
+ replace_block_command_nested_boxed_article(content, 'note')
181
+ replace_block_command_nested_boxed_article(content, 'memo')
182
+ replace_block_command_nested_boxed_article(content, 'tip')
183
+ replace_block_command_nested_boxed_article(content, 'info')
184
+ replace_block_command_nested_boxed_article(content, 'warning')
185
+ replace_block_command_nested_boxed_article(content, 'important')
186
+ replace_block_command_nested_boxed_article(content, 'caution')
187
+ replace_block_command_nested_boxed_article(content, 'notice')
188
+ end
189
+ end
190
+
191
+ def replace_block_commentout(content)
192
+ d = content.dup
193
+ d.scan(/(^#@)(\++)(.*?)(^#@)(-+)/m) { |m|
194
+ matched = m[0..-1].join
195
+ inner = m[2]
196
+ inner.gsub!(/(^.)/, '#@#\1')
197
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#@##{m[1]}#{inner}#@##{m[4]}")
198
+ }
199
+ end
200
+
201
+ def replace_block_commentout_without_sampleout(content)
202
+ d = content.dup
203
+ d.gsub!(/(^\/\/sampleoutputbegin\[)(.*?)(\])(.*?)(^\/\/sampleoutputend)/m, '')
204
+ d.scan(/(^#@)(\++)(.*?)(^#@)(-+)/m) { |m|
205
+ matched = m[0..-1].join
206
+ inner = m[2]
207
+ inner.gsub!(/(^.)/, '#@#\1')
208
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#@##{m[1]}#{inner}#@##{m[4]}")
209
+ }
210
+ end
211
+
212
+ def replace_sampleoutput(content)
213
+ # replace_block_commentout_without_sampleout(content)
214
+ content.dup.scan(/(^\/\/sampleoutputbegin\[)(.*?)(\].*?\R)(.*?)(^\/\/sampleoutputend)/m) { |m|
215
+ matched = m[0..-1].join
216
+ sampleoutputbegin = m[0..2].join
217
+ sampleoutputend = m[4]
218
+ option = m[1]
219
+ inner = m[3]
220
+ # inner.gsub!(/^\/\//, '//@<nop>{}')
221
+ content.gsub!(/#{Regexp.escape(matched)}/m, "#{option}\n#@##{sampleoutputbegin}#{inner}#@##{sampleoutputend}")
222
+ }
223
+ end
224
+
225
+ def replace_auto_ids(content, command, require_option_count)
226
+ index = -1
227
+ content.gsub!(/^\/\/#{command}\[(|\?)\]/) { |s| index += 1; "//#{command}[starter_auto_id_#{command}_#{index}]" }
228
+ if require_option_count > 0
229
+ while !content.gsub!(/(^\/\/#{command}(\[[^\[\]]*?\]){0,#{require_option_count-1}})($|{)/, '\1[]\3').nil?
230
+ end
231
+ end
232
+ end
233
+
234
+ def fix_deprecated_list(content)
235
+ if Gem::Version.new(ReVIEW::VERSION) >= Gem::Version.new('4.0.0')
236
+ content.gsub!(/^: (.*)/, ' : \1')
237
+ end
238
+ end
239
+
240
+ def remove_starter_refid(content)
241
+ # note - noteref
242
+ content.dup.scan(/(@<noteref>)(?:(\$)|(?:({)|(\|)))(.*?)(?(2)(\$)|(?(3)(})|(\|)))/) { |m|
243
+ matched = m[0..-1].join
244
+ ref = m[4]
245
+ n = content.match(/^\/\/note\[#{ref}\](\[.*?\])/)
246
+ unless n.nil?
247
+ content.gsub!(/#{Regexp.escape(matched)}/, n[1])
248
+ content.gsub!(/^\/\/note\[#{ref}\](\[.*?\])/, '//note\1')
249
+ else
250
+ # content.gsub!(/#{Regexp.escape(matched)}/, "noteref<#{ref}>")
251
+ end
252
+ }
253
+ end
254
+
255
+ def remove_starter_options(content)
256
+ # image border
257
+ content.gsub!(/(^\/\/image\[.*?\]\[.*?\]\[.*?)((,|)border=[^,\]]*)(.*?\])/, '\1\4')
258
+ # list lineno
259
+ content.gsub!(/(^\/\/list\[.*?\]\[.*?\]\[.*?)((,|)lineno=[^,\]]*)(.*?\])/, '\1\4')
260
+ end
261
+
262
+ def expand_nested_inline_command(content)
263
+ found = false
264
+ content.dup.scan(/(@<.*?>)(?:(\$)|(?:({)|(\|)))(.*?)(?(2)(\$)|(?(3)(})|(\|)))/) { |m|
265
+ matched = m.join
266
+ body = m[4]
267
+ im = body.match(/(.*)(@<.*?>)(?:(\$)|(?:({)|(\|)))(.*?)(?(3)(\$)|(?(4)(})|(\|)))(.*)/)
268
+ if im.nil?
269
+ im = body.match(/(.*)(@<.*?>)#{m[1..3].join}/)
270
+ unless im.nil?
271
+ outcmd_begin = m[0] + "$|{".gsub(m[1..3].join, '')
272
+ outcmd_end = "$|}".gsub(m[5..7].join, '')
273
+ rep = "#{outcmd_begin}#{body}#{outcmd_end}"
274
+ content.gsub!(matched, rep)
275
+ found = true
276
+ end
277
+ else
278
+ outcmd_begin = m[0..3].join
279
+ outcmd_end = m[5..7].join
280
+ rep = "#{outcmd_begin}#{im[1]}#{outcmd_end}#{im[2..9].join}#{outcmd_begin}#{im[-1]}#{outcmd_end}"
281
+ content.gsub!(matched, rep)
282
+ found = true
283
+ end
284
+ }
285
+ if found
286
+ expand_nested_inline_command(content)
287
+ end
288
+ end
289
+
76
290
  def copy_embedded_contents(outdir, content)
77
291
  content.scan(/\#@mapfile\((.*?)\)/).each do |filepath|
78
292
  srcpath = File.join(@basedir, filepath)
@@ -85,16 +299,119 @@ module ReVIEW
85
299
  end
86
300
  end
87
301
 
302
+ def add_linkurl_footnote(content)
303
+ urls = {}
304
+ content.dup.scan(/(^.*)(@<href>{)(.*?)(,)(.*?)(})(.*)$/) { |m|
305
+ unless m[0].match(/^#@#/)
306
+ matched = m.join
307
+ prev = m[0]
308
+ url = m[2]
309
+ text = m[4]
310
+ post = m[6]
311
+ id = "link_auto_footnote#{urls.length}"
312
+ urls[id] = url
313
+ content.sub!(/#{Regexp.escape(matched)}$/, "#{prev}@<href>{#{url},#{text}} @<fn>{#{id}} #{post}")
314
+ end
315
+ }
316
+
317
+ urls.each { |k,v|
318
+ content.sub!(/(@<href>{#{v},.*?} @<fn>{#{k}}.*?\R\R)/m, "\\1//footnote[#{k}][#{v}]\n")
319
+ }
320
+
321
+ urls.each { |k,v|
322
+ unless content.match(/\/\/footnote\[#{k}\]\[#{v}\]/)
323
+ content << "//footnote[#{k}][#{v}]\n"
324
+ end
325
+ }
326
+ end
327
+
88
328
  def update_content(outdir, contentfile)
89
329
  info contentfile
90
330
  content = File.read(contentfile)
91
- content.gsub!(/(\/\/sideimage\[.*?\]\[.*?\])\[.*?\]/, '\1')
92
- content.gsub!(/\/\/sideimage/, '//image')
331
+ content.gsub!(/@<href>{(.*?)#.*?,(.*?)}/, '@<href>{\1,\2}')
93
332
  content.gsub!(/@<href>{(.*?)#.*?}/, '@<href>{\1}')
94
- while !content.gsub!(/(\/\/table.*)@<br>(.*?\/\/})/m, '\1\2').nil? do
333
+ linkurl_footnote = @config['starter']['linkurl_footnote']
334
+ # table 内の @ コマンドは不安定らしい
335
+ while !content.gsub!(/(\/\/table.*)@<br>{}(.*?\/\/})/m, "\\1#{@table_br_replace}\\2").nil? do
336
+ end
337
+ # 空セルが2行になることがあるらしい
338
+ while !content.gsub!(/(\/\/table.*\s)\.(\s.*?\/\/})/m, "\\1#{@table_empty_replace}\\2").nil? do
339
+ end
340
+ # Re:VIEW Starter commands
341
+ replace_compatible_block_command_outline(content, 'terminal', 'cmd', 1)
342
+ replace_compatible_block_command_outline(content, 'cmd', 'cmd', 0)
343
+ replace_compatible_block_command_to_outside(content, 'sideimage', 'image', 1, '[]')
344
+ replace_block_command_outline(content, 'abstract', 'lead', true)
345
+ delete_block_command(content, 'needvspace')
346
+ delete_block_command(content, 'clearpage')
347
+ delete_block_command(content, 'flushright')
348
+ delete_block_command(content, 'centering')
349
+ delete_block_command(content, 'noindent')
350
+ delete_block_command(content, 'paragraphend')
351
+
352
+ replace_inline_command(content, 'secref', 'hd')
353
+ replace_inline_command(content, 'file', 'kw')
354
+ replace_inline_command(content, 'hlink', 'href')
355
+ replace_inline_command(content, 'B', 'strong')
356
+ delete_inline_command(content, 'userinput')
357
+ delete_inline_command(content, 'weak')
358
+ delete_inline_command(content, 'cursor')
359
+ # font size
360
+ delete_inline_command(content, 'small')
361
+ delete_inline_command(content, 'xsmall')
362
+ delete_inline_command(content, 'xxsmall')
363
+ delete_inline_command(content, 'large')
364
+ delete_inline_command(content, 'xlarge')
365
+ delete_inline_command(content, 'xxlarge')
366
+
367
+ # fixed lack of options
368
+ content.gsub!(/^\/\/list{/, '//list[][]{')
369
+
370
+ if Gem::Version.new(ReVIEW::VERSION) >= Gem::Version.new('4.0.0')
371
+ # empty caption is not allow
372
+ content.gsub!(/^\/\/image\[(.*)\]\[\]{/, '//image[\1][ ]{')
95
373
  end
96
- delete_inline_command(content , 'xsmall')
97
- delete_inline_command(content , 'weak')
374
+
375
+ # special command
376
+ replace_sampleoutput(content)
377
+
378
+ if linkurl_footnote
379
+ add_linkurl_footnote(content)
380
+ end
381
+
382
+ # # br to blankline
383
+ # content.gsub!(/(.*)@<br>{}(.*)/, '\1\n//blankline\n\2')
384
+
385
+ # nested command
386
+ replace_block_command_nested_boxed_articles(content)
387
+
388
+ # empty ids
389
+ replace_auto_ids(content, 'list', 2)
390
+ replace_auto_ids(content, 'listnum', 2)
391
+
392
+ # remove starter extension
393
+ remove_starter_refid(content)
394
+ remove_starter_options(content)
395
+
396
+ # replace block comment
397
+ replace_block_commentout(content)
398
+
399
+ # special charactor
400
+ content.gsub!('@<LaTeX>{}', 'LaTeX')
401
+ content.gsub!('@<TeX>{}', 'TeX')
402
+ content.gsub!('@<hearts>{}', '!HEART!')
403
+
404
+ # nop replace must be last step
405
+ content.gsub!('@<nop>$$', '@<b>$$')
406
+ content.gsub!('@<nop>||', '@<b>||')
407
+ content.gsub!('@<nop>{}', '@<b>{}')
408
+
409
+ # expand nested inline command
410
+ expand_nested_inline_command(content)
411
+
412
+ # fix deprecated
413
+ fix_deprecated_list(content)
414
+
98
415
  File.write(contentfile, content)
99
416
  copy_embedded_contents(outdir, content)
100
417
  end
@@ -118,7 +435,7 @@ module ReVIEW
118
435
  yamlfile = @config['catalogfile']
119
436
  abspath = File.absolute_path(outdir)
120
437
  contentdir = abspath
121
- info 'replace //sideimage to //image'
438
+ info 'replace starter block command'
122
439
  info 'replace starter inline command'
123
440
  if options['strict']
124
441
  catalog = ReVIEW::Catalog.new(File.open(File.join(abspath, yamlfile)))
@@ -133,6 +450,45 @@ module ReVIEW
133
450
  end
134
451
  end
135
452
 
453
+ def preproc_content_files(outdir, pp, contentdir, contentfiles)
454
+ files = contentfiles.is_a?(String) ? contentfiles.split(/\R/) : contentfiles
455
+ files.each do |content|
456
+ contentpath = File.join(contentdir, content)
457
+ if File.exist?(contentpath)
458
+ info "preproc #{contentpath}"
459
+ buf = StringIO.new
460
+ pwd = Dir.pwd
461
+ Dir.chdir(outdir)
462
+ File.open(contentpath) { |f| pp.process(f, buf) }
463
+ Dir.chdir(pwd)
464
+ content = buf.string
465
+ content.gsub!(/^#[@]map.*$/, '')
466
+ File.write(contentpath, content)
467
+ end
468
+ end
469
+ end
470
+
471
+ def preproc_contents(outdir, options)
472
+ yamlfile = @config['catalogfile']
473
+ abspath = File.absolute_path(outdir)
474
+ contentdir = abspath
475
+ param = {}
476
+ param['tabwidth'] = options['tabwidth'].to_i
477
+ pp = ReVIEW::Preprocessor.new(ReVIEW::Repository.new(param), param)
478
+
479
+ if options['strict']
480
+ catalog = ReVIEW::Catalog.new(File.open(File.join(abspath, yamlfile)))
481
+ preproc_content_files(outdir, pp, contentdir, catalog.predef())
482
+ preproc_content_files(outdir, pp, contentdir, catalog.chaps())
483
+ preproc_content_files(outdir, pp, contentdir, catalog.appendix())
484
+ preproc_content_files(outdir, pp, contentdir, catalog.postdef())
485
+ else
486
+ # copy_contents(outdir)
487
+ contentsfiles = Pathname.glob(File.join(File.join(@basedir, @srccontentsdir), '*.re')).map(&:basename)
488
+ preproc_content_files(outdir, pp, contentdir, contentsfiles)
489
+ end
490
+ end
491
+
136
492
  def clean_initial_project(outdir)
137
493
  FileUtils.rm(File.join(outdir, 'config.yml'))
138
494
  FileUtils.rm(File.join(outdir, 'catalog.yml'))
@@ -154,6 +510,8 @@ module ReVIEW
154
510
  end
155
511
 
156
512
  def execute(yamlfile, outdir, options)
513
+ @table_br_replace = options['table-br-replace']
514
+ @table_empty_replace = options['table-empty-replace']
157
515
  load_config(yamlfile)
158
516
  create_initial_project(outdir, options)
159
517
 
@@ -168,8 +526,16 @@ module ReVIEW
168
526
  updater = ReVIEW::Update.new
169
527
  updater.force = true
170
528
  # updater.backup = false
171
- updater.execute()
529
+ begin
530
+ updater.execute()
531
+ rescue
532
+ end
172
533
  Dir.chdir(pwd)
534
+
535
+ if options['preproc']
536
+ info 'preproc'
537
+ preproc_contents(outdir, options)
538
+ end
173
539
  end
174
540
 
175
541
  def self.execute(yamlfile, outdir, options)