From 26767cc88c0548ad7978021796d0ccc4c9f7ffed Mon Sep 17 00:00:00 2001
From: Ralph Amissah
Date: Sat, 2 Jun 2007 11:27:06 +0100
Subject: 0.53.0, pre-build, see changelog, library naming changed for scm,
placed under v0 (instead of 0.53)
---
lib/sisu/v0/xhtml.rb | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 475 insertions(+)
create mode 100644 lib/sisu/v0/xhtml.rb
(limited to 'lib/sisu/v0/xhtml.rb')
diff --git a/lib/sisu/v0/xhtml.rb b/lib/sisu/v0/xhtml.rb
new file mode 100644
index 00000000..44293919
--- /dev/null
+++ b/lib/sisu/v0/xhtml.rb
@@ -0,0 +1,475 @@
+=begin
+ * Name: SiSU information Structuring Universe - Structured information, Serialized Units
+ * Author: Ralph Amissah
+ * http://www.jus.uio.no/sisu
+ * http://www.jus.uio.no/sisu/SiSU/download.html
+
+ * Description: xhtml output logic, flow
+
+ * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah
+
+ * License: GPL 2 or later
+
+ Summary of GPL 2
+
+ 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 2 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, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+
+ If you have Internet connection, the latest version of the GPL should be
+ available at these locations:
+ http://www.fsf.org/licenses/gpl.html
+ http://www.gnu.org/copyleft/gpl.html
+ http://www.jus.uio.no/sisu/gpl2.fsf
+
+ SiSU was first released to the public on January 4th 2005
+
+ SiSU uses:
+
+ * Standard SiSU markup syntax,
+ * Standard SiSU meta-markup syntax, and the
+ * Standard SiSU object citation numbering and system
+
+ © Ralph Amissah 1997, current 2007.
+ All Rights Reserved.
+
+ * Ralph Amissah: ralph@amissah.com
+ ralph.amissah@gmail.com
+
+ * Notes: tidy -xml scroll.xhtml >> index.tidy
+=end
+module SiSU_XHTML
+ 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[:xhtml]}\n\t#{@env.program.xml_viewer} #{path}/#{@md.fnb}/#{@md.fn[:xhtml]}"
+ elsif @opt.cmd =~/v/; "#{@env.program.web_browser} #{loc}/#{@md.fnb}/#{@md.fn[:xhtml]}"
+ else ''
+ end
+ SiSU_Screen::Ansi.new(@opt.cmd,'invert','XHTML',tool).colorize unless @opt.cmd =~/q/
+ SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:xhtml]}").flow if @opt.cmd =~/[MV]/
+ @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here
+ SiSU_XHTML::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_XHTML::Source::Scroll.new(@md,@data).songsheet
+ SiSU_XHTML::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[:xhtml]).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
+ @@xml={ :body=>[],:sisu=>[],:open=>[],:close=>[],:head=>[] }
+ require "#{SiSU_lib}/shared_txt"
+ require "#{SiSU_lib}/css"
+ include SiSU_text_utils
+ @@dp=nil
+ def initialize(md=nil,data='')
+ @md,@data=md,data
+ @vz=SiSU_Env::Get_init.instance.skin
+ @dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern
+ @regx=/^(?:(?:<:p[nb]>\s*)?\d~(?:(\S+))?\s+)?(.+?)\s*<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/
+ @tab="\t"
+ @env=SiSU_Env::Info_env.new(@md.fns)
+ @trans=SiSU_XML_munge::Trans.new(@md)
+ @sys=SiSU_Env::System_call.new
+ end
+ def songsheet
+ pre
+ markup
+ 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. \\2
+#{@tab*1}
+WOK
+)
+ wrap.gsub!(/^([*+]\d+)\s+(.+?)\s*\Z/m, <
+#{@tab*2}\\1 \\2
+#{@tab*1}
+WOK
+)
+ wrap.gsub!(/^([*+]+)\s+(.+?)\s*\Z/m, <
+#{@tab*2}\\1 \\2
+#{@tab*1}
+WOK
+)
+#KEEP alternative presentation of endnotes
+# wrap.gsub!(/^(\d+)\s+(.+?)\s*\Z/m, <
+##{@tab*2}\\1. \\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_structure_ee(para='',lv='',ocn='',hname='') #embedded endnotes
+ lv=lv.to_i
+ n=lv - 1
+ n3=lv + 2
+ lv=nil if lv == 0
+ embedded_endnotes(para)
+ if para[@regx]
+ paragraph="#{para[@regx,2]}"
+ util=SiSU_text_utils::Wrap.new(paragraph,70)
+ wrapped=util.line_wrap
+ end
+ @@xml[:body] << "#{@tab*0}" << "\n" if para[@regx]
+ 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}