=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: html generation, html pre-processing
=end
require "#{SiSU_lib}/param"
module SiSU_Tune
#require "#{SiSU_lib}/defaults"
require "#{SiSU_lib}/sysenv"
require "#{SiSU_lib}/param"
require "#{SiSU_lib}/html_format" #watch
include SiSU_Env
include SiSU_Screen
@@line_mode=''
@@endnote_array=[]
@@endnote_call_counter=1
@@table_align='
 \; |
'
@@table_align_close=' |
|
'
@@counter,@@column,@columns=0,0,0
class Output
def initialize(data,md)
@data,@md=data,md
@cX=SiSU_Screen::Ansi.new(@md.cmd).cX
end
def hard_output
my_make=SiSU_Env::Create_file.new(@md.cmd,@md.fns)
@filename_tune=my_make.file_tune
data=[]
@data.each{|x| x.strip; data << x if not x.empty?} #1.9 array?
data.each do |para|
@filename_tune.puts para, "\n" #if para !~/¡/
end
end
def marshal
my_make=SiSU_Env::Create_file.new(@md.cmd,@md.fns)
@marshal_tune=my_make.marshal_tune
File.open(@marshal_tune,'w') {|f| Marshal.dump(@data.to_a,f)}
end
end
class Clean_html
def initialize(html='')
@html=html
end
def clean
@html.gsub!(/¢/,'¢') # ¢
@html.gsub!(/£/,'£') # £
@html.gsub!(/¥/,'¥') # ¥
@html.gsub!(/§/,'§') # §
@html.gsub!(/©/,'©') # ©
@html.gsub!(/ª/,'ª') # ª
@html.gsub!(/«/,'«') # «
@html.gsub!(/®/,'®') # ®
@html.gsub!(/°/,'°') # °
@html.gsub!(/±/,'±') # ±
@html.gsub!(/²/,'²') # ²
@html.gsub!(/³/,'³') # ³
@html.gsub!(/µ/,'µ') # µ
@html.gsub!(/¶/,'¶') # ¶
@html.gsub!(/¹/,'¹') # ¹
@html.gsub!(/º/,'º') # º
@html.gsub!(/»/,'»') # »
@html.gsub!(/¼/,'¼') # ¼
@html.gsub!(/½/,'½') # ½
@html.gsub!(/¾/,'¾') # ¾
@html.gsub!(/×/,'×') # ×
@html.gsub!(/÷/,'÷') # ÷
@html.gsub!(/¿/,'¿') # ¿
@html.gsub!(/À/,'À') # À
@html.gsub!(/Á/,'Á') # Á
@html.gsub!(/Â/,'Â') # Â
@html.gsub!(/Ã/,'Ã') # Ã
@html.gsub!(/Ä/,'Ä') # Ä
@html.gsub!(/Å/,'Å') # Å
@html.gsub!(/Æ/,'Æ') # Æ
@html.gsub!(/Ç/,'Ç') # Ç
@html.gsub!(/È/,'È') # È
@html.gsub!(/É/,'É') # É
@html.gsub!(/Ê/,'Ê') # Ê
@html.gsub!(/Ë/,'Ë') # Ë
@html.gsub!(/Ì/,'Ì') # Ì
@html.gsub!(/Í/,'Í') # Í
@html.gsub!(/Î/,'Î') # Î
@html.gsub!(/Ï/,'Ï') # Ï
@html.gsub!(/Ð/,'Ð') # Ð
@html.gsub!(/Ñ/,'Ñ') # Ñ
@html.gsub!(/Ò/,'Ò') # Ò
@html.gsub!(/Ó/,'Ó') # Ó
@html.gsub!(/Ô/,'Ô') # Ô
@html.gsub!(/Õ/,'Õ') # Õ
@html.gsub!(/Ö/,'Ö') # Ö
@html.gsub!(/Ø/,'Ø') # Ø
@html.gsub!(/Ù/,'Ù') # Ù
@html.gsub!(/Ú/,'Ú') # Ú
@html.gsub!(/Û/,'Û') # Û
@html.gsub!(/Ü/,'Ü') # Ü
@html.gsub!(/Ý/,'Ý') # Ý
@html.gsub!(/Þ/,'Þ') # Þ
@html.gsub!(/ß/,'ß') # ß
@html.gsub!(/à/,'à') # à
@html.gsub!(/á/,'á') # á
@html.gsub!(/â/,'â') # â
@html.gsub!(/ã/,'ã') # ã
@html.gsub!(/ä/,'ä') # ä
@html.gsub!(/å/,'å') # å
@html.gsub!(/æ/,'æ') # æ
@html.gsub!(/ç/,'ç') # ç
@html.gsub!(/è/,'è') # è
@html.gsub!(/é/,'é') # é
@html.gsub!(/ê/,'ê') # ê
@html.gsub!(/ë/,'ë') # ë
@html.gsub!(/ì/,'ì') # ì
@html.gsub!(/í/,'í') # í
@html.gsub!(/î/,'î') # î
@html.gsub!(/ï/,'ï') # ï
@html.gsub!(/ð/,'ð') # ð
@html.gsub!(/ñ/,'ñ') # ñ
@html.gsub!(/ò/,'ò') # ò
@html.gsub!(/ó/,'ó') # ó
@html.gsub!(/ô/,'ô') # ô
@html.gsub!(/õ/,'õ') # õ
@html.gsub!(/ö/,'ö') # ö
@html.gsub!(/ø/,'ø') # ø
@html.gsub!(/ù/,'ù') # ú
@html.gsub!(/ú/,'ú') # û
@html.gsub!(/û/,'û') # ü
@html.gsub!(/ü/,'ü') # ý
@html.gsub!(/þ/,'þ') # þ
@html.gsub!(/ÿ/,'ÿ') # ÿ
@html.gsub!(/ý/,'ý')
@html
end
end
class Tune
@@dp=nil
def initialize(data,md)
@data,@md=data,md
@vz=SiSU_Env::Get_init.instance.skin
@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
begin
@cX=SiSU_Screen::Ansi.new(@md.cmd).cX
tell=SiSU_Screen::Ansi.new(@md.cmd,'Tune')
tell.txt_grey unless @md.cmd =~/q/
data=Tune.new(@data,@md).endnotes_html
data=Tune.new(data,@md).url_markup
if @sys.locale =~/utf-?8/i
data=Tune.new(data,@md).utf8_markup
end
if @md.cmd =~/M/ #Hard Output Tune Optional on/off here
data=Output.new(data,@md).hard_output
Output.new(data,@md).marshal
end
tuned=Tune.new(@data,@md).output
rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error
ensure
end
end
def para_numbers
data=@data
@tuned_file=[]
data.each do |para|
para.gsub!(/(\d~(\S+))/,'\1#\2. ')
@tuned_file << para
end
end
def utf8_markup
@tuned_file=[]
@data.each do |para|
#@utf8.new(para).html
#@utf8.html(@para)
if @sys.locale =~/utf-?8/i # instead ucs for utf8 #require 'iconv' ? Iñtërnâtiônàlizætiøn
#¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûü
#¢£¥§©ª«®°±²³µ¶¹º»¼½¾×÷
##para.gsub!(//, '')
##para.gsub!(//, '&;')
para=SiSU_Tune::Clean_html.new(para).clean
end
@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=%{
#{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$/
%{#{caption}}
else %{#{caption}}
end
word.gsub!(/\{.+?\}((?:https?|ftp)\S+|image)/,ins)
else
link=m[/(.+)/m]
png=m.scan(/\S+/)[0].strip
link=link.strip
ins=%{#{link}#{d}}
word.gsub!(/\{.+?\}(?:https?|ftp)\S+/,ins)
end
word
else word
end
word
end
@words
end
def url_markup
data=@data
@tuned_file=[]
data.each do |para|
para.gsub!(/<:name\#(\S+?)>/,'')
para.gsub!(/<-#>/,'')
para.gsub!(/<:p[bn]>/,'')
para.gsub!(/<(p|br)>/,'<\1 />')
para.gsub!(/<:br>/,'
')
if para =~/<::\s+/ #watch
para.gsub!(/<::\s+(\S+?)\s+!>/,
%{})
end
if para =~/<:image\s+/
para.gsub!(/<:image\s+(http\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+>/,
%{})
para.gsub!(/<:image\s+(http\S+)\s+(\S+)\s+>/,
%{})
para.gsub!(/<:image\s+(\S+)\s+(\S+)\s+(\S+)\s+>/,
%{})
para.gsub!(/<:image\s+(\S+)\s+>/,
%{})
end
if para =~/\{.+?\}((?:http|ftp)\S+|image)/
@word_mode=para.scan(/\{.+?\}(?:(?:https?|ftp)\S+|image)|\S+/)
word_mode=urls(@word_mode)
words=word_mode.join(' ')
para.gsub!(/.+/,words)
end
if (para !~/^0~/)
para.gsub!(/\\copyright/i,%{©})
if (para !~/\<:ad\s+\.\.\//)
para.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/,
%{\n\n})
else
para.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/,
%{\n\n})
end
para.gsub!(/!pick/, %{})
para.gsub!(/!new/, %{ })
para.gsub!(/<:h(.{1,7}?)>/,'\1')
para.gsub!(/<:to(\d{1,7}?)>/,'to { \1 } ')
if (para =~/\b\S+\@\S+?\.\S+/ and para !~/(\"\S+\@\S+?\.\S+\"|>\S+\@\S+?\.\S+?<)/)
para.gsub!(/\b(\S+\@\S+?\.\S+)(\s)/,'<\1>\2')
end
if (para !~/(\"\w+:\/\/\S+?\"|>\s*\w+:\/\/\w+?\S*<)/) #url markup http etc.
if para=~/\w+:\/\/\S+?\.\S+?[.,] /
para.gsub!(/(\w+:\/\/\S+?\.\S+?)([.,] )/,'<\1>\2') #full stops ! have been a bother
else
para.gsub!(/(\w+:\/\/\S+?\.\S+)/, '<\1>')
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<\2>\3') #full stops ! have been a bother
else
para.gsub!(/([ ^])((?:https?|ftp):\/\/\S+)/,'\1<\2>')
end
end
if (para =~/..\/\S+/ and para !~/(\"..\/\S+?\"|>\s*..\/\S+<)/)
para.gsub!(/(\.\.\/\S+)/,'\1')
end
para.gsub!(/([}]~)/,
' \2 ' + #note- endnote-
'\1\2 \2. \3 \4') #endnote- note- (careful may have switched)
para.gsub!(/(~\[)([*+]\d+) (.+?) <#@dp>(\]~)/,
' \2 ' + #note- endnote-
'\1\2 \2. \3 \4') #endnote- note- (careful may have switched)
para.gsub!(/(~\{)([*+]+) (.+?) <#@dp>(\}~)/,
' \2 ' + #note- endnote-
'\1\2 \2 \3 \4') #endnote- note- (careful may have switched)
@tuned_file << para
end
end
def output
data=@data
@tuned_file=[]
data.each do |para|
para.strip!
para.chomp!
@tuned_file << para
end
@tuned_file << "\n" if (@md.fns =~/\.sst0/) #remove
@tuned_file
end
end
end
__END__