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 diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 248a0a835..1d16558bd 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -58,6 +58,7 @@ def builder_init_file @chapter.book.image_types = %w( .png .jpg .jpeg .gif .svg ) @column = 0 @sec_counter = SecCounter.new(5, @chapter) + @nonum_counter = 0 end private :builder_init_file @@ -194,10 +195,12 @@ def headline(level, label, caption) end def nonum_begin(level, label, caption) + @nonum_counter += 1 puts '' if level > 1 unless caption.empty? if label.nil? - puts %Q[#{compile_inline(caption)}] + id = normalize_id("#{@chapter.name}_nonum#{@nonum_counter}") + puts %Q[#{compile_inline(caption)}] else puts %Q[#{compile_inline(caption)}] end diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index f94039cba..de5b15284 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -101,6 +101,7 @@ def headline(level, label, caption) def nonum_begin(level, label, caption) blank unless @output.pos == 0 puts macro(HEADLINE[level]+"*", compile_inline(caption)) + puts macro('addcontentsline', 'toc', HEADLINE[level], compile_inline(caption)) end def nonum_end(level)