=begin * Name: SiSU * Description: a framework for document structuring, publishing and search * Author: Ralph Amissah * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah All Rights Reserved. * License: GPL 3 or later: SiSU, a framework for document structuring, publishing and search Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . If you have Internet connection, the latest version of the GPL should be available at these locations: * SiSU uses: * Standard SiSU markup syntax, * Standard SiSU meta-markup syntax, and the * Standard SiSU object citation numbering and system * Hompages: * Download: * Ralph Amissah ** Description: modules shared by db and flatfile output generators, mostly xml/xhtml/html formatting =end module SiSU_Format_Shared require "#{SiSU_lib}/defaults" include SiSU_Viz class CSS_Format require "#{SiSU_lib}/defaults" @@fns=nil def initialize(md,content=nil,col=nil,en=nil) content.gsub!(/<:i[12]>/,'') @md,@content=md,content @id=@ocn=col[:id] @ocnd,@ocns=col[:ocnd],col[:ocns] @notenumber=en @lv=col[:lev].to_s @@hname=if @md.fns != @@fns @@fns=@md.fns '' end @hname=if col[:seg] \ and not col[:seg].to_s.empty? @@hname=col[:seg].to_s else @@hname end @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 @env=SiSU_Env::Info_env.new(@md.fns) @base_url="#{@env.url.root}/#{@md.fnb}/#@hname.html" end def urls(data) @words=[] data.each do |word| @words << if word=~/\{(.+?)\}((?:https?|file|ftp)\S+|image)/ if word =~/\{(.+?)\}((?:https?|file|ftp)\S+|image)([;.,](?:\s|$))/ m,u,d=/\{(.+?)\}((?:https?|file|ftp)\S+|image)([;.,](?:\s|$))/.match(word).captures else m,u=/\{(.+?)\}((?:https?|file|ftp)\S+|image)/.match(word).captures d='' end word=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=%{

#{c}

} 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$/ %{[#{png}]#{caption}} else %{[#{png}] #{caption}} end word.gsub!(/\{.+?\}((?:https?|file|ftp)\S+|image)/,ins) else link=m[/(.+)/m] png=m.scan(/\S+/)[0].strip link=link.strip ins=%{#{link}#{d}} #ins=%{#{link} [link]#{d}} word.gsub!(/\{.+?\}(?:https?|file|ftp)\S+/,ins) end else word end word end @words=@words.join(' ') end def markup(para) if para !~/^<:code>/ if para =~/\{.+?\}((?:https?|file|ftp)\S+|image)/ wm=para.scan(/\{.+?\}(?:(?:https?|file|ftp)\S+|image)|\S+/) words=urls(wm) para.gsub!(/.+/m,words) end para.gsub!(/\b[_\\]((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\1\2') #http ftp matches escaped, no decoration para.gsub!(/((?:^|\s)[}])((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\1\2\3') #special case \{ e.g. \}http://url para.gsub!(/(^|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?=\s|$))/,%{\\1#{@url_brace.xml_open}\\2#{@url_brace.xml_close}\\3}) #http ftp matches with decoration else para.gsub!(/(^|[^}])_/m,'\1>') #code-block: angle brackets special characters para.gsub!(/(^|[^}])_/m,'\1>') end para end def paragraph %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} << "\n" end def endnote #used only by db @content=markup(@content) < #{@tab*2}#@notenumber. #@content #{@tab*1}

GSUB end def lev_toc_hname %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} << "\n" end def lev_toc %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} << "\n" end def lev4_plus %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} << "\n" end def lev4_minus %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} << "\n" end def norm_comment %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} end def norm @content=markup(@content) %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} end def indent1 @content=markup(@content) %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} end def indent2 @content=markup(@content) %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} end def para_table %{

} end def ocn %{#{@tab*1}

#@ocn

} << "\n" end def html_table # get rid of use html_table @new_content=[] @content.split(/\n/).each do |parablock| m=parablock[//,1] @@tablefoot</,'') @@tablehead=1 if parablock =~//, #%{

\n} + %{}) if parablock =~// tablefoot=[] @@tablefoot.each {|x| tablefoot << %{

#{x}

\n}} @@tablefoot=[] parablock.gsub!(//, %{#{@vz.table_close}\n}) # + #%{#{tablefoot}}) end if @@tablehead == 1 if parablock =~/¡¡/ parablock.gsub!(/} + %{\n') @@tablehead=0 #if parablock =~/!>/ end parablock else parablock.gsub!(/} + %{\n') parablock end @new_content << parablock end @new_content.join end end class CSS_Format_generic #does CSS_Format in one definition, needs to be told about class, despite brevity of generic, easier to see structure with CSS_Format def initialize(css_class='',content='',id=nil,ocnd=nil,ocns=nil,lv='',hname=nil) @tab="\t" @class=css_class @content=content @lv=@notenumber=lv.to_s #@ocn=ocn.to_s @hname=hname.to_s @id=@ocn=id end def paragraph css_class=%{class="#@class" } if @ocn id=%{id="#@ocn" } type=%{type="substantive" } else id=%{id="none" } type=%{type="comment" } end header=%{header="#@hname" } if @hname %{#{@tab*1}

\n#{@tab*2}#@content\n#{@tab*1}

\n} << "\n" end def para paragraph end end end __END__
} + %{#{para_table}}) parablock.gsub!(/¡¡(\d+?)¡/, %{} + %{#{para_table}}) parablock.gsub!(/!>/, '
} + %{#{para_table}}) parablock.gsub!(/¡¡(\d+?)¡/, %{} + %{#{para_table}}) parablock.gsub!(/!>/, '