From fec639c59a032977b87ff49920e74ae08d485f04 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 26 May 2010 13:18:31 -0400 Subject: output formats internal document (and relative) linking as possible --- lib/sisu/v2/odf.rb | 56 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'lib/sisu/v2/odf.rb') diff --git a/lib/sisu/v2/odf.rb b/lib/sisu/v2/odf.rb index dc8c90a8..24f45f50 100644 --- a/lib/sisu/v2/odf.rb +++ b/lib/sisu/v2/odf.rb @@ -236,7 +236,27 @@ module SiSU_ODF def text_link_odf(txt,url,trail) txt.gsub!(/(\\\+)/,'+') #this is convoluted, and risky :-( url.gsub!(/(\\\+)/,'+') #this is convoluted, and risky :-( - %{#{txt.strip}#{trail}} + map_nametags=SiSU_Particulars::Combined_singleton.instance.get_map_nametags(@md).nametags_map + t=case url + when /^http:/ + %{#{txt.strip}#{trail}} + when /^:/ # site same document collection html link + url.gsub!(/^:/,"#{@env.url.root}/") + %{#{txt.strip}#{trail}} + when /^\.\.\// # site same document collection html link + url.gsub!(/^\.\.\//,"#{@env.url.root}/") + %{#{txt.strip}#{trail}} + else # document internal link + if map_nametags[url] \ + and map_nametags[url][:segname] + else p "NOT FOUND name_tags: #{url}" + end + t=map_nametags[url] \ + && map_nametags[url][:segname] \ + ? %{#{txt.strip}#{trail}} \ + : %{#{txt.strip}#{trail}} + end + t end def text_link(dob) m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) #sort @@ -253,6 +273,21 @@ module SiSU_ODF end dob end + def text_link_relative(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt.gsub!(/([)(\]\[])/,"\\\\\\1") + txt.gsub!(/([+?*])/,"\\\\\\1") # problems with + + url.gsub!(/([+?])/,"\\\\\\1") # problems with + + dob.obj.gsub!(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m,text_link_odf(txt,url,trail)) #make sure trailing ']' are not caught in url + dob.obj.gsub!(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end def normal(dob) #P1 - P3 dob.obj.gsub!(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, '\1') #http ftp matches escaped, no decoration @@ -268,6 +303,13 @@ module SiSU_ODF end def fontface(dob) end + def footnote_urls(str) + str.gsub!(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) + str=text_link(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + str=text_link_relative(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + str + end def footnote(t_o) str=if defined? t_o.obj; t_o.obj elsif t_o.class==String; t_o @@ -281,6 +323,8 @@ module SiSU_ODF asterisk=str.scan(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/) asterisk.each do |x| a=x[0].gsub(/([*+])/,"\\\\\\1") + str=group_clean(str) + str=footnote_urls(str) str.gsub!(/#{Mx[:en_a_o]}(#{a})\s+(.+?)#{Mx[:en_a_c]}/,%{\\1 \\2}) @astx+=1 end @@ -289,6 +333,8 @@ module SiSU_ODF asterisk=str.scan(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/) asterisk.each do |x| a=x[0].gsub(/([*+])/,"\\\\\\1") + str=group_clean(str) + str=footnote_urls(str) str.gsub!(/#{Mx[:en_b_o]}(#{a})\s+(.+?)#{Mx[:en_b_c]}/,%{\\1 \\2}) @astx+=1 end @@ -362,10 +408,10 @@ module SiSU_ODF def odf_structure(md,dob) @md,@dob=md,dob dob=if dob.is !='code' - dob=if dob.obj =~/#{Mx[:lnk_o]}[ ]*\S+?\.(?:png|jpg|gif)\s.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/; image(dob) - elsif dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/; text_link(dob) - else dob - end + dob=image(dob) if dob.obj =~/#{Mx[:lnk_o]}[ ]*\S+?\.(?:png|jpg|gif)\s.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + dob=text_link(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + dob=text_link_relative(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + dob else dob end dob=footnote(dob) -- cgit v1.2.3