diff options
Diffstat (limited to 'lib/sisu/v0/shared_html_lite.rb')
-rw-r--r-- | lib/sisu/v0/shared_html_lite.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/sisu/v0/shared_html_lite.rb b/lib/sisu/v0/shared_html_lite.rb index 93e77db7..3c0e9ce1 100644 --- a/lib/sisu/v0/shared_html_lite.rb +++ b/lib/sisu/v0/shared_html_lite.rb @@ -50,6 +50,7 @@ module SiSU_Format_Shared require "#{SiSU_lib}/defaults" include SiSU_Viz class CSS_Format + require "#{SiSU_lib}/defaults" def initialize(content=nil,id=nil,ocnd='',ocns='',lv='',hname=nil) content.gsub!(/<:i[12]>/,'') @content=content @@ -58,14 +59,78 @@ module SiSU_Format_Shared @lv=@notenumber=lv.to_s @hname=hname.to_s @tab="\t" + @url_brace=SiSU_Viz::Skin.new.url_decoration # lots introduced to do html tables in db @@tablehead,@@tablefoot=[],[] @vz=SiSU_Env::Get_init.instance.skin 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}">[#{png}]</a>#{caption}} + else %{[#{png}] #{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 markup(para) + if para =~/\{.+?\}((?:http|ftp)\S+|image)/ + @word_mode=para.scan(/\{.+?\}(?:(?:https?|ftp)\S+|image)|\S+/) + word_mode=urls(para) + words=word_mode.join(' ') + para.gsub!(/.+/,words) + end + if (para !~/(\"\w+:\/\/\S+?\"|>\s*\w+:\/\/\w+?\S*<)/) #url markup http etc. + if para=~/\w+:\/\/\S+?\.\S+?[.,] / + para.gsub!(/(\w+:\/\/\S+?\.\S+?)([.,] )/,%{#{@url_brace.xml_open}<a href="\\1" target="_top">\\1</a>#{@url_brace.xml_close}\\2}) #full stops ! have been a bother + else + para.gsub!(/(\w+:\/\/\S+?\.\S+)/,%{#{@url_brace.xml_open}<a href="\\1" target="_top">\\1</a>#{@url_brace.xml_close}}) + 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#{@url_brace.xml_open}<a href="\\2" target="_top">\\2</a>#{@url_brace.xml_close}\\3}) #full stops ! have been a bother + else + para.gsub!(/([ ^])((?:https?|ftp):\/\/\S+)/,%{\\1#{@url_brace.xml_open}<a href="\\2" target="_top">\\2</a>#{@url_brace.xml_close}}) + end + end + para + end def paragraph %{#{@tab*1}<p class="h#@lv" id="#@ocn" type="substantive" header="#@hname">\n#{@tab*2}#@content\n#{@tab*1}</p>\n} << "\n" end def endnote + @content=markup(@content) <<GSUB #{@tab*1}<p class="endnote" name="note_#@notenumber" from="#@ocn"> #{@tab*2}<a name="_#@notenumber" href="#-#@notenumber">#@notenumber.</a> <note>#@content</note> @@ -88,12 +153,15 @@ GSUB %{#{@tab*1}<p class="norm" id="none" type="comment">\n#{@tab*2}#@content\n#{@tab*1}</p>\n} end def norm + @content=markup(@content) %{#{@tab*1}<p class="norm" id="#@ocn" type="substantive">\n#{@tab*2}#@content\n#{@tab*1}</p>\n} end def indent1 + @content=markup(@content) %{#{@tab*1}<p class="indent1" id="#@ocn" type="substantive">\n#{@tab*2}#@content\n#{@tab*1}</p>\n} end def indent2 + @content=markup(@content) %{#{@tab*1}<p class="indent2" id="#@ocn" type="substantive">\n#{@tab*2}#@content\n#{@tab*1}</p>\n} end def para_table |