review 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -4
- data/.travis.yml +1 -1
- data/NEWS.ja.md +97 -1
- data/NEWS.md +97 -1
- data/bin/review-catalog-converter +1 -1
- data/bin/review-check +5 -5
- data/bin/review-checkdep +1 -1
- data/bin/review-compile +5 -5
- data/bin/review-idgxmlmaker +16 -0
- data/bin/review-index +7 -7
- data/bin/review-preproc +9 -9
- data/bin/review-validate +2 -2
- data/bin/review-vol +5 -5
- data/doc/config.yml.sample +14 -6
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +15 -5
- data/doc/format.md +30 -18
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/lib/review/book.rb +1 -1
- data/lib/review/book/base.rb +23 -63
- data/lib/review/book/chapter.rb +18 -3
- data/lib/review/book/compilable.rb +5 -0
- data/lib/review/book/index.rb +26 -65
- data/lib/review/book/index/item.rb +40 -0
- data/lib/review/book/part.rb +22 -2
- data/lib/review/builder.rb +60 -40
- data/lib/review/catalog.rb +12 -15
- data/lib/review/compiler.rb +68 -36
- data/lib/review/configure.rb +10 -7
- data/lib/review/epubmaker.rb +5 -2
- data/lib/review/htmlbuilder.rb +24 -71
- data/lib/review/htmlutils.rb +2 -3
- data/lib/review/i18n.rb +2 -2
- data/lib/review/idgxmlbuilder.rb +101 -55
- data/lib/review/idgxmlmaker.rb +184 -0
- data/lib/review/init-web/finish.html +10 -0
- data/lib/review/init-web/index.html +190 -0
- data/lib/review/init-web/review-layout-design.js +691 -0
- data/lib/review/init.rb +110 -26
- data/lib/review/latexbuilder.rb +76 -54
- data/lib/review/lineinput.rb +1 -1
- data/lib/review/logger.rb +4 -8
- data/lib/review/makerhelper.rb +6 -4
- data/lib/review/markdownbuilder.rb +25 -38
- data/lib/review/md2inaobuilder.rb +3 -5
- data/lib/review/pdfmaker.rb +15 -15
- data/lib/review/plaintextbuilder.rb +67 -76
- data/lib/review/preprocessor.rb +13 -13
- data/lib/review/rstbuilder.rb +31 -31
- data/lib/review/textmaker.rb +13 -3
- data/lib/review/textutils.rb +77 -2
- data/lib/review/tocparser.rb +17 -17
- data/lib/review/tocprinter.rb +8 -8
- data/lib/review/topbuilder.rb +76 -57
- data/lib/review/update.rb +16 -16
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +2 -2
- data/lib/review/yamlloader.rb +3 -0
- data/review.gemspec +4 -3
- data/samples/sample-book/README.md +7 -2
- data/samples/sample-book/src/.gitignore +153 -0
- data/samples/sample-book/src/config-jlreq.yml +6 -0
- data/samples/sample-book/src/lib/tasks/review.rake +20 -9
- data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
- data/samples/syntax-book/ch03.re +3 -6
- data/samples/syntax-book/config-jlreq.yml +5 -0
- data/samples/syntax-book/lib/tasks/review.rake +7 -7
- data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
- data/templates/latex/config.erb +6 -0
- data/templates/latex/layout.tex.erb +1 -0
- data/templates/latex/review-jlreq/review-base.sty +93 -31
- data/templates/latex/review-jlreq/review-jlreq.cls +6 -0
- data/templates/latex/review-jlreq/review-style.sty +3 -0
- data/templates/latex/review-jsbook/README.md +39 -0
- data/templates/latex/review-jsbook/review-base.sty +65 -10
- data/templates/latex/review-jsbook/review-jsbook.cls +4 -0
- data/templates/latex/review-jsbook/review-style.sty +4 -1
- data/test/assets/test_template.tex +11 -3
- data/test/assets/test_template_backmatter.tex +11 -3
- data/test/test_book.rb +65 -19
- data/test/test_catalog.rb +18 -42
- data/test/test_catalog_converter_cmd.rb +1 -1
- data/test/test_epubmaker_cmd.rb +2 -2
- data/test/test_helper.rb +1 -1
- data/test/test_htmlbuilder.rb +144 -55
- data/test/test_i18n.rb +25 -25
- data/test/test_idgxmlbuilder.rb +60 -18
- data/test/test_image_finder.rb +6 -6
- data/test/test_latexbuilder.rb +128 -24
- data/test/test_latexbuilder_v2.rb +23 -23
- data/test/test_logger.rb +14 -1
- data/test/test_makerhelper.rb +3 -3
- data/test/test_markdownbuilder.rb +45 -4
- data/test/test_md2inaobuilder.rb +12 -2
- data/test/test_pdfmaker.rb +1 -1
- data/test/test_pdfmaker_cmd.rb +1 -1
- data/test/test_plaintextbuilder.rb +31 -6
- data/test/test_rstbuilder.rb +33 -4
- data/test/test_textutils.rb +109 -2
- data/test/test_topbuilder.rb +35 -7
- data/test/test_update.rb +17 -8
- data/test/test_yamlloader.rb +13 -0
- metadata +26 -2
data/lib/review/preprocessor.rb
CHANGED
@@ -51,10 +51,10 @@ module ReVIEW
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def process(inf, outf)
|
54
|
-
init_errorutils
|
54
|
+
init_errorutils(inf)
|
55
55
|
@f = outf
|
56
56
|
begin
|
57
|
-
preproc
|
57
|
+
preproc(inf)
|
58
58
|
rescue Errno::ENOENT => e
|
59
59
|
error e.message
|
60
60
|
end
|
@@ -80,7 +80,7 @@ module ReVIEW
|
|
80
80
|
direc = parse_directive(line, 1, 'stderr')
|
81
81
|
@f.print line
|
82
82
|
get_output(expand(direc.arg), direc['stderr']).each { |out| @f.print out.string }
|
83
|
-
skip_list
|
83
|
+
skip_list(f)
|
84
84
|
|
85
85
|
when /\A\#@mapfile/
|
86
86
|
direc = parse_directive(line, 1, 'eval')
|
@@ -131,15 +131,15 @@ module ReVIEW
|
|
131
131
|
@f.print directive_line
|
132
132
|
newlines.each do |line|
|
133
133
|
if with_lineno
|
134
|
-
print_number
|
134
|
+
print_number(line.number)
|
135
135
|
end
|
136
136
|
@f.print line.string
|
137
137
|
end
|
138
|
-
skip_list
|
138
|
+
skip_list(f)
|
139
139
|
end
|
140
140
|
|
141
141
|
def print_number(num)
|
142
|
-
@f.printf
|
142
|
+
@f.printf('%4s ', (num ? num.to_s : ''))
|
143
143
|
end
|
144
144
|
|
145
145
|
def skip_list(f)
|
@@ -279,7 +279,7 @@ module ReVIEW
|
|
279
279
|
Open3.popen3(cmd) do |_stdin, stdout, stderr|
|
280
280
|
out = stdout.readlines
|
281
281
|
if use_stderr
|
282
|
-
out.concat
|
282
|
+
out.concat(stderr.readlines)
|
283
283
|
else
|
284
284
|
err = stderr.readlines
|
285
285
|
end
|
@@ -361,7 +361,7 @@ module ReVIEW
|
|
361
361
|
end
|
362
362
|
|
363
363
|
def parse_file(fname)
|
364
|
-
File.open(fname, '
|
364
|
+
File.open(fname, 'rt:BOM|utf-8') do |f|
|
365
365
|
init_errorutils f
|
366
366
|
return _parse_file(f)
|
367
367
|
end
|
@@ -403,14 +403,14 @@ module ReVIEW
|
|
403
403
|
error "begin x2: #{key}"
|
404
404
|
end
|
405
405
|
(repo[type] ||= {})[spec] = curr[key] = []
|
406
|
-
opened.push
|
406
|
+
opened.push([type, spec])
|
407
407
|
|
408
408
|
when %r{(?:\A\#@|\#@@)([a-z]+)/(\w+)\}}
|
409
409
|
type = check_type($1)
|
410
410
|
spec = check_spec($2)
|
411
411
|
curr.delete("#{type}/#{spec}") or
|
412
412
|
error "end before begin: #{type}/#{spec}"
|
413
|
-
opened.delete
|
413
|
+
opened.delete("#{type}/#{spec}")
|
414
414
|
|
415
415
|
when /(?:\A\#@|\#@@)\}/
|
416
416
|
type, spec = opened.last
|
@@ -423,17 +423,17 @@ module ReVIEW
|
|
423
423
|
|
424
424
|
when /\A\#@-/ # does not increment line number.
|
425
425
|
line = canonical($')
|
426
|
-
curr.each_value { |list| list.push
|
426
|
+
curr.each_value { |list| list.push(Line.new(nil, line)) }
|
427
427
|
|
428
428
|
else
|
429
429
|
next if yacchack and line.strip == ';'
|
430
430
|
line = canonical(line)
|
431
|
-
curr.each_value { |list| list.push
|
431
|
+
curr.each_value { |list| list.push(Line.new(lineno, line)) }
|
432
432
|
lineno += 1
|
433
433
|
end
|
434
434
|
end
|
435
435
|
if curr.size > 1
|
436
|
-
curr.delete
|
436
|
+
curr.delete('WHOLE')
|
437
437
|
curr.each { |range, lines| @logger.warn "#{filename}: unclosed range: #{range} (begin @#{lines.first.number})" }
|
438
438
|
raise ApplicationError, 'ERROR'
|
439
439
|
end
|
data/lib/review/rstbuilder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto
|
2
2
|
# 2002-2006 Minero Aoki
|
3
3
|
#
|
4
4
|
# This program is free software.
|
@@ -103,13 +103,13 @@ module ReVIEW
|
|
103
103
|
blank
|
104
104
|
end
|
105
105
|
puts '=' * caption.size * 2
|
106
|
-
when 2
|
106
|
+
when 2
|
107
107
|
p = '='
|
108
|
-
when 3
|
108
|
+
when 3
|
109
109
|
p = '-'
|
110
|
-
when 4
|
110
|
+
when 4
|
111
111
|
p = '`'
|
112
|
-
when 5
|
112
|
+
when 5
|
113
113
|
p = '~'
|
114
114
|
end
|
115
115
|
|
@@ -124,7 +124,7 @@ module ReVIEW
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def ul_item(lines)
|
127
|
-
puts ' ' * (@ul_indent - 1) + "* #{lines
|
127
|
+
puts ' ' * (@ul_indent - 1) + "* #{join_lines_to_paragraph(lines)}"
|
128
128
|
end
|
129
129
|
|
130
130
|
def ul_end
|
@@ -138,7 +138,7 @@ module ReVIEW
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def ol_item(lines, _num)
|
141
|
-
puts ' ' * (@ol_indent - 1) + "#. #{lines
|
141
|
+
puts ' ' * (@ol_indent - 1) + "#. #{join_lines_to_paragraph(lines)}"
|
142
142
|
end
|
143
143
|
|
144
144
|
def ol_end
|
@@ -167,7 +167,7 @@ module ReVIEW
|
|
167
167
|
if @in_role
|
168
168
|
pre = ' '
|
169
169
|
end
|
170
|
-
puts pre + lines
|
170
|
+
puts pre + join_lines_to_paragraph(lines)
|
171
171
|
puts "\n"
|
172
172
|
end
|
173
173
|
|
@@ -575,87 +575,87 @@ module ReVIEW
|
|
575
575
|
end
|
576
576
|
|
577
577
|
def flushright(lines)
|
578
|
-
base_parablock
|
578
|
+
base_parablock('flushright', lines, nil)
|
579
579
|
end
|
580
580
|
|
581
581
|
def centering(lines)
|
582
|
-
base_parablock
|
582
|
+
base_parablock('centering', lines, nil)
|
583
583
|
end
|
584
584
|
|
585
585
|
def note(lines, caption = nil)
|
586
|
-
base_parablock
|
586
|
+
base_parablock('note', lines, caption)
|
587
587
|
end
|
588
588
|
|
589
589
|
def memo(lines, caption = nil)
|
590
|
-
base_parablock
|
590
|
+
base_parablock('memo', lines, caption)
|
591
591
|
end
|
592
592
|
|
593
593
|
def tip(lines, caption = nil)
|
594
|
-
base_parablock
|
594
|
+
base_parablock('tip', lines, caption)
|
595
595
|
end
|
596
596
|
|
597
597
|
def info(lines, caption = nil)
|
598
|
-
base_parablock
|
598
|
+
base_parablock('info', lines, caption)
|
599
599
|
end
|
600
600
|
|
601
601
|
def planning(lines, caption = nil)
|
602
|
-
base_parablock
|
602
|
+
base_parablock('planning', lines, caption)
|
603
603
|
end
|
604
604
|
|
605
605
|
def best(lines, caption = nil)
|
606
|
-
base_parablock
|
606
|
+
base_parablock('best', lines, caption)
|
607
607
|
end
|
608
608
|
|
609
609
|
def important(lines, caption = nil)
|
610
|
-
base_parablock
|
610
|
+
base_parablock('important', lines, caption)
|
611
611
|
end
|
612
612
|
|
613
613
|
def security(lines, caption = nil)
|
614
|
-
base_parablock
|
614
|
+
base_parablock('security', lines, caption)
|
615
615
|
end
|
616
616
|
|
617
617
|
def caution(lines, caption = nil)
|
618
|
-
base_parablock
|
618
|
+
base_parablock('caution', lines, caption)
|
619
619
|
end
|
620
620
|
|
621
621
|
def term(lines)
|
622
|
-
base_parablock
|
622
|
+
base_parablock('term', lines, nil)
|
623
623
|
end
|
624
624
|
|
625
625
|
def link(lines, caption = nil)
|
626
|
-
base_parablock
|
626
|
+
base_parablock('link', lines, caption)
|
627
627
|
end
|
628
628
|
|
629
629
|
def notice(lines, caption = nil)
|
630
|
-
base_parablock
|
630
|
+
base_parablock('notice', lines, caption)
|
631
631
|
end
|
632
632
|
|
633
633
|
def point(lines, caption = nil)
|
634
|
-
base_parablock
|
634
|
+
base_parablock('point', lines, caption)
|
635
635
|
end
|
636
636
|
|
637
637
|
def shoot(lines, caption = nil)
|
638
|
-
base_parablock
|
638
|
+
base_parablock('shoot', lines, caption)
|
639
639
|
end
|
640
640
|
|
641
641
|
def reference(lines)
|
642
|
-
base_parablock
|
642
|
+
base_parablock('reference', lines, nil)
|
643
643
|
end
|
644
644
|
|
645
645
|
def practice(lines)
|
646
|
-
base_parablock
|
646
|
+
base_parablock('practice', lines, nil)
|
647
647
|
end
|
648
648
|
|
649
649
|
def expert(lines)
|
650
|
-
base_parablock
|
650
|
+
base_parablock('expert', lines, nil)
|
651
651
|
end
|
652
652
|
|
653
653
|
def insn(lines, caption = nil)
|
654
|
-
base_block
|
654
|
+
base_block('insn', lines, caption)
|
655
655
|
end
|
656
656
|
|
657
657
|
def warning(lines, caption = nil)
|
658
|
-
base_parablock
|
658
|
+
base_parablock('warning', lines, caption)
|
659
659
|
end
|
660
660
|
|
661
661
|
alias_method :box, :insn
|
@@ -682,7 +682,7 @@ module ReVIEW
|
|
682
682
|
end
|
683
683
|
|
684
684
|
def bpo(lines)
|
685
|
-
base_block
|
685
|
+
base_block('bpo', lines, nil)
|
686
686
|
end
|
687
687
|
|
688
688
|
def inline_dtp(_str)
|
@@ -714,7 +714,7 @@ module ReVIEW
|
|
714
714
|
end
|
715
715
|
|
716
716
|
def source(lines, caption = nil, _lang = nil)
|
717
|
-
base_block
|
717
|
+
base_block('source', lines, caption)
|
718
718
|
end
|
719
719
|
|
720
720
|
def inline_ttibold(str)
|
data/lib/review/textmaker.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2018 Kenshi Muto
|
1
|
+
# Copyright (c) 2018-2019 Kenshi Muto
|
2
2
|
#
|
3
3
|
# This program is free software.
|
4
4
|
# You can distribute or modify this program under the terms of
|
@@ -15,9 +15,12 @@ require 'review/book'
|
|
15
15
|
require 'review/yamlloader'
|
16
16
|
require 'review/topbuilder'
|
17
17
|
require 'review/version'
|
18
|
+
require 'review/makerhelper'
|
18
19
|
|
19
20
|
module ReVIEW
|
20
21
|
class TEXTMaker
|
22
|
+
include MakerHelper
|
23
|
+
|
21
24
|
attr_accessor :config, :basedir
|
22
25
|
|
23
26
|
def initialize
|
@@ -27,12 +30,12 @@ module ReVIEW
|
|
27
30
|
end
|
28
31
|
|
29
32
|
def error(msg)
|
30
|
-
@logger.error
|
33
|
+
@logger.error msg
|
31
34
|
exit 1
|
32
35
|
end
|
33
36
|
|
34
37
|
def warn(msg)
|
35
|
-
@logger.warn
|
38
|
+
@logger.warn msg
|
36
39
|
end
|
37
40
|
|
38
41
|
def self.execute(*args)
|
@@ -65,6 +68,7 @@ module ReVIEW
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def remove_old_files(path)
|
71
|
+
cleanup_mathimg('_review_math_text')
|
68
72
|
FileUtils.rm_rf(path)
|
69
73
|
end
|
70
74
|
|
@@ -80,6 +84,7 @@ module ReVIEW
|
|
80
84
|
rescue => e
|
81
85
|
error "yaml error #{e.message}"
|
82
86
|
end
|
87
|
+
|
83
88
|
# YAML configs will be overridden by command line options.
|
84
89
|
@config.deep_merge!(cmd_config)
|
85
90
|
I18n.setup(@config['language'])
|
@@ -89,6 +94,11 @@ module ReVIEW
|
|
89
94
|
raise if @config['debug']
|
90
95
|
error(e.message)
|
91
96
|
end
|
97
|
+
|
98
|
+
math_dir = "./#{@config['imagedir']}/_review_math_text"
|
99
|
+
if @config['imgmath'] && File.exist?(File.join(math_dir, '__IMGMATH_BODY__.tex'))
|
100
|
+
make_math_images(math_dir)
|
101
|
+
end
|
92
102
|
end
|
93
103
|
|
94
104
|
def generate_text_files(yamlfile)
|
data/lib/review/textutils.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
+
# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
|
2
|
+
# KADO Masanori
|
3
|
+
# 2002-2007 Minero Aoki
|
4
|
+
#
|
5
|
+
# This program is free software.
|
6
|
+
# You can distribute or modify this program under the terms of
|
7
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
8
|
+
#
|
1
9
|
require 'nkf'
|
10
|
+
require 'digest'
|
2
11
|
|
3
12
|
module ReVIEW
|
4
13
|
module TextUtils
|
@@ -26,10 +35,76 @@ module ReVIEW
|
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
38
|
+
blocked_lines.map! { |i| join_lines_to_paragraph(i) }
|
39
|
+
|
29
40
|
if pre && post
|
30
|
-
blocked_lines.map! { |i|
|
41
|
+
blocked_lines.map! { |i| pre + i + post }
|
42
|
+
end
|
43
|
+
|
44
|
+
blocked_lines
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_space?(line1, line2, lang, lazy = nil)
|
48
|
+
# https://drafts.csswg.org/css-text-3/#line-break-transform
|
49
|
+
tail = line1[-1]
|
50
|
+
head = line2[0]
|
51
|
+
if tail.nil? || head.nil?
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
space = true
|
55
|
+
# rule 2
|
56
|
+
if %i[F W H].include?(Unicode::Eaw.property(tail)) &&
|
57
|
+
%i[F W H].include?(Unicode::Eaw.property(head)) &&
|
58
|
+
tail !~ /\p{Hangul}/ && head !~ /\p{Hangul}/
|
59
|
+
space = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
if %w[ja zh zh_CN zh_TW yi].include?(lang)
|
63
|
+
# rule 3
|
64
|
+
if (%i[F W H].include?(Unicode::Eaw.property(tail)) &&
|
65
|
+
tail !~ /\p{Hangul}/ &&
|
66
|
+
(head =~ /\p{P}/ || head =~ /\p{S}/ || Unicode::Eaw.property(head) == :A)) ||
|
67
|
+
(%i[F W H].include?(Unicode::Eaw.property(head)) &&
|
68
|
+
head !~ /\p{Hangul}/ &&
|
69
|
+
(tail =~ /\p{P}/ || head =~ /\p{S}/ || Unicode::Eaw.property(tail) == :A))
|
70
|
+
space = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# lazy than rule 3, but it looks better
|
74
|
+
if lazy &&
|
75
|
+
(%i[F W H].include?(Unicode::Eaw.property(tail)) &&
|
76
|
+
tail !~ /\p{Hangul}/) ||
|
77
|
+
(%i[F W H].include?(Unicode::Eaw.property(head)) &&
|
78
|
+
head !~ /\p{Hangul}/)
|
79
|
+
space = nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
space
|
83
|
+
end
|
84
|
+
|
85
|
+
def join_lines_to_paragraph(lines)
|
86
|
+
unless @book.config['join_lines_by_lang']
|
87
|
+
return lines.join
|
88
|
+
end
|
89
|
+
lazy = true
|
90
|
+
lang = 'ja'
|
91
|
+
0.upto(lines.size - 2) do |n|
|
92
|
+
if add_space?(lines[n], lines[n + 1], lang, lazy)
|
93
|
+
lines[n] += ' '
|
94
|
+
end
|
95
|
+
end
|
96
|
+
lines.join
|
97
|
+
end
|
98
|
+
|
99
|
+
def defer_math_image(str, path, key)
|
100
|
+
# for Re:VIEW >3
|
101
|
+
File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.tex'), 'a+') do |f|
|
102
|
+
f.puts str
|
103
|
+
f.puts '\\clearpage'
|
104
|
+
end
|
105
|
+
File.open(File.join(File.dirname(path), '__IMGMATH_BODY__.map'), 'a+') do |f|
|
106
|
+
f.puts key
|
31
107
|
end
|
32
|
-
blocked_lines.map(&:join)
|
33
108
|
end
|
34
109
|
|
35
110
|
private
|
data/lib/review/tocparser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2008-
|
2
|
+
# Copyright (c) 2008-2019 Minero Aoki, Kenshi Muto
|
3
3
|
# 2002-2007 Minero Aoki
|
4
4
|
#
|
5
5
|
# This program is free software.
|
@@ -15,7 +15,7 @@ require 'review/textbuilder'
|
|
15
15
|
module ReVIEW
|
16
16
|
class TOCParser
|
17
17
|
def self.parse(chap)
|
18
|
-
stream = StringIO.new(chap.content, '
|
18
|
+
stream = StringIO.new(chap.content, 'rt:BOM|utf-8')
|
19
19
|
new.parse(stream, chap).map do |root|
|
20
20
|
root.number = chap.number
|
21
21
|
root
|
@@ -43,40 +43,40 @@ module ReVIEW
|
|
43
43
|
when /\A(={2,})[\[\s\{]/
|
44
44
|
lev = $1.size
|
45
45
|
if lev > 5
|
46
|
-
error!
|
46
|
+
error!(filename, f.lineno, "section level too deep: #{lev}")
|
47
47
|
end
|
48
48
|
label = get_label(line)
|
49
49
|
if node_stack.empty?
|
50
50
|
# missing chapter label
|
51
51
|
dummy_chapter = Chapter.new(label, chap)
|
52
|
-
node_stack.push
|
53
|
-
roots.push
|
52
|
+
node_stack.push(dummy_chapter)
|
53
|
+
roots.push(dummy_chapter)
|
54
54
|
end
|
55
55
|
next if label =~ %r{\A\[/} # ex) "[/column]"
|
56
56
|
sec = Section.new(lev, label.gsub(/\A\{.*?\}\s?/, ''))
|
57
57
|
node_stack.pop until node_stack.last.level < sec.level
|
58
|
-
node_stack.last.add_child
|
59
|
-
node_stack.push
|
58
|
+
node_stack.last.add_child(sec)
|
59
|
+
node_stack.push(sec)
|
60
60
|
|
61
61
|
when /\A=[^=]/
|
62
62
|
label = get_label(line)
|
63
63
|
node_stack.clear
|
64
64
|
new_chapter = Chapter.new(label, chap)
|
65
|
-
node_stack.push
|
66
|
-
roots.push
|
65
|
+
node_stack.push(new_chapter)
|
66
|
+
roots.push(new_chapter)
|
67
67
|
|
68
68
|
when %r{\A//\w+(?:\[.*?\])*\{\s*\z}
|
69
69
|
if node_stack.empty?
|
70
|
-
error!
|
70
|
+
error!(filename, f.lineno, 'list found before section label')
|
71
71
|
end
|
72
72
|
node_stack.last.add_child(list = List.new)
|
73
73
|
beg = f.lineno
|
74
|
-
list.add
|
74
|
+
list.add(line)
|
75
75
|
while line = f.gets
|
76
76
|
break if %r{\A//\}} =~ line
|
77
|
-
list.add
|
77
|
+
list.add(line)
|
78
78
|
end
|
79
|
-
error!
|
79
|
+
error!(filename, beg, 'unterminated list') unless line
|
80
80
|
|
81
81
|
when %r{\A//\w}
|
82
82
|
# do nothing
|
@@ -87,10 +87,10 @@ module ReVIEW
|
|
87
87
|
# end
|
88
88
|
next if node_stack.empty?
|
89
89
|
node_stack.last.add_child(par = Paragraph.new(chap))
|
90
|
-
par.add
|
90
|
+
par.add(line)
|
91
91
|
while line = f.gets
|
92
92
|
break if /\A\s*\z/ =~ line
|
93
|
-
par.add
|
93
|
+
par.add(line)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -124,7 +124,7 @@ module ReVIEW
|
|
124
124
|
attr_reader :children
|
125
125
|
|
126
126
|
def add_child(c)
|
127
|
-
@children.push
|
127
|
+
@children.push(c)
|
128
128
|
end
|
129
129
|
|
130
130
|
def each_node(&block)
|
@@ -196,7 +196,7 @@ module ReVIEW
|
|
196
196
|
|
197
197
|
class Chapter < Section
|
198
198
|
def initialize(label, chap)
|
199
|
-
super
|
199
|
+
super(1, label, chap.path)
|
200
200
|
@chapter = chap
|
201
201
|
@chapter_id = chap.id
|
202
202
|
@path = chap.path
|