From 58c13f49d81e3a6448a0f4dabf44b3bfb52ea84c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 1 Oct 2012 15:27:56 -0400 Subject: v3: odf, internal links/bookmarks, toc, book index --- lib/sisu/v3/odf_format.rb | 60 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'lib/sisu/v3/odf_format.rb') diff --git a/lib/sisu/v3/odf_format.rb b/lib/sisu/v3/odf_format.rb index ae5c4aec..cd998f43 100644 --- a/lib/sisu/v3/odf_format.rb +++ b/lib/sisu/v3/odf_format.rb @@ -63,8 +63,15 @@ module SiSU_ODF_Format def initialize(paranum) @paranum=/(\d+)/m.match(paranum.to_s)[1] end - def display - @paranum.gsub(/(\d+)/,' [\1]') + def set_ref_and_display + set_ref=@paranum.gsub(/(\d+)/,' ') + disp=@paranum.gsub(/(\d+)/,' [\1]') + ocn={ display: disp, set_ref: set_ref } + end + def set_bookmark_and_display + set_ref=@paranum.gsub(/(\d+)/,' ') + disp=@paranum.gsub(/(\d+)/,' [\1]') + ocn={ display: disp, set_ref: set_ref } end def name @paranum.gsub(/(\d+)/,'') @@ -73,6 +80,50 @@ module SiSU_ODF_Format @paranum.gsub(/(\d+)/,'') end end + class FormatBookIndex + def initialize(idx_str) + @idx_str=idx_str + end + def book_idx_bookmark + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + rgx_bookmark=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m + while @idx_str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m + link,url=$1,$2 + link,url=link.strip,url.strip + @idx_str=@idx_str.gsub(/&/m,"&") + ocn_lnk=if map_nametags[url] \ + and map_nametags[url][:ocn] + map_nametags[url][:ocn] + else nil + end + ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk) + if ocn_lnk and not ocn_lnk.empty? + @idx_str=@idx_str.sub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + '\1'). + sub(rgx_bookmark, + %{#{link.strip}}) + else + puts %{name tag: "#{url}" not found} + @idx_str.sub!(rgx_bookmark,"#{link}") + end + end + @idx_str=@idx_str.gsub(/#{Xx[:protect]}/m,''). + sub(/,\s*$/m,''). + gsub(/\n/,'') + @idx_str='' + @idx_str + '' + end + end + class Tags + def set_bookmark_tag(dob) + tags='' + if dob.tags.length > 0 + dob.tags.each do |tag| + tags +=%{ } + end + end + tags + end + end class FormatTextObject def initialize(md,t_o) @md,@t_o=md,t_o @@ -136,12 +187,13 @@ module SiSU_ODF_Format when 14; 'N' else 'D' end - %{#{@br}} + + tag=SiSU_ODF_Format::Tags.new.set_bookmark_tag(@dob) + %{#{@p_num[:set_ref]}#{tag}#{@br}} + %{#{@br}} end def table_close(tablefoot='') '' \ - + %{#{@p_num}} + + %{#{@p_num[:display]}} end def table_tag_cell(str,i) txt_name_cell=if i==0 \ -- cgit v1.2.3