Skip to content

Commit

Permalink
skip nonum from counting
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Apr 14, 2016
1 parent a2a5a40 commit 656e74e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/review/book/base.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions lib/review/book/chapter.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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</\A//[a-z]+/>
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
Expand Down

0 comments on commit 656e74e

Please sign in to comment.