From 90ad666b942b965394f3dcb461177a52a25f90cd Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 18 Aug 2011 23:14:00 -0400 Subject: v3: epub, param, (defaults) epub tuning * include levels A - C as individual sections (xhtml file with consistent opf & ncx) * sync ncx with sisu internal structural logic (correct depth, include level A, place sisu toc) --- lib/sisu/v3/defaults.rb | 2 +- lib/sisu/v3/epub.rb | 75 ++++++++++++++++++++++++++++++-------------- lib/sisu/v3/epub_format.rb | 63 +++++++++++++++++++++++-------------- lib/sisu/v3/epub_segments.rb | 70 ++++++++++++++++++++++++----------------- lib/sisu/v3/param.rb | 39 +++++++++++++++++++---- 5 files changed, 167 insertions(+), 82 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v3/defaults.rb b/lib/sisu/v3/defaults.rb index 0ef81402..97c2b263 100644 --- a/lib/sisu/v3/defaults.rb +++ b/lib/sisu/v3/defaults.rb @@ -546,7 +546,7 @@ module SiSU_Viz %{"#{color_white}"} end def color_body - %{\n\n} + %{} end def color_font_face #was font WATCH "#{color_black}" diff --git a/lib/sisu/v3/epub.rb b/lib/sisu/v3/epub.rb index 83a0a795..e2d65111 100644 --- a/lib/sisu/v3/epub.rb +++ b/lib/sisu/v3/epub.rb @@ -85,9 +85,9 @@ module SiSU_EPUB @env=@particulars.env loc=@env.path.url.output_tell unless @opt.cmd =~/q/ - tool=if @opt.cmd =~/[MVvz]/; "#{@env.program.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" - else "[#{@opt.f_pth[:lng_is]}] #{@opt.fns}" - end + tool=(@opt.cmd =~/[MVvz]/) \ + ? "#{@env.program.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" \ + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fns}" @opt.cmd=~/[MVvz]/ \ ? SiSU_Screen::Ansi.new(@opt.cmd,'EPUB',tool).green_hi_blue \ : SiSU_Screen::Ansi.new(@opt.cmd,'EPUB',tool).green_title_hi @@ -199,7 +199,8 @@ module SiSU_EPUB @@firstseg=nil @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] - @nav_no=1 + @nav_no=0 + @s_a_no,@s_b_no,@s_c_no=0,0,0 @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author @@ -207,7 +208,6 @@ module SiSU_EPUB @@toc[:opf] << @epub.metadata_opf.package_open @@toc[:opf] << @epub.metadata_opf.metadata @@toc[:opf] << @epub.metadata_opf.manifest_open - @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc @@toc[:seg] << %{
\n
} @@toc[:scr] << %{
\n
} md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc @@ -216,43 +216,68 @@ module SiSU_EPUB @ncxo=[nil,false,false,false,false,false,false] @dob_toc2,@dob_toc3=nil,nil @ncx_cls=[] + @level_a_first_occurrence=true @data.each do |dob| if dob.is=='heading' \ or dob.is=='heading_insert' dob_toc=dob.dup toc=case dob_toc.ln when 1 + @s_a_no +=1 + name_s_a='section_a' + @s_a_no.to_s + @nav_no+=1 + @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4]=true,false,false,false + @epub.sections(dob_toc,name_s_a) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_a) if dob_toc + if @level_a_first_occurrence + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc + @level_a_first_occurrence=false + end + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_a) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_s_a) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_s_a) Toc.new(@md,dob_toc).level_1 when 2 + @s_b_no +=1 + name_s_b='section_b' + @s_b_no.to_s @nav_no+=1 @nav_no2=@nav_no - @ncx_cls << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncx_cls << @epub.toc_ncx.navpoint_close if @ncxo[3] - @ncx_cls << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[2],@ncxo[3],@ncxo[4]=false,false,false - @dob_toc2=dob_toc - @ncxo[2]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @ncxo[2],@ncxo[3],@ncxo[4]=true,false,false + @epub.sections(dob_toc,name_s_b) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_b) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_b) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_s_b) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_s_b) Toc.new(@md,dob_toc).level_2 when 3 + @s_c_no +=1 + name_s_c='section_c' + @s_c_no.to_s @nav_no+=1 @nav_no3=@nav_no - @ncx_cls << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncx_cls << @epub.toc_ncx.navpoint_close if @ncxo[3] - @ncxo[3],@ncxo[4]=false,false - @dob_toc3=dob_toc - @ncxo[3]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @ncxo[3],@ncxo[4]=true,false + @epub.sections(dob_toc,name_s_c) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,name_s_c) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,name_s_c) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,name_s_c) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,name_s_c) Toc.new(@md,dob_toc).level_3 when 4 - @@toc[:ncx] << @ncx_cls if @ncx_cls.length > 0 @ncx_cls=[] - @@toc[:ncx] << @epub.toc_ncx.navpoint_top3(@dob_toc2,@nav_no2,dob_toc.name) if @dob_toc2 #epub ncx navmap - @@toc[:ncx] << @epub.toc_ncx.navpoint_top3(@dob_toc3,@nav_no3,dob_toc.name) if @dob_toc3 #epub ncx navmap - @dob_toc2,@dob_toc3=nil,nil @nav_no+=1 @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncxo[4]=false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no) if dob_toc #epub ncx navmap @ncxo[4]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no) if dob_toc md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc) md_opf_a_spine << @epub.metadata_opf.spine(dob_toc) md_opf_a_guide << @epub.metadata_opf.guide(dob_toc) @@ -499,8 +524,10 @@ module SiSU_EPUB dochead.gsub!(/toc\.(html)/,'doc.\1') #kludge toc_shared << dochead #<< ads.div.major segtoc << format_head_toc.head #<< ads.div.major - toc_shared << format_head_toc.toc_head_escript if SiSU_EPUB_Format::Head_toc.method_defined? :toc_head_escript - segtoc << format_head_toc.toc_head_escript if SiSU_EPUB_Format::Head_toc.method_defined? :toc_head_escript + if SiSU_EPUB_Format::Head_toc.method_defined? :toc_head_escript + toc_shared << format_head_toc.toc_head_escript + segtoc << format_head_toc.toc_head_escript + end if defined? @md.rights.all \ and @md.rights.all rights=format_head_toc.rights.all diff --git a/lib/sisu/v3/epub_format.rb b/lib/sisu/v3/epub_format.rb index 6afae58b..1de067e4 100644 --- a/lib/sisu/v3/epub_format.rb +++ b/lib/sisu/v3/epub_format.rb @@ -1321,6 +1321,32 @@ WOK WOK + end + def sections(dob,name) + filename="#{name}#{Sfx[:epub_xhtml]}" + dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}" + segfilename="#{dir_epub_cont}/#{filename}" + output_epub_cont_seg=File.new(segfilename,'w') + output_epub_cont_seg << %{#{doc_type} + + + #{dob.obj} - + #{@md.html_title} + + +#{@css.xhtml_epub} + +#{@vz.color_body} +
+
+ +

