diff --git a/lib/review/book/base.rb b/lib/review/book/base.rb index 9c7d69251..feba1854d 100644 --- a/lib/review/book/base.rb +++ b/lib/review/book/base.rb @@ -1,8 +1,6 @@ # -# $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $ -# # Copyright (c) 2002-2008 Minero Aoki -# 2009 Minero Aoki, Kenshi Muto +# 2009-2016 Minero Aoki, Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -336,11 +334,17 @@ def parse_chapters return catalog.parts_with_chaps.map do |entry| if entry.is_a? Hash chaps = entry.values.first.map do |chap| - Chapter.new(self, (num += 1), chap, "#{@basedir}/#{chap}") + chap = Chapter.new(self, (num += 1), chap, "#{@basedir}/#{chap}") + chap end Part.new(self, (part += 1), chaps, read_PART.split("\n")[part - 1]) else chap = Chapter.new(self, (num += 1), entry, "#{@basedir}/#{entry}") + if chap.number + num = chap.number + else + num -= 1 + end Part.new(self, nil, [chap]) end end diff --git a/lib/review/book/chapter.rb b/lib/review/book/chapter.rb index 3df98547e..3cea19329 100644 --- a/lib/review/book/chapter.rb +++ b/lib/review/book/chapter.rb @@ -1,8 +1,6 @@ # -# $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $ -# # Copyright (c) 2002-2008 Minero Aoki -# 2009 Minero Aoki, Kenshi Muto +# 2009-2016 Minero Aoki, Kenshi Muto # # This program is free software. # You can distribute or modify this program under the terms of @@ -35,6 +33,7 @@ def initialize(book, number, name, path, io = nil) end if !@content && @path && File.exist?(@path) @content = File.read(@path).sub(/\A\xEF\xBB\xBF/u, '') + @number = nil if check_header == "nonum" end @list_index = nil @table_index = nil @@ -48,11 +47,31 @@ def initialize(book, number, name, path, io = nil) @volume = nil end + def check_header + f = LineInput.new(Preprocessor::Strip.new(StringIO.new(@content))) + while f.next? + case f.peek + when /\A=+[\[\s\{]/ + m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(f.gets) + return m[2] # tag + when %r + line = f.gets + if line.rstrip[-1,1] == "{" + f.until_match(%r<\A//\}>) + end + end + f.gets + end + nil + end + def inspect "\#<#{self.class} #{@number} #{@path}>" end def format_number(heading = true) + return "" unless @number + if on_PREDEF? return "#{@number}" end