review-retrovert 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9311aa0fa85bd42652cbbe163b02383bb3e3ce8b82d5c10f1d85af48ecda098
4
- data.tar.gz: cac37e6eae36803b96a0f009695ffe480a7fafe4642a1bb45a44a4bcc1eb948b
3
+ metadata.gz: fdd00a05ee2fe184542575f75ff8b5f7541ea11ead119c28b1b00e00d38aeab8
4
+ data.tar.gz: 6a1dcf4eedabf43d6be0b8bf7814dc11d30d8798730a95e33ed6a95cda59173d
5
5
  SHA512:
6
- metadata.gz: 506fd1726a38d677b12c6641ba1f77330c332c9ec75d9d18427cedc8647ec319762df7025b8bcc65458e7bac9921fd62b6c3e7f3d6faf0447c5ad15a486ed2a9
7
- data.tar.gz: 21dabf3b90b0d6f93183d7e48aa7a3b32614b37edc078f6c538c6e8b810fc5c5f4ae7577ca10d9f6a45cc8732867d2e12f558f7ff5d1fb4fb97ddefe547c80fa
6
+ metadata.gz: 4f3748ae4c99d94ecb773de86501b720712f25381061055d42e12186f795775ad0a359e7c901b089fa804f82e9fb3d8506a17aeb693d51d14138a80a5b3a8256
7
+ data.tar.gz: 7126a6536e53cceb34e41c9b606d6974b336bd6afb8d6391a279db5ba16ba3b3939aea4b9efcda8a51c0a2221ef0f1226aa4849625e90cd8e25a2e5900d2299f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- review-retrovert (0.3.4)
4
+ review-retrovert (0.9.2)
5
5
  review (>= 3.2.0, < 4.0)
6
6
  thor
7
7
 
@@ -60,7 +60,7 @@ GEM
60
60
  ffi (1.13.1)
61
61
  i18n (1.8.5)
62
62
  concurrent-ruby (~> 1.0)
63
- image_size (2.0.2)
63
+ image_size (2.1.0)
64
64
  middleware (0.1.0)
65
65
  minitest (5.14.1)
66
66
  multi_test (0.1.2)
@@ -74,7 +74,7 @@ GEM
74
74
  image_size
75
75
  rouge
76
76
  rubyzip
77
- rouge (3.21.0)
77
+ rouge (3.26.0)
78
78
  rspec (3.9.0)
79
79
  rspec-core (~> 3.9.0)
80
80
  rspec-expectations (~> 3.9.0)
@@ -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 "preproc", desc: 'Execute preproc after conversion', type: :boolean
11
+ method_option "tabwidth", desc: 'Preproc tabwidth option value', type: :numeric, default: 0
10
12
  method_option "table-br-replace", desc: '@<br>{} in table replace string', type: :string, default: ''
11
13
  method_option "table-empty-replace", desc: 'empty cell(.) in table replace string', type: :string, default: ' '
12
14
  def convert(review_starter_configfile, outdir)
@@ -70,7 +70,11 @@ module ReVIEW
70
70
  end
71
71
 
