lib/review/tocprinter.rb in review-1.7.2 vs lib/review/tocprinter.rb in review-2.0.0.beta1
- old
+ new
@@ -11,27 +11,50 @@
# For details of LGPL, see the file "COPYING".
#
require 'review/htmlutils'
require 'review/htmllayout'
+require 'nkf'
module ReVIEW
class TOCPrinter
def TOCPrinter.default_upper_level
- 99 # no one use 99 level nest
+ 99 # no one use 99 level nest
end
def initialize(print_upper, param)
@print_upper = print_upper
@config = param
end
def print?(level)
level <= @print_upper
end
+
+ def nkffilter(line)
+ inc = ""
+ outc = "-w"
+ if @config["inencoding"] =~ /^EUC$/
+ inc = "-E"
+ elsif @config["inencoding"] =~ /^SJIS$/
+ inc = "-S"
+ elsif @config["inencoding"] =~ /^JIS$/
+ inc = "-J"
+ end
+
+ if @config["outencoding"] =~ /^EUC$/
+ outc = "-e"
+ elsif @config["outencoding"] =~ /^SJIS$/
+ outc = "-s"
+ elsif @config["outencoding"] =~ /^JIS$/
+ outc = "-j"
+ end
+
+ NKF.nkf("#{inc} #{outc}", line)
+ end
end
class TextTOCPrinter < TOCPrinter
def print_book(book)
@@ -54,26 +77,26 @@
if node.chapter?
vol = node.volume
printf "%3s %3dKB %6dC %5dL %s (%s)\n",
chapnumstr(node.number),
vol.kbytes, vol.chars, vol.lines,
- node.label, node.chapter_id
+ nkffilter(node.label), node.chapter_id
else
printf "%17s %5dL %s\n",
'', node.estimated_lines,
- " #{' ' * (node.level - 1)}#{number} #{node.label}"
+ nkffilter(" #{' ' * (node.level - 1)}#{number} #{node.label}")
end
end
def chapnumstr(n)
n ? sprintf('%2d.', n) : ' '
end
def volume_columns(level, volstr)
cols = ["", "", "", nil]
cols[level - 1] = volstr
- cols[0, 3] # does not display volume of level-4 section
+ cols[0, 3] # does not display volume of level-4 section
end
end
@@ -161,11 +184,11 @@
end
class IDGTOCPrinter < TOCPrinter
def print_book(book)
puts %Q(<?xml version="1.0" encoding="UTF-8"?>)
- puts %Q(<doc xmlns:aid='http://ns.adobe.com/AdobeInDesign/4.0/'><title aid:pstyle="h0">1 パート1</title><?dtp level="0" section="第1部 パート1"?>) # FIXME: 部タイトルを取るには? & 部ごとに結果を分けるには?
+ puts nkffilter(%Q(<doc xmlns:aid='http://ns.adobe.com/AdobeInDesign/4.0/'><title aid:pstyle="h0">1 パート1</title><?dtp level="0" section="第1部 パート1"?>)) # FIXME: 部タイトルを取るには? & 部ごとに結果を分けるには?
puts %Q(<ul aid:pstyle='ul-partblock'>)
print_children book
puts %Q(</ul></doc>)
end
@@ -183,18 +206,18 @@
def print_node(seq, node)
if node.chapter?
vol = node.volume
printf "<li aid:pstyle='ul-part'>%s</li>\n",
- "#{chapnumstr(node.number)}#{node.label}"
+ nkffilter("#{chapnumstr(node.number)}#{node.label}")
else
printf "<li>%-#{LABEL_LEN}s\n",
- " #{' ' * (node.level - 1)}#{seq} #{node.label}</li>"
+ nkffilter(" #{' ' * (node.level - 1)}#{seq} #{node.label}</li>")
end
end
def chapnumstr(n)
- n ? sprintf('第%d章 ', n) : ''
+ n ? nkffilter(sprintf('第%d章 ', n)) : ''
end
def volume_columns(level, volstr)
cols = ["", "", "", nil]
cols[level - 1] = volstr