lib/review/index_builder.rb in review-5.2.0 vs lib/review/index_builder.rb in review-5.3.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2008-2020 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
+# Copyright (c) 2008-2021 Minero Aoki, Kenshi Muto, Masayoshi Takahashi,
# KADO Masanori
#
# This program is free software.
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
@@ -11,11 +11,12 @@
require 'review/builder'
require 'review/sec_counter'
module ReVIEW
class IndexBuilder < Builder
- attr_reader :list_index, :table_index, :equation_index, :footnote_index,
+ attr_reader :list_index, :table_index, :equation_index,
+ :footnote_index, :endnote_index,
:numberless_image_index, :image_index, :icon_index, :indepimage_index,
:headline_index, :column_index, :bibpaper_index
def initialize(strict = false, *args)
super
@@ -51,15 +52,20 @@
end
def builder_init_file
super
@headline_stack = []
+ @crossref = {
+ footnote: {},
+ endnote: {}
+ }
@list_index = ReVIEW::Book::ListIndex.new
@table_index = ReVIEW::Book::TableIndex.new
@equation_index = ReVIEW::Book::EquationIndex.new
@footnote_index = ReVIEW::Book::FootnoteIndex.new
+ @endnote_index = ReVIEW::Book::EndnoteIndex.new
@headline_index = ReVIEW::Book::HeadlineIndex.new(@chapter)
@column_index = ReVIEW::Book::ColumnIndex.new
@chapter_index = ReVIEW::Book::ChapterIndex.new
@bibpaper_index = ReVIEW::Book::BibpaperIndex.new
@@ -71,10 +77,18 @@
end
end
private :builder_init_file
def result
+ %i[footnote endnote].each do |name|
+ @crossref[name].each_pair do |k, v|
+ if v == 0
+ warn "#{@chapter.basename}: #{name} ID #{k} is not referred."
+ end
+ end
+ end
+
nil
end
def target_name
'index'
@@ -98,10 +112,11 @@
item_id = @headline_stack.join('|')
item = ReVIEW::Book::Index::Item.new(item_id, @sec_counter.number_list, caption)
@headline_index.add_item(item)
+ compile_inline(caption)
end
def nonum_begin(level, label, caption)
check_id(label)
return if level < 2
@@ -245,85 +260,115 @@
def read(_lines)
end
alias_method :lead, :read
- def list(_lines, id, _caption, _lang = nil)
+ def list(lines, id, caption, _lang = nil)
check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @list_index.size + 1)
@list_index.add_item(item)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
- def source(_lines, _caption = nil, _lang = nil)
+ def source(lines, caption = nil, _lang = nil)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
- def listnum(_lines, id, _caption, _lang = nil)
+ def listnum(lines, id, caption, _lang = nil)
check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @list_index.size + 1)
@list_index.add_item(item)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
- def emlist(lines, caption = nil, lang = nil)
+ def emlist(lines, caption = nil, _lang = nil)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
- def emlistnum(lines, caption = nil, lang = nil)
+ def emlistnum(lines, caption = nil, _lang = nil)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
def cmd(lines, caption = nil)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
def quote(lines)
+ lines.each { |line| compile_inline(line) }
end
def image(_lines, id, caption, _metric = nil)
check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @image_index.size + 1, caption)
@image_index.add_item(item)
+ compile_inline(caption)
end
- def table(_lines, id = nil, caption = nil)
+ def table(lines, id = nil, caption = nil)
check_id(id)
if id
item = ReVIEW::Book::Index::Item.new(id, @table_index.size + 1, caption)
@table_index.add_item(item)
end
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
- def emtable(_lines, _caption = nil)
+ def emtable(_lines, caption = nil)
# item = ReVIEW::Book::TableIndex::Item.new(id, @table_index.size + 1)
# @table_index << item
+ compile_inline(caption)
end
def comment(lines, comment = nil)
end
- def imgtable(_lines, id, _caption = nil, _metric = nil)
+ def imgtable(_lines, id, caption = nil, _metric = nil)
check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @table_index.size + 1)
@table_index.add_item(item)
## to find image path
item = ReVIEW::Book::Index::Item.new(id, @indepimage_index.size + 1)
@indepimage_index.add_item(item)
+ compile_inline(caption)
end
def footnote(id, str)
check_id(id)
+ @crossref[:footnote][id] ||= 0
item = ReVIEW::Book::Index::Item.new(id, @footnote_index.size + 1, str)
@footnote_index.add_item(item)
+ compile_inline(str)
end
- def indepimage(_lines, id, _caption = '', _metric = nil)
+ def endnote(id, str)
check_id(id)
+ @crossref[:endnote][id] ||= 0
+ item = ReVIEW::Book::Index::Item.new(id, @endnote_index.size + 1, str)
+ @endnote_index.add_item(item)
+ compile_inline(str)
+ end
+
+ def indepimage(_lines, id, caption = '', _metric = nil)
+ check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @indepimage_index.size + 1)
@indepimage_index.add_item(item)
+ compile_inline(caption)
end
- def numberlessimage(_lines, id, _caption = '', _metric = nil)
+ def numberlessimage(_lines, id, caption = '', _metric = nil)
check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @indepimage_index.size + 1)
@indepimage_index.add_item(item)
+ compile_inline(caption)
end
def hr
end
@@ -332,28 +377,34 @@
end
def blankline
end
- def flushright(_lines)
+ def flushright(lines)
+ lines.each { |line| compile_inline(line) }
end
def centering(lines)
+ lines.each { |line| compile_inline(line) }
end
def olnum(_num)
end
def pagebreak
end
- def bpo(_lines)
+ def bpo(lines)
+ lines.each { |line| compile_inline(line) }
end
def noindent
end
+ def printendnotes
+ end
+
def compile_inline(s)
@compiler.text(s)
end
def inline_chapref(_id)
@@ -386,14 +437,20 @@
def inline_eq(_id)
''
end
- def inline_fn(_id)
+ def inline_fn(id)
+ @crossref[:footnote][id] = @crossref[:footnote][id] ? @crossref[:footnote][id] + 1 : 1
''
end
+ def inline_endnote(id)
+ @crossref[:endnote][id] = @crossref[:endnote][id] ? @crossref[:endnote][id] + 1 : 1
+ ''
+ end
+
def inline_i(_str)
''
end
def inline_b(_str)
@@ -462,14 +519,16 @@
def text(_str)
''
end
- def bibpaper(_lines, id, caption)
+ def bibpaper(lines, id, caption)
check_id(id)
item = ReVIEW::Book::Index::Item.new(id, @bibpaper_index.size + 1, caption)
@bibpaper_index.add_item(item)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
end
def inline_hd(_id)
''
end
@@ -600,27 +659,34 @@
## override
def error(msg = nil)
# ignore in indexing
end
- def texequation(_lines, id = nil, _caption = '')
+ def texequation(_lines, id = nil, caption = '')
check_id(id)
if id
item = ReVIEW::Book::Index::Item.new(id, @equation_index.size + 1)
@equation_index.add_item(item)
end
+ compile_inline(caption)
end
def get_chap(_chapter = nil)
''
end
def extract_chapter_id(_chap_ref)
''
end
- def captionblock(_type, _lines, _caption, _specialstyle = nil)
+ def captionblock(_type, lines, caption, _specialstyle = nil)
+ compile_inline(caption)
+ lines.each { |line| compile_inline(line) }
''
+ end
+
+ def graph(lines, id, _command, caption = '')
+ image(lines, id, caption)
end
def tsize(_str)
''
end