aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/xml_fictionbook2.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v5/xml_fictionbook2.rb')
-rw-r--r--lib/sisu/v5/xml_fictionbook2.rb88
1 files changed, 47 insertions, 41 deletions
diff --git a/lib/sisu/v5/xml_fictionbook2.rb b/lib/sisu/v5/xml_fictionbook2.rb
index 8ee2fb89..6549fa12 100644
--- a/lib/sisu/v5/xml_fictionbook2.rb
+++ b/lib/sisu/v5/xml_fictionbook2.rb
@@ -8,7 +8,8 @@
* Author: Ralph Amissah
* Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- 2007, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved.
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah,
+ All Rights Reserved.
* License: GPL 3 or later:
@@ -131,10 +132,11 @@ module SiSU_XML_Fictionbook
def tags
# collapsed -->
def collapsed
- %w[ 0 1 2 3 4 5 6 ]
+ %w[ 0 1 2 3 4 5 ]
end
def fictionbook
- [ 'section',
+ [
+ 'section',
'section',
'section',
'section',
@@ -270,16 +272,16 @@ module SiSU_XML_Fictionbook
</FictionBook>
WOK
end
- def output(o,lev=nil,comment='')
- puts lev == 0..6 \
- ? "#{space*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}</#{lev}>#{comment}"
- : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}</#{lev}>#{comment}"
+ def output(o,comment='')
+ puts o.lc == 0..6 \
+ ? "#{space*o.lc}<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}</#{o.lc}>#{comment}"
+ : "<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}</#{o.lc}>#{comment}"
end
def structure_collapsed(data)
puts "\ncollapsed structure, heading outline --->\n\n"
data.each_with_index do |o,i|
if (o.is ==:heading || o.is ==:heading_insert)
- output(o,o.lc)
+ output(o)
end
end
end
@@ -300,23 +302,19 @@ module SiSU_XML_Fictionbook
data.each_with_index do |o,i|
ocn=(defined? o.ocn and not o.ocn.nil?) ? "\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}" : ''
if o.is ==:heading
- lev=o.lc
- chlv=(o.lv.to_i == 1) \
- ? @chlv=o.lc.to_i
- : 0
unless doc_position==:head
- filename_fictionbook.puts structure_build_tag_close(lev,h)
+ filename_fictionbook.puts structure_build_tag_close(o.lc,h)
end
doc_position=:body_and_tail
- filename_fictionbook.puts %{#{space*lev}<#{tags.fictionbook[lev]}>
-#{space*lev}<title>
+ filename_fictionbook.puts %{#{space*o.lc}<#{tags.fictionbook[o.lc]}>
+#{space*o.lc}<title>
}
- filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,(lev*2+2)).line_wrap
- filename_fictionbook.puts %{#{space*lev}</title>}
- h=lev
+ filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,(o.lc*2+2)).line_wrap
+ filename_fictionbook.puts %{#{space*o.lc}</title>}
+ h=o.lc
elsif o.is ==:heading_insert \
and o.obj =~/Endnotes/ \
- and o.ln == 2
+ and o.ln == 1
break
elsif (o.of ==:para or o.of ==:block)
filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,6).line_wrap
@@ -327,36 +325,44 @@ module SiSU_XML_Fictionbook
filename_fictionbook.puts tail(images_base64)
filename_fictionbook.close
end
- def structure_build_tag_close(lev,h)
+ def structure_build_tag_close(lc,h)
x=[]
case h
+ when 0
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
when 1
- x << "#{space*1}</#{tags.fictionbook[1]}>" if (lev <= 1)
+ x << "#{space*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
when 2
- x << "#{space*2}</#{tags.fictionbook[2]}>" if (lev <= 2)
- x << "#{space*1}</#{tags.fictionbook[1]}>" if (lev <= 1)
+ x << "#{space*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
+ x << "#{space*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
when 3
- x << "#{space*3}</#{tags.fictionbook[3]}>" if (lev <= 3)
- x << "#{space*2}</#{tags.fictionbook[2]}>" if (lev <= 2)
- x << "#{space*1}</#{tags.fictionbook[1]}>" if (lev <= 1)
+ x << "#{space*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
+ x << "#{space*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
+ x << "#{space*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
when 4
- x << "#{space*4}</#{tags.fictionbook[4]}>" if (lev <= 4)
- x << "#{space*3}</#{tags.fictionbook[3]}>" if (lev <= 3)
- x << "#{space*2}</#{tags.fictionbook[2]}>" if (lev <= 2)
- x << "#{space*1}</#{tags.fictionbook[1]}>" if (lev <= 1)
+ x << "#{space*4}</#{tags.fictionbook[4]}>" if (lc <= 4)
+ x << "#{space*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
+ x << "#{space*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
+ x << "#{space*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
when 5
- x << "#{space*5}</#{tags.fictionbook[5]}>" if (lev <= 5)
- x << "#{space*4}</#{tags.fictionbook[4]}>" if (lev <= 4)
- x << "#{space*3}</#{tags.fictionbook[3]}>" if (lev <= 3)
- x << "#{space*2}</#{tags.fictionbook[2]}>" if (lev <= 2)
- x << "#{space*1}</#{tags.fictionbook[1]}>" if (lev <= 1)
+ x << "#{space*5}</#{tags.fictionbook[5]}>" if (lc <= 5)
+ x << "#{space*4}</#{tags.fictionbook[4]}>" if (lc <= 4)
+ x << "#{space*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
+ x << "#{space*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
+ x << "#{space*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
when 6
- x << "#{space*6}</#{tags.fictionbook[6]}>" if (lev <= 6)
- x << "#{space*5}</#{tags.fictionbook[5]}>" if (lev <= 5)
- x << "#{space*4}</#{tags.fictionbook[4]}>" if (lev <= 4)
- x << "#{space*3}</#{tags.fictionbook[3]}>" if (lev <= 3)
- x << "#{space*2}</#{tags.fictionbook[2]}>" if (lev <= 2)
- x << "#{space*1}</#{tags.fictionbook[1]}>" if (lev <= 1)
+ x << "#{space*6}</#{tags.fictionbook[6]}>" if (lc <= 6)
+ x << "#{space*5}</#{tags.fictionbook[5]}>" if (lc <= 5)
+ x << "#{space*4}</#{tags.fictionbook[4]}>" if (lc <= 4)
+ x << "#{space*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
+ x << "#{space*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
+ x << "#{space*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
+ x << "#{space*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
end
x.join("\n")
end