72
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>//}")
73
+ if option_count > 0
74
+ content.gsub!(/^\/\/#{command}(?<option>(\[[^\r\n]*?\]){0,#{option_count}})(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}\\k<option>{\\k<inner>//}")
75
+ else
76
+ content.gsub!(/^\/\/#{command}(\[[^\r\n]*\])*{(?<inner>.*?)\/\/}/m, "//#{new_command}{\\k<inner>//}")
77
+ end
74
78
  end
75
79
 
76
80
  def replace_compatible_block_command_to_outside(content, command, new_command, option_count, add_options="", new_body="")
@@ -105,22 +109,29 @@ module ReVIEW
105
109
  content.gsub!(/@<#{command}>/, "@<#{new_command}>")
106
110
  end
107
111
 
108
- def replace_block_command_nested_boxed_article(content, box)
112
+ def replace_block_command_nested_boxed_article_i(content, box, depth)
109
113
  found = false
110
114
  content.dup.scan(/(^\/\/#{box})(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)).*?[\r\n]+)/m) { |m|
111
115
  matched = m[0..-1].join
112
116
  inner = m[5]
117
+ # info depth
113
118
  im = inner.match(/^\/\/(\w+)((\[.*?\])*)([$|{])/)
114
119
  unless im.nil?
115
120
  inner_cmd = im[1]
116
121
  inner_open = im[4]
117
122
  inner_opts = im[2]
118
- first_opt = inner_opts.match(/^\[(.*?)\]/)[1]
123
+ first_opt_m = inner_opts.match(/^\[(.*?)\]/)
124
+ first_opt = ""
119
125
 
126
+ # is_commentout = false
120
127
  is_commentout = true
121
- unless first_opt.empty?
122
- if inner.match(/@<.*?>[$|{]#{first_opt}/)
123
- is_commentout = false
128
+ if first_opt_m
129
+ first_opt_v = first_opt_m[1]
130
+ unless first_opt_v.empty?
131
+ if inner.match(/@<.*?>[$|{]#{first_opt}/)
132
+ is_commentout = false
133
+ first_opt = "\\[#{first_opt_v}\\]"
134
+ end
124
135
  end
125
136
  end
126
137
  cmd_begin = m[0..4].join
@@ -129,10 +140,10 @@ module ReVIEW
129
140
  if inner_open == m[2..4].join
130
141
  # if same fence then cmd_end == inner_end
131
142
  if is_commentout
132
- inner.gsub!(/(^\/\/(\w+\[.*?\])*#{inner_open})/, '#@#\1')
143
+ inner.gsub!(/(^\/\/(\w+(\[.*?\]|))*#{inner_open})/, '#@#\1')
133
144
  content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#@##{cmd_end}")
134
145
  else
135
- imb = inner.match(/(\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/\w+\[#{first_opt}\](\[.*?\])*#{inner_open}.*)\R/m)
146
+ imb = inner.match(/(\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/#{inner_cmd}#{first_opt}(\[.*?\])*#{inner_open}.*)\R/m)
136
147
  to_out_block = imb[1]
137
148
  inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '')
138
149
  content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}")
@@ -140,10 +151,10 @@ module ReVIEW
140
151
  else
141
152
  close = inner_open == '{' ? '}' : inner_open
142
153
  if is_commentout
143
- inner.gsub!(/(^\/\/(\w+\[.*?\])*#{inner_open})(.*?)(^\/\/#{close})/m, '#@#\1\2#@#\3')
154
+ inner.gsub!(/(^\/\/(\w+(\[.*?\]|))*#{inner_open})(.*?)(^\/\/#{close})/m, '#@#\1\2#@#\3')
144
155
  content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}")
145
156
  else
146
- imb = inner.match(/\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/(\w+)\[#{first_opt}\](\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)))/m)
157
+ imb = inner.match(/\R((^\/\/\w+(\[.*?\])*)\s*)*^\/\/(#{inner_cmd})#{first_opt}(\[[^\r\n]*?\])*(?:(\$)|(?:({)|(\|)))(.*?)(^\/\/)(?(3)(\$)|(?(4)(})|(\|)))/m)
147
158
  to_out_block = imb[0]
148
159
  inner.gsub!(/#{Regexp.escape(to_out_block)}/m, '')
149
160
  content.gsub!(/#{Regexp.escape(matched)}/m, "#{cmd_begin}#{inner}#{cmd_end}#{to_out_block}")
@@ -153,10 +164,14 @@ module ReVIEW
153
164
  end
154
165
  }
155
166
  if found
156
- replace_block_command_nested_boxed_article(content, box)
167
+ replace_block_command_nested_boxed_article_i(content, box, depth+1)
157
168
  end
158
169
  end
159
170
 
171
+ def replace_block_command_nested_boxed_article(content, box)
172
+ replace_block_command_nested_boxed_article_i(content, box, 0)
173
+ end
174
+
160
175
  def replace_block_command_nested_boxed_articles(content)
161
176
  replace_block_command_nested_boxed_article(content, 'note')
162
177
  replace_block_command_nested_boxed_article(content, 'memo')
@@ -263,11 +278,38 @@ module ReVIEW
263
278
  end
264
279
  end
265
280
 
281
+ def add_linkurl_footnote(content)
282
+ urls = {}
283
+ content.dup.scan(/(^.*)(@<href>{)(.*?)(,)(.*?)(})(.*)$/) { |m|
284
+ unless m[0].match(/^#@#/)
285
+ matched = m.join
286
+ prev = m[0]
287
+ url = m[2]
288
+ text = m[4]
289
+ post = m[6]
290
+ id = "link_auto_footnote#{urls.length}"
291
+ urls[id] = url
292
+ content.sub!(/#{matched}$/, "#{prev}@<href>{#{url},#{text}} @<fn>{#{id}} #{post}")
293
+ end
294
+ }
295
+
296
+ urls.each { |k,v|
297
+ content.sub!(/(@<href>{#{v},.*?} @<fn>{#{k}}.*?\R\R)/m, "\\1//footnote[#{k}][#{v}]\n")
298
+ }
299
+
300
+ urls.each { |k,v|
301
+ unless content.match(/\/\/footnote\[#{k}\]\[#{v}\]/)
302
+ content << "//footnote[#{k}][#{v}]\n"
303
+ end
304
+ }
305
+ end
306
+
266
307
  def update_content(outdir, contentfile)
267
308
  info contentfile
268
309
  content = File.read(contentfile)
269
310
  content.gsub!(/@<href>{(.*?)#.*?,(.*?)}/, '@<href>{\1,\2}')
270
311
  content.gsub!(/@<href>{(.*?)#.*?}/, '@<href>{\1}')
312
+ linkurl_footnote = @config['starter']['linkurl_footnote']
271
313
  # table 内の @ コマンドは不安定らしい
272
314
  while !content.gsub!(/(\/\/table.*)@<br>{}(.*?\/\/})/m, "\\1#{@table_br_replace}\\2").nil? do
273
315
  end
@@ -276,6 +318,7 @@ module ReVIEW
276
318
  end
277
319
  # Re:VIEW Starter commands
278
320
  replace_compatible_block_command_outline(content, 'terminal', 'cmd', 1)
321
+ replace_compatible_block_command_outline(content, 'cmd', 'cmd', 0)
279
322
  replace_compatible_block_command_to_outside(content, 'sideimage', 'image', 1, '[]')
280
323
  replace_block_command_outline(content, 'abstract', 'lead', true)
281
324
  delete_block_command(content, 'needvspace')
@@ -306,6 +349,10 @@ module ReVIEW
306
349
  # special command
307
350
  replace_sampleoutput(content)
308
351
 
352
+ if linkurl_footnote
353
+ add_linkurl_footnote(content)
354
+ end
355
+
309
356
  # nested command
310
357
  replace_block_command_nested_boxed_articles(content)
311
358
 
@@ -368,6 +415,45 @@ module ReVIEW
368
415
  end
369
416
  end
370
417
 
418
+ def preproc_content_files(outdir, pp, contentdir, contentfiles)
419
+ files = contentfiles.is_a?(String) ? contentfiles.split(/\R/) : contentfiles
420
+ files.each do |content|
421
+ contentpath = File.join(contentdir, content)
422
+ if File.exist?(contentpath)
423
+ info "preproc #{contentpath}"
424
+ buf = StringIO.new
425
+ pwd = Dir.pwd
426
+ Dir.chdir(outdir)
427
+ File.open(contentpath) { |f| pp.process(f, buf) }
428
+ Dir.chdir(pwd)
429
+ content = buf.string
430
+ content.gsub!(/^#[@]map.*$/, '')
431
+ File.write(contentpath, content)
432
+ end
433
+ end
434
+ end
435
+
436
+ def preproc_contents(outdir, options)
437
+ yamlfile = @config['catalogfile']
438
+ abspath = File.absolute_path(outdir)
439
+ contentdir = abspath
440
+ param = {}
441
+ param['tabwidth'] = options['tabwidth'].to_i
442
+ pp = ReVIEW::Preprocessor.new(ReVIEW::Repository.new(param), param)
443
+
444
+ if options['strict']
445
+ catalog = ReVIEW::Catalog.new(File.open(File.join(abspath, yamlfile)))
446
+ preproc_content_files(outdir, pp, contentdir, catalog.predef())
447
+ preproc_content_files(outdir, pp, contentdir, catalog.chaps())
448
+ preproc_content_files(outdir, pp, contentdir, catalog.appendix())
449
+ preproc_content_files(outdir, pp, contentdir, catalog.postdef())
450
+ else
451
+ # copy_contents(outdir)
452
+ contentsfiles = Pathname.glob(File.join(File.join(@basedir, @srccontentsdir), '*.re')).map(&:basename)
453
+ preproc_content_files(outdir, pp, contentdir, contentsfiles)
454
+ end
455
+ end
456
+
371
457
  def clean_initial_project(outdir)
372
458
  FileUtils.rm(File.join(outdir, 'config.yml'))
373
459
  FileUtils.rm(File.join(outdir, 'catalog.yml'))
@@ -407,6 +493,11 @@ module ReVIEW
407
493
  # updater.backup = false
408
494
  updater.execute()
409
495
  Dir.chdir(pwd)
496
+
497
+ if options['preproc']
498
+ info 'preproc'
499
+ preproc_contents(outdir, options)
500
+ end
410
501
  end
411
502
 
412
503
  def self.execute(yamlfile, outdir, options)
@@ -1,5 +1,5 @@
1
1
  module ReVIEW
2
2
  module Retrovert
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: review-retrovert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - srz_zumix
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-03 00:00:00.000000000 Z
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -74,7 +74,6 @@ files:
74
74
  - ".gitignore"
75
75
  - ".rspec"
76
76
  - ".ruby-version"
77
- - ".travis.yml"
78
77
  - CHANGELOG.md
79
78
  - Dockerfile
80
79
  - Gemfile
@@ -196,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
195
  - !ruby/object:Gem::Version
197
196
  version: '0'
198
197
  requirements: []
199
- rubygems_version: 3.1.2
198
+ rubygems_version: 3.1.4
200
199
  signing_key:
201
200
  specification_version: 4
202
201
  summary: Re:VIEW Starter to Re:VIEW
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.5.5
6
- before_install: gem install bundler -v 2.1.4