diff options
author | Ralph Amissah <ralph@amissah.com> | 2012-10-01 15:27:56 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2012-10-01 15:27:56 -0400 |
commit | 58c13f49d81e3a6448a0f4dabf44b3bfb52ea84c (patch) | |
tree | f69d4a34d9c7b9b70572308f46cc3de071d0437c /lib/sisu/v3/odf_format.rb | |
parent | v3: vim syntax, sisu.vim, =\\= page new & -\\- page break (diff) |
v3: odf, internal links/bookmarks, toc, book index
Diffstat (limited to 'lib/sisu/v3/odf_format.rb')
-rw-r--r-- | lib/sisu/v3/odf_format.rb | 60 |
1 files changed, 56 insertions, 4 deletions
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+)/,' <text:span text:style-name="Span_subscript">[\1]</text:span>') + def set_ref_and_display + set_ref=@paranum.gsub(/(\d+)/,' <text:span text:style-name="Span_subscript"><text:reference-mark-start text:name="\1"/><text:reference-mark-end text:name="\1"/></text:span>') + disp=@paranum.gsub(/(\d+)/,' <text:span text:style-name="Span_subscript">[\1]</text:span>') + ocn={ display: disp, set_ref: set_ref } + end + def set_bookmark_and_display + set_ref=@paranum.gsub(/(\d+)/,' <text:span text:style-name="Span_subscript"><text:bookmark-start text:name="\1"/><text:bookmark-end text:name="\1"/></text:span>') + disp=@paranum.gsub(/(\d+)/,' <text:span text:style-name="Span_subscript">[\1]</text:span>') + ocn={ display: disp, set_ref: set_ref } end def name @paranum.gsub(/(\d+)/,'<a name="\1"></a>') @@ -73,6 +80,50 @@ module SiSU_ODF_Format @paranum.gsub(/(\d+)/,'<a href="#\1">') 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]}/, + '<text:span text:style-name="Span_bold">\1</text:span>'). + sub(rgx_bookmark, + %{<text:bookmark-ref text:reference-format="text" text:ref-name="#{url}">#{link.strip}</text:bookmark-ref>}) + 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='<text:p text:style-name="P_normal">' + @idx_str + '</text:p>' + end + end + class Tags + def set_bookmark_tag(dob) + tags='' + if dob.tags.length > 0 + dob.tags.each do |tag| + tags +=%{ <text:span text:style-name="Span_subscript"><text:bookmark-start text:name="#{tag}"/><text:bookmark-end text:name="#{tag}"/></text:span>} + 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 - %{<table:table table:name="Table#{count}" table:style-name="Table#{type}">#{@br}} + + tag=SiSU_ODF_Format::Tags.new.set_bookmark_tag(@dob) + %{<table:table table:name="Table#{count}" table:style-name="Table#{type}">#{@p_num[:set_ref]}#{tag}#{@br}} + %{<table:table-column table:style-name="Table#{type}.#{alpha}" table:number-columns-repeated="#{@dob.cols}"/>#{@br}} end def table_close(tablefoot='') '</table:table>' \ - + %{<text:p text:style-name="P_group">#{@p_num}</text:p>} + + %{<text:p text:style-name="P_group">#{@p_num[:display]}</text:p>} end def table_tag_cell(str,i) txt_name_cell=if i==0 \ |