+ #{dob.obj} +

+
+ +} +output_epub_cont_seg.close end def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map def structure @@ -1354,7 +1380,7 @@ WOK WOK end def head - depth=@md.lvs[2] + @md.lvs[3] + @md.lvs[4] + depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4] < @@ -1404,19 +1430,8 @@ WOK WOK end - def navpoint(dob,no) - id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ - ? '' \ - : "-#{no}" - < - - #{dob.obj} - - -WOK - end - def navpoint_top3(dob,no,name) + def navpoint(dob,no,name=nil) + name=name ? name : dob.name id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ ? '' \ : "-#{no}" @@ -1609,11 +1624,12 @@ WOK WOK end - def manifest_content(dob) + def manifest_content(dob,name=nil) + name=name ? name : dob.name < + WOK - end + end def manifest_images(imgs) imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png'] images=[" \n"] @@ -1642,9 +1658,10 @@ WOK WOK end - def spine(dob) + def spine(dob,name=nil) + name=name ? name : dob.name < + WOK end def spine_close @@ -1663,9 +1680,10 @@ WOK WOK end - def guide(dob) + def guide(dob,name=nil) + name=name ? name : dob.name < + WOK end def guide_close @@ -2091,8 +2109,7 @@ WOK #{@css.xhtml_epub} -#{@vz.color_body} -#{@vz.js_top}} +#{@vz.color_body}} end def toc_metadata @metalink=%{./#{@md.fn[:metadata]}} diff --git a/lib/sisu/v3/epub_segments.rb b/lib/sisu/v3/epub_segments.rb index 23af70f7..f110dfe4 100644 --- a/lib/sisu/v3/epub_segments.rb +++ b/lib/sisu/v3/epub_segments.rb @@ -168,7 +168,8 @@ WOK @@seg[:heading_idx]='' end data.each do |dob| - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==4 @@seg_name << dob.name seg_name=dob.name @@ -193,7 +194,8 @@ WOK # # end # #end #end - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==4 if dob.ocn==0 @@heading4=dob.obj @@ -201,23 +203,27 @@ WOK end @@is4=newfile=1 end - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==3 @@heading3=dob.obj @@is4,@@is3=0,1 end - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==2 @@heading2=dob.obj @@is4,@@is3,@@is2=0,0,1 end - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==1 @@heading1=dob.obj @@is4,@@is3,@@is2,@@is1=0,0,0,1 end if (@@is1 && !@@is2 && !@@is3 && !@@is4) - if not (dob.is=='heading' or dob.is=='heading_insert') \ + if not (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==1 head1=$_ #; check end @@ -227,7 +233,8 @@ WOK if newfile==1 \ or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/ newfile=0 - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==4 if tracking != 0 Seg.new(@md).tail @@ -266,8 +273,13 @@ WOK end tracking=tracking+1 end - @@get_hash_to=dob.name if (dob.is=='heading' or dob.is=='heading_insert') and dob.ln==4 and dob.name - @@get_hash_fn=dob.name if (dob.is=='heading' or dob.is=='heading_insert') and dob.ln==4 and dob.name + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ + and dob.ln==4 \ + and dob.name + @@get_hash_to=dob.name + @@get_hash_fn=dob.name + end if dob.obj.class==String markup(dob) elsif dob.obj.class==Array @@ -288,9 +300,9 @@ WOK format_head_seg=SiSU_EPUB_Format::Head_seg.new(@md) if dob.is=='heading' \ and dob.ln =~/^[1-6]/ - if @@tracker < @@seg_total-1; @@seg[:dot_nav]=format_head_seg.dot_control_pre_next - else @@seg[:dot_nav]=format_head_seg.dot_control_pre - end + @@seg[:dot_nav]= (@@tracker < @@seg_total-1) \ + ? format_head_seg.dot_control_pre_next \ + : format_head_seg.dot_control_pre end @@seg[:title]=format_head_seg.head end @@ -298,9 +310,9 @@ WOK clean=/|<:.*?>$/ format_head_seg=SiSU_EPUB_Format::Head_seg.new(@md) if @@tracker < @@seg_total-1 - if @@tracker==0; @@segtocband=format_head_seg.toc_next2 #if format_head_seg.toc_next2 - else @@segtocband=format_head_seg.toc_pre_next2 #if format_head_seg.toc_pre_next2 - end + @@segtocband=(@@tracker==0) \ + ? format_head_seg.toc_next2 \ + : format_head_seg.toc_pre_next2 else @@segtocband=format_head_seg.toc_pre2 #if format_head_seg.toc_pre2 end @p_num ||= '' @@ -377,11 +389,9 @@ WOK and dob.indent =~/[0-9]/ \ and dob.hang =~/[0-9]/ if dob.bullet_ - if dob.indent =~/[1-9]/ - sto.format('li',"i#{dob.indent}") - else - sto.format('li','bullet') - end + (dob.indent =~/[1-9]/) \ + ? sto.format('li',"i#{dob.indent}") \ + : sto.format('li','bullet') elsif dob.indent == dob.hang sto.format('p',"i#{dob.indent}") elsif dob.indent != dob.hang @@ -409,12 +419,15 @@ WOK and (not dob.ocn or dob.ocn.to_s.empty?) format_seg=SiSU_EPUB_Format::Format_seg.new(@md,dob) end - if (dob.is=='heading' or dob.is=='heading_insert' or dob.is=='para') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert' \ + || dob.is=='para') \ and dob.note_ #dob.obj =~/ \n} @@seg[:main] << dob_xhtml @@ -453,7 +466,8 @@ WOK data.each do |dob| dob.obj.gsub!(/(.+?)<\/a>/mi,'\1') if @md.flag_auto_endnotes - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln.to_s =~/^[1234]/ \ and not @@fn.to_s.empty? @@seg_endnotes[@@fn]=[] @@ -461,7 +475,8 @@ WOK @@seg_endnotes_array=[] if dob.ln==4 @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/ end - if (dob.is=='heading' or dob.is=='heading_insert') \ + if (dob.is=='heading' \ + || dob.is=='heading_insert') \ and dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs @@seg_subtoc[@@fn]=@@seg_subtoc_array @@seg_subtoc_array=[] @@ -469,10 +484,9 @@ WOK and dob.obj @@fn=dob.name else - if dob.name =~/\S+/ - @@fn=dob.name - else @@fn='' - end + @@fn=(dob.name =~/\S+/) \ + ? dob.name \ + : '' end end end diff --git a/lib/sisu/v3/param.rb b/lib/sisu/v3/param.rb index c33bab75..58d3aba9 100644 --- a/lib/sisu/v3/param.rb +++ b/lib/sisu/v3/param.rb @@ -1150,18 +1150,45 @@ module SiSU_Param @lv5 ||=/^5~/ @lv6 ||=/^6~/ else #% * + l_0=l_1=l_2=l_3=l_4=l_5='' + if defined? @make.headings[0] + l_0=if defined? @make.headings[0][0] \ + and @make.headings[0][0] =~/\S+/ + "|^#{@make.headings[0][0]}" + end + l_1=if defined? @make.headings[0][1] \ + and @make.headings[0][1] =~/\S+/ + "|^#{@make.headings[0][1]}" + end + l_2=if defined? @make.headings[0][2] \ + and @make.headings[0][2] =~/\S+/ + "|^#{@make.headings[0][2]}" + end + l_3=if defined? @make.headings[0][3] \ + and @make.headings[0][3] =~/\S+/ + "|^#{@make.headings[0][3]}" + end + l_4=if defined? @make.headings[0][4] \ + and @make.headings[0][4] =~/\S+/ + "|^#{@make.headings[0][4]}" + end + l_5=if defined? @make.headings[0][5] \ + and @make.headings[0][5] =~/\S+/ + "|^#{@make.headings[0][5]}" + end + end case para - when /^:?A~/ + when /^:?A~#{l_0}/ @lvs[1]=1 - when /^:?B~/ + when /^:?B~#{l_1}/ @lvs[2]=1 - when /^:?C~/ + when /^:?C~#{l_2}/ @lvs[3]=1 - when /^1~/ + when /^1~#{l_3}/ @lvs[4]=1 - when /^2~/ + when /^2~#{l_4}/ @lvs[5]=1 - when /^3~/ + when /^3~#{l_5}/ @lvs[6]=1 end if para =~ /^:A~/ #% processing -- cgit v1.2.3