aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v2/odf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v2/odf.rb')
-rw-r--r--lib/sisu/v2/odf.rb56
1 files changed, 51 insertions, 5 deletions
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 :-(
- %{<text:a xlink:type="simple" xlink:href="#{url}">#{txt.strip}</text:a>#{trail}}
+ map_nametags=SiSU_Particulars::Combined_singleton.instance.get_map_nametags(@md).nametags_map
+ t=case url
+ when /^http:/
+ %{<text:a xlink:type="simple" xlink:href="#{url}">#{txt.strip}</text:a>#{trail}}
+ when /^:/ # site same document collection html link
+ url.gsub!(/^:/,"#{@env.url.root}/")
+ %{<text:a xlink:type="simple" xlink:href="#{url}">#{txt.strip}</text:a>#{trail}}
+ when /^\.\.\// # site same document collection html link
+ url.gsub!(/^\.\.\//,"#{@env.url.root}/")
+ %{<text:a xlink:type="simple" xlink:href="#{url}">#{txt.strip}</text:a>#{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] \
+ ? %{<text:a xlink:type="simple" xlink:href="#{@env.url.root}/#{@md.fnb}/#{map_nametags[url][:segname]}#{Sfx[:html]}##{url}">#{txt.strip}</text:a>#{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]}/,
'<text:a xlink:type="simple" xlink:href="\1">\1</text:a>') #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}<text:a xlink:type="simple" xlink:href="\\1">\\1</text:a>#{@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]}/,%{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
@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]}/,%{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
@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)