=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: xml output (sax style) processing
=end
module SiSU_XML_SAX
require "#{SiSU_lib}/defaults"
require "#{SiSU_lib}/param"
include SiSU_Param
include SiSU_Viz
require "#{SiSU_lib}/sysenv"
include SiSU_Env
require "#{SiSU_lib}/dal"
require "#{SiSU_lib}/shared_xml"
require "#{SiSU_lib}/xml_format"
include SiSU_XML_format
include SiSU_XML_munge
require "#{SiSU_lib}/rexml"
include SiSU_Rexml
@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0
@@tablefoot=''
class Source
def initialize(opt)
@opt=opt
end
def read
begin
@md=SiSU_Param::Parameters.new(@opt).get
@env=SiSU_Env::Info_env.new(@opt.fns)
path=@env.path.output_tell
loc=@env.url.output_tell
tool=if @opt.cmd =~/[MV]/; "#{@env.program.web_browser} #{loc}/#{@md.fnb}/#{@md.fn[:sax]}\n\t#{@env.program.xml_viewer} #{path}/#{@md.fnb}/#{@md.fn[:sax]}"
elsif @opt.cmd =~/v/; "#{@env.program.web_browser} #{loc}/#{@md.fnb}/#{@md.fn[:sax]}"
else ''
end
SiSU_Screen::Ansi.new(@opt.cmd,'invert','XML SAX',tool).colorize unless @opt.cmd =~/q/
SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:sax]}").flow if @opt.cmd =~/[MV]/
@dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here
SiSU_XML_SAX::Source::Songsheet.new(@dal_array,@md,@env).songsheet
rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error
ensure
#file closed in songsheet
end
end
private
class Songsheet
def initialize(data,md,dir)
@data,@md,@env=data,md,dir
end
def songsheet
begin
SiSU_XML_SAX::Source::Scroll.new(@data,@md).songsheet
SiSU_XML_SAX::Source::Tidy.new(@md,@env).xml if @md.cmd =~/[vVM]/ # test wellformedness, comment out when not in use
SiSU_Rexml::Rexml.new(@md,@md.fn[:sax]).xml if @md.cmd =~/M/ # test rexml parsing, comment out when not in use #debug
rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error
ensure
end
end
end
class Scroll
require "#{SiSU_lib}/shared_txt"
require "#{SiSU_lib}/css"
include SiSU_text_utils
@@dp,@@env=nil,nil
@@xml={ :body=>[],:open=>[],:close=>[],:head=>[] }
def initialize(data='',md=nil)
@data,@md=data,md
@vz=SiSU_Env::Get_init.instance.skin
@dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern
@regx=/^(?:(?:<:p[bn]>\s*)?\d~(?:(\S+))?\s+)?(.+?)\s*<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/
@tab="\t"
@env=SiSU_Env::Info_env.new(@md.fns) if @md
@trans=SiSU_XML_munge::Trans.new(@md)
@sys=SiSU_Env::System_call.new
end
def songsheet
pre
@data=markup(@data)
post
publish
end
protected
def embedded_endntoes(para='')
para.gsub!(/~\{(\d+)\s+(.+?)\s*<#@dp>\}~/,
'\1\2 ')
para.gsub!(/~\[([*+]\d+)\s+(.+?)\s*<#@dp>\]~/,
'\1\2 ')
para.gsub!(/~\{([*+]+)\s+(.+?)\s*<#@dp>\}~/,
'\1\2 ')
end
def extract_endnotes(para='')
notes=para.scan(/~[{\[]([\d*+]+\s+.+?)\s*<#@dp>[}\]]~/)
notes.flatten.each do |e|
s=e.to_s
util=SiSU_text_utils::Wrap.new(s,70)
wrap=util.line_wrap
wrap.gsub!(/^(\d+)\s+(.+?)\s*\Z/m, <
#{@tab*2}\\1
#{@tab*2}
#{@tab*3}\\2
#{@tab*2}
#{@tab*1}
WOK
)
wrap.gsub!(/^([*+]\d+)\s+(.+?)\s*\Z/m, <
#{@tab*2}\\1
#{@tab*2}
#{@tab*3}\\2
#{@tab*2}
#{@tab*1}
WOK
)
wrap.gsub!(/^([*+]+)\s+(.+?)\s*\Z/m, <
#{@tab*2}\\1
#{@tab*2}
#{@tab*3}\\2
#{@tab*2}
#{@tab*1}
WOK
)
@endnotes << wrap
end
end
def xml_head(meta)
txt=meta.text
txt.gsub!(/ /,'')
txt.gsub!(/ & /,' and ')
el=meta.el.gsub(/\./,'_')
el_txt=meta.el.gsub(/\./,' ')
@@xml[:head] <<= if meta.type == 'meta'
<#{el_txt.capitalize}:
#{@tab}<#{el} class="#{meta.attrib}">
#{@tab*2}#{txt}
#{@tab}#{el}>
#{@tab}
WOK
else ''
end
end
def xml_sc(md='')
sc=if @md.sc_info
<
filename:
#{@md.sc_filename}
version number:
#{@md.sc_number}
version date:
#{@md.sc_date}
WOK
else ''
end
@@xml[:sc]=sc
end
def xml_structure(para='',lv='',ocn='',hname='',type='norm') #extracted endnotes
lv=lv.to_i
n=lv - 1
n3=lv + 2
lv=nil if lv == 0
extract_endnotes(para)
para.gsub!(/~[{\[]([\d*+]+)\s+(?:.+?)\s*<#@dp>[}\]]~/,'\1') #footnote/endnote clean
if para[@regx]
paragraph="#{para[@regx,2]}"
util=SiSU_text_utils::Wrap.new(paragraph,70)
wrapped=util.line_wrap
end
@@xml[:body] << if para[@regx,3]; %{#{@tab*0}