Skip to content

Commit c2199f3

Browse files
committed
Merge remote-tracking branch 'origin' into bibliography
2 parents 6a20de8 + dfc1fd7 commit c2199f3

19 files changed

+244
-199
lines changed

.rubocop.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
AllCops:
22
Exclude:
3-
- lib/lineinput.rb
43
- lib/uuid.rb
54
- test/syntax-book/*
65
- tmp/*
@@ -135,6 +134,9 @@ Style/ClassMethods:
135134
Style/CommentedKeyword:
136135
Enabled: false
137136

137+
Style/DocumentDynamicEvalDefinition:
138+
Enabled: false
139+
138140
Style/FloatDivision:
139141
Enabled: false
140142

@@ -592,6 +594,8 @@ Naming/VariableName:
592594
Naming/VariableNumber:
593595
EnforcedStyle: normalcase
594596
Enabled: true
597+
Exclude:
598+
- test/*
595599

596600
#### Security
597601

bin/review-check

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def each_paragraph(f)
134134
case line
135135
when /\A\#@ok\((.*)\)/
136136
@review_utils_word_ok = $1
137-
when /\A\#@/
137+
when /\A\#@/, /\A\s*\z/
138138
# do nothing
139139
next
140140
when %r{\A//caption\{(.*?)//\}}
@@ -145,9 +145,6 @@ def each_paragraph(f)
145145
end
146146
when /\A=/
147147
yield [line.slice(/\A=+(?:\[.*?\])?\s+(.*)/, 1).strip], f.lineno
148-
when /\A\s*\z/
149-
# skip
150-
next
151148
else
152149
buf = [line.strip]
153150
lineno = f.lineno

lib/lineinput.rb

Lines changed: 0 additions & 155 deletions
This file was deleted.

lib/review/book/chapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def find_first_header_option
9999
nil
100100
rescue ArgumentError => e
101101
raise ReVIEW::CompileError, "#{@name}: #{e}"
102+
rescue SyntaxError => e
103+
raise ReVIEW::SyntaxError, "#{@name}:#{f.lineno}: #{e}"
102104
end
103105
end
104106

lib/review/compiler.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
module ReVIEW
1616
class Compiler
17+
MAX_HEADLINE_LEVEL = 6
18+
1719
def initialize(builder)
1820
@builder = builder
1921

@@ -333,6 +335,8 @@ def do_compile
333335
end
334336
end
335337
close_all_tagged_section
338+
rescue SyntaxError => e
339+
error e
336340
end
337341

338342
def compile_minicolumn_begin(name, caption = nil)
@@ -366,24 +370,27 @@ def compile_headline(line)
366370
@headline_indexs ||= [@chapter.number.to_i - 1]
367371
m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line)
368372
level = m[1].size
373+
if level > MAX_HEADLINE_LEVEL
374+
raise CompileError, "Invalid header: max headline level is #{MAX_HEADLINE_LEVEL}"
375+
end
369376
tag = m[2]
370377
label = m[3]
371378
caption = m[4].strip
372379
index = level - 1
373380
if tag
374-
if tag !~ %r{\A/}
375-
if caption.empty?
376-
warn 'headline is empty.'
377-
end
378-
close_current_tagged_section(level)
379-
open_tagged_section(tag, level, label, caption)
380-
else
381+
if tag.start_with?('/')
381382
open_tag = tag[1..-1]
382383
prev_tag_info = @tagged_section.pop
383384
if prev_tag_info.nil? || prev_tag_info.first != open_tag
384385
error "#{open_tag} is not opened."
385386
end
386387
close_tagged_section(*prev_tag_info)
388+
else
389+
if caption.empty?
390+
warn 'headline is empty.'
391+
end
392+
close_current_tagged_section(level)
393+
open_tagged_section(tag, level, label, caption)
387394
end
388395
else
389396
if caption.empty?

lib/review/idgxmlbuilder.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,10 @@ def inline_chapref(id)
11821182
chs = ['', '「', '」']
11831183
if @book.config['chapref']
11841184
chs2 = @book.config['chapref'].split(',')
1185-
if chs2.size != 3
1186-
error '--chapsplitter must have exactly 3 parameters with comma.'
1187-
else
1185+
if chs2.size == 3
11881186
chs = chs2
1187+
else
1188+
error '--chapsplitter must have exactly 3 parameters with comma.'
11891189
end
11901190
end
11911191
s = "#{chs[0]}#{@book.chapter_index.number(id)}#{chs[1]}#{@book.chapter_index.title(id)}#{chs[2]}"

lib/review/latexbuilder.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ def notoc_end(level)
180180
end
181181

182182
def nodisp_begin(level, _label, caption)
183-
if @output.pos != 0
184-
blank
185-
else
183+
if @output.pos == 0
186184
puts macro('clearpage')
185+
else
186+
blank
187187
end
188188
puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption))
189189
# FIXME: headings
@@ -1377,10 +1377,10 @@ def index(str)
13771377
else
13781378
if item =~ /\A[[:ascii:]]+\Z/ || @index_mecab.nil?
13791379
esc_item = escape_index(escape(item))
1380-
if esc_item != item
1381-
"#{escape_index(item)}@#{esc_item}"
1382-
else
1380+
if esc_item == item
13831381
esc_item
1382+
else
1383+
"#{escape_index(item)}@#{esc_item}"
13841384
end
13851385
else
13861386
yomi = NKF.nkf('-w --hiragana', @index_mecab.parse(item).force_encoding('UTF-8').chomp)

0 commit comments

Comments
 (0)