aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/html_tune.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2007-06-14 10:16:51 +0100
committerRalph Amissah <ralph.amissah@gmail.com>2007-06-14 10:16:51 +0100
commit4c11eebf5ea1ce4abaeb8dc555ec1bf2cb27947e (patch)
treef85706d4725d429e61c12320a13c71a5033a300e /lib/sisu/v0/html_tune.rb
parent0.53.0, pre-build, see changelog, library naming changed for scm, placed unde... (diff)
sisu-0.54.0 (minor additions to syntax, indent range extended)sisu_0.54.0
* indent levels (1-9) added [previously two levels] done for plaintext, html, xml, odf, latex/pdf [minor syntax addition (_3 - _9), version number change] * bullet indent levels (1-9) added [previously two levels] done for plaintext, html, odf, latex/pdf [minor syntax addition (_3* - _9*), version number change] * url decoration, open close, default angle brackets <http://url> * fixes, some line-breaking for plaintext (and text groups for) odf and xml * css, modifications for extended indents in html and xml [sisu -CC (for update)] * vim syntax highlighter updated to take account of extended indent range * rant installer minor changes for future ruby * conversion script in data/sisu/conf/convert/sisu_convert
Diffstat (limited to 'lib/sisu/v0/html_tune.rb')
-rw-r--r--lib/sisu/v0/html_tune.rb98
1 files changed, 46 insertions, 52 deletions
diff --git a/lib/sisu/v0/html_tune.rb b/lib/sisu/v0/html_tune.rb
index 2d295a6c..749f5180 100644
--- a/lib/sisu/v0/html_tune.rb
+++ b/lib/sisu/v0/html_tune.rb
@@ -187,6 +187,7 @@ module SiSU_Tune
@env=SiSU_Env::Info_env.new(@md.fns)
@sys=SiSU_Env::System_call.new
@dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern
+ @env=SiSU_Env::Info_env.new(@md.fns)
#@utf8=SiSU_character_encode::UTF8 #.new
end
def songsheet
@@ -231,6 +232,45 @@ module SiSU_Tune
@tuned_file << para
end
end
+ def urls(data)
+ @words=[]
+ data.each do |word|
+ @words << if word=~/\{(.+?)\}((?:https?|ftp)\S+|image)/
+ if word =~/\{(.+?)\}((?:https?|ftp)\S+|image)([.,](?:\s|$))/
+ m,u,d=/\{(.+?)\}((?:https?|ftp)\S+|image)([.,](?:\s|$))/.match(word).captures
+ else m,u=/\{(.+?)\}((?:https?|ftp)\S+|image)/.match(word).captures
+ d=''
+ end
+ case m
+ when /\.png|\.jpg|\.gif|c=|\d+x\d+/
+ w,h=/(\d+)x(\d+)/.match(m).captures if m =~/\d+x\d+/
+ w=%{width="#{w}"} if w
+ h=%{height="#{h}"} if h
+ c=m[/"(.+?)"/m,1]
+ caption=%{<br /><p class="caption">#{c}</p>} if c
+ png=m.scan(/\S+/)[0]
+ image_path=if @md.fns =~/\.-ss[tm]$/; @env.url.images_external
+ else @env.url.images_local
+ end
+ ins=if u and u.strip !~/^image$/
+ %{<a href="#{u}"><img src="#{image_path}/#{png}" #{w} #{h} naturalsizeflag="0" align="bottom" border="0"></a>#{caption}}
+ else %{<img src="#{image_path}/#{png}" #{w} #{h} naturalsizeflag="0" align="bottom" border="0">#{caption}}
+ end
+ word.gsub!(/\{.+?\}((?:https?|ftp)\S+|image)/,ins)
+ else
+ link=m[/(.+)/m]
+ png=m.scan(/\S+/)[0].strip
+ link=link.strip
+ ins=%{<a href="#{u}">#{link}</a>#{d}}
+ word.gsub!(/\{.+?\}(?:https?|ftp)\S+/,ins)
+ end
+ word
+ else word
+ end
+ word
+ end
+ @words
+ end
def url_markup
data=@data
@tuned_file=[]
@@ -256,7 +296,7 @@ module SiSU_Tune
end
if para =~/\{.+?\}((?:http|ftp)\S+|image)/
@word_mode=para.scan(/\{.+?\}(?:(?:https?|ftp)\S+|image)|\S+/)
- word_mode=SiSU_Tune::Tune_urls.new(@word_mode,@md).urls
+ word_mode=urls(@word_mode)
words=word_mode.join(' ')
para.gsub!(/.+/,words)
end
@@ -274,20 +314,20 @@ module SiSU_Tune
para.gsub!(/<:h(.{1,7}?)>/,'<a href="#h\1">\1</a>')
para.gsub!(/<:to(\d{1,7}?)>/,'<a href="#to\1">to&nbsp;{&nbsp;\1&nbsp;}</a> ')
if (para =~/\b\S+\@\S+?\.\S+/ and para !~/(\"\S+\@\S+?\.\S+\"|>\S+\@\S+?\.\S+?<)/)
- para.gsub!(/\b(\S+\@\S+?\.\S+)(\s)/,'<a href="mailto:\1">\1</a>\\2')
+ para.gsub!(/\b(\S+\@\S+?\.\S+)(\s)/,'&lt;<a href="mailto:\1">\1</a>&gt;\2')
end
if (para !~/(\"\w+:\/\/\S+?\"|>\s*\w+:\/\/\w+?\S*<)/) #url markup http etc.
if para=~/\w+:\/\/\S+?\.\S+?[.,] /
- para.gsub!(/(\w+:\/\/\S+?\.\S+?)([.,] )/,'<a href="\1" target="_top">\1</a>\2') #full stops ! have been a bother
+ para.gsub!(/(\w+:\/\/\S+?\.\S+?)([.,] )/,'&lt;<a href="\1" target="_top">\1</a>&gt;\2') #full stops ! have been a bother
else
- para.gsub!(/(\w+:\/\/\S+?\.\S+)/, '<a href="\1" target="_top">\1</a>')
+ para.gsub!(/(\w+:\/\/\S+?\.\S+)/, '&lt;<a href="\1" target="_top">\1</a>&gt;')
end
end
if (para =~/[ ^](?:https?|ftp):\/\/\S+/) #url markup http leftovers watch carefully may accept too much 2004w46
if para=~/([ ^])((?:https?|ftp):\/\/\S+?)([\.,] )/
- para.gsub!(/([ ^])((?:https?|ftp):\/\/\S+?)([\.,] )/,'\1<a href="\2" target="_top">\2</a>\3') #full stops ! have been a bother
+ para.gsub!(/([ ^])((?:https?|ftp):\/\/\S+?)([\.,] )/,'\1&lt;<a href="\2" target="_top">\2</a>&gt;\3') #full stops ! have been a bother
else
- para.gsub!(/([ ^])((?:https?|ftp):\/\/\S+)/,'\1<a href="\2" target="_top">\2</a>')
+ para.gsub!(/([ ^])((?:https?|ftp):\/\/\S+)/,'\1&lt;<a href="\2" target="_top">\2</a>&gt;')
end
end
if (para =~/..\/\S+/ and para !~/(\"..\/\S+?\"|>\s*..\/\S+<)/)
@@ -326,51 +366,5 @@ module SiSU_Tune
@tuned_file
end
end
- class Tune_urls
- def initialize(data,md)
- @data,@md=data,md
- @vz=SiSU_Env::Get_init.instance.skin
- @env=SiSU_Env::Info_env.new(@md.fns)
- end
- def urls
- @words=[]
- @data.each do |word|
- @words << if word=~/\{(.+?)\}((?:https?|ftp)\S+|image)/
- if word =~/\{(.+?)\}((?:https?|ftp)\S+|image)([.,](?:\s|$))/
- m,u,d=/\{(.+?)\}((?:https?|ftp)\S+|image)([.,](?:\s|$))/.match(word).captures
- else m,u=/\{(.+?)\}((?:https?|ftp)\S+|image)/.match(word).captures
- d=''
- end
- case m
- when /\.png|\.jpg|\.gif|c=|\d+x\d+/
- w,h=/(\d+)x(\d+)/.match(m).captures if m =~/\d+x\d+/
- w=%{width="#{w}"} if w
- h=%{height="#{h}"} if h
- c=m[/"(.+?)"/m,1]
- caption=%{<br /><p class="caption">#{c}</p>} if c
- png=m.scan(/\S+/)[0]
- image_path=if @md.fns =~/\.-ss[tm]$/; @env.url.images_external
- else @env.url.images_local
- end
- ins=if u and u.strip !~/^image$/
- %{<a href="#{u}"><img src="#{image_path}/#{png}" #{w} #{h} naturalsizeflag="0" align="bottom" border="0"></a>#{caption}}
- else %{<img src="#{image_path}/#{png}" #{w} #{h} naturalsizeflag="0" align="bottom" border="0">#{caption}}
- end
- word.gsub!(/\{.+?\}((?:https?|ftp)\S+|image)/,ins)
- else
- link=m[/(.+)/m]
- png=m.scan(/\S+/)[0].strip
- link=link.strip
- ins=%{<a href="#{u}">#{link}</a>#{d}}
- word.gsub!(/\{.+?\}(?:https?|ftp)\S+/,ins)
- end
- word
- else word
- end
- word
- end
- @words
- end
- end
end
__END__