From 6c3930e1c1faeee50dcde7991b7e8d63a746805c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:10:52 -0500 Subject: v5: some file renaming related to: shared files & epub, odf:odt, plaintext --- data/doc/sisu/CHANGELOG_v5 | 3 + lib/sisu/v5/concordance.rb | 4 +- lib/sisu/v5/db_import.rb | 2 +- lib/sisu/v5/dbi.rb | 2 +- lib/sisu/v5/dbi_discrete.rb | 2 +- lib/sisu/v5/epub.rb | 769 ----------- lib/sisu/v5/epub_concordance.rb | 324 ----- lib/sisu/v5/epub_format.rb | 2236 -------------------------------- lib/sisu/v5/epub_segments.rb | 543 -------- lib/sisu/v5/epub_tune.rb | 333 ----- lib/sisu/v5/html_format.rb | 2 +- lib/sisu/v5/html_lite_shared.rb | 325 +++++ lib/sisu/v5/html_scroll.rb | 2 +- lib/sisu/v5/html_segments.rb | 2 +- lib/sisu/v5/html_shared.rb | 68 + lib/sisu/v5/hub.rb | 18 +- lib/sisu/v5/manpage.rb | 4 +- lib/sisu/v5/odf.rb | 820 ------------ lib/sisu/v5/odf_format.rb | 671 ---------- lib/sisu/v5/plaintext.rb | 576 -------- lib/sisu/v5/plaintext_format.rb | 104 -- lib/sisu/v5/share_src.rb | 102 -- lib/sisu/v5/share_src_kdissert.rb | 90 -- lib/sisu/v5/shared_html.rb | 68 - lib/sisu/v5/shared_html_lite.rb | 325 ----- lib/sisu/v5/shared_sisupod_source.rb | 312 ----- lib/sisu/v5/shared_txt.rb | 236 ---- lib/sisu/v5/shared_xhtml.rb | 68 - lib/sisu/v5/shared_xml.rb | 721 ---------- lib/sisu/v5/sisupod_make.rb | 167 --- lib/sisu/v5/sitemaps.rb | 2 +- lib/sisu/v5/src_kdissert_share.rb | 90 ++ lib/sisu/v5/src_share.rb | 102 ++ lib/sisu/v5/src_shared.rb | 312 +++++ lib/sisu/v5/src_sisupod_make.rb | 167 +++ lib/sisu/v5/sst_to_s_xml_sax.rb | 4 +- lib/sisu/v5/txt_plain.rb | 576 ++++++++ lib/sisu/v5/txt_shared.rb | 242 ++++ lib/sisu/v5/wikispeak.rb | 4 +- lib/sisu/v5/xhtml.rb | 6 +- lib/sisu/v5/xhtml_epub2.rb | 769 +++++++++++ lib/sisu/v5/xhtml_epub2_concordance.rb | 324 +++++ lib/sisu/v5/xhtml_epub2_format.rb | 2236 ++++++++++++++++++++++++++++++++ lib/sisu/v5/xhtml_epub2_segments.rb | 543 ++++++++ lib/sisu/v5/xhtml_epub2_tune.rb | 333 +++++ lib/sisu/v5/xhtml_shared.rb | 68 + lib/sisu/v5/xml_dom.rb | 6 +- lib/sisu/v5/xml_fictionbook.rb | 305 ----- lib/sisu/v5/xml_odf_odt.rb | 820 ++++++++++++ lib/sisu/v5/xml_odf_odt_format.rb | 671 ++++++++++ lib/sisu/v5/xml_sax.rb | 6 +- lib/sisu/v5/xml_shared.rb | 751 +++++++++++ 52 files changed, 8433 insertions(+), 8803 deletions(-) delete mode 100644 lib/sisu/v5/epub.rb delete mode 100644 lib/sisu/v5/epub_concordance.rb delete mode 100644 lib/sisu/v5/epub_format.rb delete mode 100644 lib/sisu/v5/epub_segments.rb delete mode 100644 lib/sisu/v5/epub_tune.rb create mode 100644 lib/sisu/v5/html_lite_shared.rb create mode 100644 lib/sisu/v5/html_shared.rb delete mode 100644 lib/sisu/v5/odf.rb delete mode 100644 lib/sisu/v5/odf_format.rb delete mode 100644 lib/sisu/v5/plaintext.rb delete mode 100644 lib/sisu/v5/plaintext_format.rb delete mode 100644 lib/sisu/v5/share_src.rb delete mode 100644 lib/sisu/v5/share_src_kdissert.rb delete mode 100644 lib/sisu/v5/shared_html.rb delete mode 100644 lib/sisu/v5/shared_html_lite.rb delete mode 100644 lib/sisu/v5/shared_sisupod_source.rb delete mode 100644 lib/sisu/v5/shared_txt.rb delete mode 100644 lib/sisu/v5/shared_xhtml.rb delete mode 100644 lib/sisu/v5/shared_xml.rb delete mode 100644 lib/sisu/v5/sisupod_make.rb create mode 100644 lib/sisu/v5/src_kdissert_share.rb create mode 100644 lib/sisu/v5/src_share.rb create mode 100644 lib/sisu/v5/src_shared.rb create mode 100644 lib/sisu/v5/src_sisupod_make.rb create mode 100644 lib/sisu/v5/txt_plain.rb create mode 100644 lib/sisu/v5/txt_shared.rb create mode 100644 lib/sisu/v5/xhtml_epub2.rb create mode 100644 lib/sisu/v5/xhtml_epub2_concordance.rb create mode 100644 lib/sisu/v5/xhtml_epub2_format.rb create mode 100644 lib/sisu/v5/xhtml_epub2_segments.rb create mode 100644 lib/sisu/v5/xhtml_epub2_tune.rb create mode 100644 lib/sisu/v5/xhtml_shared.rb delete mode 100644 lib/sisu/v5/xml_fictionbook.rb create mode 100644 lib/sisu/v5/xml_odf_odt.rb create mode 100644 lib/sisu/v5/xml_odf_odt_format.rb create mode 100644 lib/sisu/v5/xml_shared.rb diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index d132b705..af0dff54 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -46,6 +46,9 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.1.0.orig.tar.xz ao (abstract objects) shorter, also easily searched, higher sort location abstract as representation of & extraction of document objects (dal (document abstraction layer)) + * shared files e.g. shared_xml becomes xml_shared + * epub becomes xhtml_epub2 + * odf becomes xml_odf_odt * xml sax file renamed xml_sax.rb (from xml.rb) * xmlns xlink using xl diff --git a/lib/sisu/v5/concordance.rb b/lib/sisu/v5/concordance.rb index 8c675e36..3bb313d4 100644 --- a/lib/sisu/v5/concordance.rb +++ b/lib/sisu/v5/concordance.rb @@ -113,8 +113,8 @@ module SiSU_Concordance private class DocTitle include SiSU_Viz - #revisit, both requires (html & shared_xml) needed for stand alone operation (sisu -w [filename]) - require_relative 'shared_xml' # shared_xml.rb + #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) + require_relative 'xml_shared' # xml_shared.rb require_relative 'html' # html.rb def initialize(particulars) @particulars,@md=particulars,particulars.md diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 8a8cc13d..dc73bbf5 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -64,7 +64,7 @@ module SiSU_DbImport require_relative 'db_columns' # db_columns.rb require_relative 'db_load_tuple' # db_load_tuple.rb require_relative 'db_sqltxt' # db_sqltxt.rb - require_relative 'shared_html_lite' # shared_html_lite.rb + require_relative 'html_lite_shared' # html_lite_shared.rb require 'sqlite3' class Import < SiSU_DbText::Prepare include SiSU_Param diff --git a/lib/sisu/v5/dbi.rb b/lib/sisu/v5/dbi.rb index e59a09b7..6a40d3ce 100644 --- a/lib/sisu/v5/dbi.rb +++ b/lib/sisu/v5/dbi.rb @@ -66,7 +66,7 @@ module SiSU_DBI include SiSU_Param require_relative 'db_dbi' # db_dbi.rb include SiSU_DbDBI - require_relative 'shared_html_lite' # shared_html_lite.rb + require_relative 'html_lite_shared' # html_lite_shared.rb include SiSU_FormatShared class SQL def initialize(opt) diff --git a/lib/sisu/v5/dbi_discrete.rb b/lib/sisu/v5/dbi_discrete.rb index 957009b1..95fb9ce3 100644 --- a/lib/sisu/v5/dbi_discrete.rb +++ b/lib/sisu/v5/dbi_discrete.rb @@ -66,7 +66,7 @@ module SiSU_DBI_Discrete #% database building include SiSU_Param require_relative 'db_dbi' # db_dbi.rb include SiSU_DbDBI - require_relative 'shared_html_lite' # shared_html_lite.rb + require_relative 'html_lite_shared' # html_lite_shared.rb include SiSU_FormatShared require 'fileutils' include FileUtils::Verbose diff --git a/lib/sisu/v5/epub.rb b/lib/sisu/v5/epub.rb deleted file mode 100644 index 5f4957aa..00000000 --- a/lib/sisu/v5/epub.rb +++ /dev/null @@ -1,769 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: epub generation, processing - -=end -module SiSU_EPUB - require 'pstore' - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'xhtml_table' # xhtml_table.rb - require_relative 'epub_format' # epub_format.rb - include SiSU_EPUB_Format - require_relative 'epub_segments' # epub_segments.rb - include SiSU_EPUB_Seg - require_relative 'epub_tune' # epub_tune.rb - include SiSU_EPUB_Tune - require_relative 'epub_concordance' # epub_concordance.rb - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - songsheet - end - def songsheet - begin - @md=@particulars.md - @fnb=@md.fnb - @env=@particulars.env - unless @opt.act[:quiet][:set]==:on - tool=(@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? "#{@env.program.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" - : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'EPUB',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'EPUB',tool).green_title_hi - if (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").flow - end - end - @env.processing_path.epub_bld #(@md) - @env.processing_path.epub_cp_images(@md) - data=nil - SiSU_Env::FileOp.new(@md).mkdir.output.epub - @tuned_file_array=SiSU_EPUB::Source::XHTML_Environment.new(@particulars).tuned_file_instructions - data=@tuned_file_array - toc=SiSU_EPUB::Source::Toc.new(@md,data).songsheet - data=@tuned_file_array - SiSU_EPUB::Source::ScrollHeadAndSegToc.new(@md,toc).in_common #watch - SiSU_EPUB::Source::Seg.new(@md,data).songsheet - SiSU_EPUB::Source::Output.new(@md).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - unless (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"] - texfiles.each do |f| - if FileTest.file?(f) - File.unlink(f) - end - end - end - SiSU_Env::Clear.new(@opt.cmd,@opt.fns).param_instantiate - @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc,@@seg_ad={},{},{},{},{},{} - @@seg_total,@@tracker,@@loop_count,@@tablehead,@@number_of_cols=0,0,0,0,0 - @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@segtocband,@@tablefoot=Array.new(7){[]} - @@filename_seg,@@seg_url,@@fn,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','','','' - @@is4=@@is3=@@is2=@@is1=@@heading1=@@heading2=@@heading3=@@heading4=0 - end - end - private - class XHTML_Environment - def initialize(particulars) - @particulars=particulars - @md,@env=particulars.md,particulars.env - @vz=SiSU_Viz::Defaults.new - @env,@css=particulars.env,SiSU_Style::CSS.new - end - def directories - SiSU_Env::FileOp.new(@md).mkdir.output.epub - end - def tuned_file_instructions - @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) - directories - ao_array=@particulars.ao_array # ao file drawn here - @tuned_file_array=SiSU_EPUB_Tune::Tune.new(ao_array,@md).songsheet - @tuned_file_array - end - end - class Endnotes - include SiSU_EPUB_Format - def initialize(md,data) - @md,@data=md,data - end - def scroll - @scr_endnotes=[] - @data.each do |dob| - pg=dob.dup - unless pg.is ==:code - if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ / - endnote_array=[] - if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m - endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m) - end - if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m - endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m) - end - if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m - endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m) - end - endnote_array.flatten.each do |note| - txt_obj={ txt: note } - format_scroll=SiSU_EPUB_Format::FormatScroll.new(@md,txt_obj) - @scr_endnotes << format_scroll.endnote_body - end - end - end - end - @scr_endnotes - end - end - class Toc - @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } - @@seg_url='' - @@firstseg=nil - def initialize(md=nil,data='') - @md,@data=md,data - @vz=SiSU_Viz::Defaults.new - @epub=SiSU_EPUB_Format::HeadInformation.new(@md) - @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md - @make=SiSU_Env::ProcessingSettings.new(@md) - end - def songsheet #extracts toc for scroll & seg - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Toc').txt_grey - end - toc=nil - @@firstseg=nil - @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } - md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] - @nav_no=0 - @s_a_no,@s_b_no,@s_c_no,@lv5_no,@lv6_no=0,0,0,0,0 - @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap - @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close - @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author - @@toc[:ncx] << @epub.toc_ncx.navmap_open - @@toc[:opf] << @epub.metadata_opf.package_open - @@toc[:opf] << @epub.metadata_opf.metadata - @@toc[:opf] << @epub.metadata_opf.manifest_open - @@toc[:seg] << %{
\n
} - @@toc[:scr] << %{
\n
} - if defined? @md.make.cover_image \ - and @md.make.cover_image.is_a?(Hash) \ - and @md.make.cover_image[:cover] =~/\S+/ - md_opf_a_content << @epub.metadata_opf.manifest_cover_image_information(@md) - md_opf_a_spine << @epub.metadata_opf.spine_cover_image - md_opf_a_guide << @epub.metadata_opf.guide_cover_image - end - md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc - if @make.build.toc? - md_opf_a_spine << @epub.metadata_opf.spine_sisu_toc - md_opf_a_guide << @epub.metadata_opf.guide_sisu_toc - end - @ncxo=[nil,false,false,false,false,false,false] - @dob_toc2,@dob_toc3=nil,nil - @ncx_cls=[] - @level_a_first_occurrence=true - @data.each do |dob| - if dob.is==:heading \ - || dob.is==:heading_insert - dob_toc=dob.dup - toc=case dob_toc.ln - when 1 - @s_a_no +=1 - lv_name='section_a' + @s_a_no.to_s - @nav_no+=1 - @nav_no2=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false,false - @epub.sections(dob_toc,lv_name) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - if @level_a_first_occurrence \ - && @make.build.toc? - @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc - @level_a_first_occurrence=false - end - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_1 - when 2 - @s_b_no +=1 - lv_name='section_b' + @s_b_no.to_s - @nav_no+=1 - @nav_no2=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false - @epub.sections(dob_toc,lv_name) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_2 - when 3 - @s_c_no +=1 - lv_name='section_c' + @s_c_no.to_s - @nav_no+=1 - @nav_no3=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false - @epub.sections(dob_toc,lv_name) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_3 - when 4 - @ncx_cls=[] - lv_name=dob_toc.name - @nav_no+=1 - @dob_name=dob.name - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncxo[4],@ncxo[5],@ncxo[6]=true,false,false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_4 - when 5 - @ncx_cls=[] - hashtag='#o' + dob_toc.ocn.to_s - lv_name=@dob_name - @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @ncxo[5],@ncxo[6]=true,false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_5 - when 6 - @ncx_cls=[] - hashtag='#o' + dob_toc.ocn.to_s - lv_name=@dob_name - @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @ncxo[6]=true - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_6 - else nil - end - toc.each do |k,d| - d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - end if toc - if @@firstseg.nil? \ - and dob.ln==4 \ - and dob.name =~/\S+/ - @@firstseg=dob.name - end - if toc - begin - @@toc[:seg] << toc[:seg] - @@toc[:scr] << toc[:seg] - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - end - end - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false - md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) - @@toc[:seg] << "
\n
" - @@toc[:scr] << "
\n
" - @@toc[:ncx] << @epub.toc_ncx.navmap_close - @@toc[:ncx] << @epub.toc_ncx.close - @@toc[:opf] << md_opf_a_content << @epub.metadata_opf.manifest_close - @@toc[:opf] << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close - @@toc[:opf] << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close - @@toc[:opf] << @epub.metadata_opf.package_close - @@toc[:opf]=@@toc[:opf].flatten - SiSU_EPUB::Source::Output.new(@md,@@toc[:opf]).epub_metadata_opf - SiSU_EPUB::Source::Output.new(@md,@@toc[:ncx]).epub_toc_ncx - @md.firstseg=@@firstseg - @@toc - end - protected - def level_1 - dob=@data - linkname,link=dob.obj.strip,dob.ocn - title=if dob.obj !~/Document Information/ - linkname - else - link='metadata' - %{#{linkname}} - end - toc={} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:seg]=if dob.name =~/^meta/ \ - and dob.obj =~/Document Information/ #check - format_toc.lev0 - else format_toc.lev1 - end - title=if dob.ocn ==0 - if dob.name =~/^meta/ \ - and dob.obj =~/Document Information/ - %{#{linkname}} - else linkname - end - else - @@toc[:scr] << '
' - link=(dob.ln) \ - ? dob.ln - : '' - %{#{linkname}} - end - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=if dob.name =~/^meta/ \ - and dob.obj =~/Document Information/ - format_toc.lev0 - else format_toc.lev1 - end - toc - end - def level_2 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - end - txt_obj={ txt: linkname } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc={} - toc[:seg]=format_toc.lev2 - if p_num - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev2 - end - toc - end - def level_3 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - end - txt_obj={ txt: linkname } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc={} - toc[:seg]=format_toc.lev3 - if p_num - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev3 - end - toc - end - def level_4 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) if ocn - if dob.ln==4 - seg_link=%{ - #{dob.obj} - } - @@seg_url=dob.name - elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/ - seg_link=dob.obj.gsub(/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/, - %{} + - %{\\1 \\2 }) - end - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) if ocn - txt_obj={ txt: seg_link } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc={} - toc[:seg]=format_toc.lev4 - title=%{#{p_num.goto}#{linkname}} if p_num - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev4 - toc - end - def level_5 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - toc={} - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - lnk_n_txt=%{ - #{linkname} - } - txt_obj={ txt: lnk_n_txt } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:seg]=format_toc.lev5 - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev5 - end - toc - end - def level_6 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - toc={} - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - lnk_n_txt=%{ - #{linkname} -} - txt_obj={ txt: lnk_n_txt } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:seg]=format_toc.lev6 - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev6 - end - toc - end - end - class ScrollHeadAndSegToc < Toc - def initialize(md='',toc='',links_guide_toc='') - @md,@toc,@links_guide_toc=md,toc,links_guide_toc - @vz=SiSU_Viz::Defaults.new - end - def in_common - toc_shared=[] - segtoc=[] - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Scroll & Segtoc').txt_grey - end - format_head_toc=SiSU_EPUB_Format::HeadToc.new(@md) - dochead=format_head_toc.head - dochead=dochead.gsub(/toc\.(html)/,'doc.\1') #kludge - toc_shared << dochead #<< ads.div.major - segtoc << format_head_toc.head #<< ads.div.major - if defined? @md.rights.all \ - and @md.rights.all - rights=format_head_toc.rights.all - rights=SiSU_EPUB_Tune::CleanXHTML.new(rights).clean - end - if defined? @md.notes.prefix_b \ - and @md.notes.prefix_b - prefix_b=format_head_toc.prefix_b - prefix_b=SiSU_EPUB_Tune::CleanXHTML.new(prefix_b).clean - end - tmp_head=nil - doc_title_endnote=@md.title.full.gsub(/(\*+)/,'\1') - tmp_head=doc_title_endnote + "\n" - txt_obj={ txt: tmp_head } - format_txt_obj=SiSU_EPUB_Format::FormatTextObject.new(@md,txt_obj) - toc_shared << format_txt_obj.center_bold - segtoc << format_txt_obj.center_bold - if defined? @md.creator.author \ - and @md.creator.author - creator_endnote=@md.creator.author.gsub(/(\*+)/,%{#{$ep[:hsp]}\\1}) - tmp_head=creator_endnote + "\n" - txt_obj={ txt: tmp_head } - format_txt_obj=SiSU_EPUB_Format::FormatTextObject.new(@md,txt_obj) - toc_shared << format_txt_obj.center_bold - segtoc << format_txt_obj.center_bold - end - tmp_head=nil - if defined? @md.prefix_a \ - and @md.prefix_a - tmp_head ||= %{#{@md.prefix_a}\n} - toc_shared << tmp_head.dup - segtoc << tmp_head.dup - end - tmp_head=nil - toc_shared << @links_guide_toc - if defined? @md.rights.all \ - and @md.rights.all - toc_shared << rights - end - if defined? @md.prefix_b \ - and @md.prefix_b - toc_shared << prefix_b - end - #Table of Contents added/appended here - toc_shared << @toc[:scr] - segtoc << @links_guide_toc - segtoc << @toc[:seg] - if defined? @md.rights.all \ - and @md.rights.all - segtoc << rights - end - if defined? @md.prefix_b \ - and @md.prefix_b - segtoc << prefix_b - end - #Segtoc tail added here - segtoc << format_head_toc.xhtml_close - segtoc=segtoc.flatten.compact #watch - SiSU_EPUB::Source::Output.new(@md).make_cover_image - SiSU_EPUB::Source::Output.new(@md,segtoc).make_segtoc - segtoc=[] - @toc[:scr],@toc[:seg]=[],[] - toc_shared - end - end - class Table < SiSU_XHTML_Table::TableXHTML - end - class Seg < SiSU_EPUB_Seg::Seg - end - class Output - def initialize(md,output='') - @md,@output=md,output - @epub_doc="#{@md.fnb}.epub" - @epub_header=SiSU_EPUB_Format::HeadInformation.new(@md) - @make=SiSU_Env::ProcessingSettings.new(@md) - @make_file=SiSU_Env::CreateFile.new(@md.fns) - end - def songsheet - mimetype - metainf_container - css - images if @md.ec[:image] - #concordance #uncomment to enable inclusion of concordance file - output_zip - end - def mimetype - out=@make_file.epub.mimetype - out<<@epub_header.mimetype - out.close - end - def metainf_container #container.xml file in META-INF directory - out=@make_file.epub.metainf_cont - out<<@epub_header.metainf_container - out.close - end - def css - out=@make_file.epub.xhtml_css - out << SiSU_EPUB_Format::CSS.new.css_epub_xhtml - out.close - end - def epub_toc_ncx - begin - out=@make_file.epub.toc_ncx - @output.each do |para| - unless para =~/\A\s*\Z/ - out.puts para - end - end - out.close - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def epub_metadata_opf - begin - out=@make_file.epub.metadata - @output.each do |para| - unless para =~/\A\s*\Z/ - out.puts para - end - end - out.close - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def images - img_pth=@md.env.path.image_source_include - img_src_pth=unless @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ - @md.file.output_path.epub.rel_image - else - pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] - pt + '/image' - end - @md.ec[:image].each do |x| - if FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ - && FileTest.file?("#{img_src_pth}/#{x}") - FileUtils::cp("#{img_src_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") - elsif FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ - && FileTest.file?("#{img_pth}/#{x}") - FileUtils::cp("#{img_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") - else STDERR.puts %{\t*WARN* did not find image - "#{x}" in #{img_src_pth} or #{img_pth} [#{__FILE__}:#{__LINE__}]} - end - end - end - def concordance - SiSU_EPUB_Concordance::Source.new(@md.opt).read - end - def output_zip - FileUtils::mkdir_p(@md.file.output_path.epub.dir) unless FileTest.directory?(@md.file.output_path.epub.dir) - if FileTest.directory?(@md.env.processing_path.epub) - pwd=Dir.pwd - Dir.chdir(@md.env.processing_path.epub) - system(" - zip -qXr9D #{@epub_doc} * - ") - FileUtils::mv(@epub_doc, @md.file.place_file.epub.dir) - Dir.chdir(pwd) - unless @md.opt.act[:maintenance][:set]==:on - FileUtils::rm_r(@md.env.processing_path.epub) - end - end - end - def make_cover_image - begin - if @md.make.cover_image? \ - and @md.make.cover_image.is_a?(Hash) \ - and @md.make.cover_image[:cover] =~/\S+/ - filename_xhtml=@make_file.epub.xhtml_cover_image - cover_image=< - - - - Cover - - - - - -
-
- - - -
-
- - -WOK - filename_xhtml.puts cover_image,"\n" - filename_xhtml.close - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def make_segtoc - begin - if @make.build.toc? - filename_xhtml=@make_file.epub.xhtml_index - @output.each do |para| - para=para.strip - unless para =~/\A\s*\Z/ - filename_xhtml.puts para,"\n" - end - end - filename_xhtml.close - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_concordance.rb b/lib/sisu/v5/epub_concordance.rb deleted file mode 100644 index ab5b272a..00000000 --- a/lib/sisu/v5/epub_concordance.rb +++ /dev/null @@ -1,324 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: epub concordance file (html concordance, wordmap, linked index - of words in document) - -=end -module SiSU_EPUB_Concordance - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'epub_format' # epub_format.rb - include SiSU_EPUB_Format - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - begin - @env,@md=@particulars.env,@particulars.md - wordmax=@env.concord_max - unless @md.wc_words.nil? - if @md.wc_words < wordmax - SiSU_EPUB_Concordance::Source::Words.new(@particulars).songsheet - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on - end - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on - SiSU_EPUB_Concordance::Source::Words.new(@particulars).songsheet - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class DocTitle - include SiSU_Viz - #revisit, both requires (html & shared_xml) needed for stand alone operation (sisu -w [filename]) - require_relative 'epub' # epub.rb - def initialize(particulars) - @particulars,@md=particulars,particulars.md - @data=SiSU_EPUB::Source::XHTML_Environment.new(particulars).tuned_file_instructions - @vz=SiSU_Viz::Defaults.new - @fnb=@md.fnb - @lex_button=%{SiSU home} - @doc_details =<#{$ep[:hsp]}

#{@md.title.full}

#{@md.creator.author}

-WOK - end - def create - @css=SiSU_Env::CSS_Stylesheet.new(@particulars.md) - format_head_toc=SiSU_EPUB_Format::HeadToc.new(@md) - dochead=format_head_toc.head - < - #{@doc_details} -

Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
[For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

-

(The word listing/index is Case sensitive: Capitalized words appear before lower case)

-

- word (number of occurences)
linked references to word within document
- [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] -

-

- (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [#{$ep[:hsp]}http://[web host]/#{@fnb}/concordance.html#your_word#{$ep[:hsp]}] -

-WOK - end - end - class Word - @@word_previous='' - def initialize(word,freq) - @word,@freq=word,freq - end - def html - w=if @word.capitalize==@@word_previous - %{\n

#{@word}

(#{@freq})

\n\t

} - else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html - %{\n

#{@word}

(#{@freq})

\n\t

} - end - @@word_previous=@word.capitalize - w - end - end - class Words - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'epub_format' # epub_format.rb - include SiSU_EPUB_Format - require_relative 'sysenv' # sysenv.rb - include SiSU_Screen - def initialize(particulars) - @particulars=particulars - begin - @vz=SiSU_Viz::Defaults.new - @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array - @path="#{@env.processing_path.epub}" - @freq=Hash.new(0) - @rxp_lv1=/^#{Mx[:lv_o]}1:/ #fix Mx[:lv_o] - @rxp_lv2=/^#{Mx[:lv_o]}2:/ #fix Mx[:lv_o] - @rxp_lv3=/^#{Mx[:lv_o]}3:/ #fix Mx[:lv_o] - @rxp_seg=/^#{Mx[:lv_o]}4:(\S+?)#{Mx[:lv_c]}/ - @rxp_title=Regexp.new("^#{Mx[:meta_o]}title#{Mx[:meta_c]}\s*(.+?)\s*$") - @rxp_t1=Regexp.new('^T1') - @rxp_t2=Regexp.new('^T2') - @rxp_t3=Regexp.new('^T3') - @rxp_excluded1=/(?:https?|file|ftp):\/\/\S+/ - @rxp_excluded0=/^(?:#{Mx[:fa_bold_o]}|#{Mx[:fa_italics_o]})?(?:to\d+|\d+| |#{Mx[:br_endnotes]}|EOF|#{Mx[:br_eof]}|thumb_\S+|snap_\S+|_+|-+|[(]?(?:ii+|iv|vi+|ix|xi+|xiv|xv|xvi+|xix|xx)[).]?|\S+?_\S+|[\d_]+\w\S+|[\w\d]{1,2}|\d{1,3}\w?|[0-9a-f]{16,64}|\d{2,3}x\d{2,3}|\S{0,2}sha\d|\S{0,3}\d{4}w\d\d|\b\w\d+|\d_all\b|e\.?g\.?)(?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})?$/mi #this regex causes and cures a stack dump in ruby 1.9 !!! - @rgx_splitlist=%r{[—.,;:-]+|#{Mx[:nbsp]}+}mi - @rgx_scanlist=%r{#{Mx[:fa_italics_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_italics_c]}|#{Mx[:fa_bold_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_bold_c]}|#{Mx[:url_o]}https?://\S+?#{Mx[:url_c]}|file://\S+|<\S+?>|\w+|[a-zA-Z]+}mi - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def songsheet - begin - #fix to use - p __LINE__.to_s + ':' + __FILE__ - p "#{@path}/content/#{@md.fn[:epub_concord]}" - p "#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" - @file_concordance=File.open("#{@path}/content/#{@md.fn[:epub_concord]}",'w') - map_para - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - @file_concordance.close - end - end - protected - def location_scroll(wordlocation,show) - @wordlocation=wordlocation - %{#{@wordlocation}; } - end - def location_seg(wordlocation,show) - @wordlocation,@show=wordlocation,show - @word_location_seg=wordlocation.gsub(/(.+?)\#(\d+)/,"\\1#{Sfx[:epub_xhtml]}#o\\2") unless wordlocation.nil? - case @wordlocation - when @rxp_t1 - %{[H]#{@show}, } - when @rxp_t2 - %{[H]#{@show}, } - when @rxp_t3 - %{[H]#{@show}, } - else %{#{@show}, } - end - end - def map_para - @seg,toy=nil,nil - @word_map={} - @ao_array.each do |line| - if defined? line.ocn - if (line.is ==:heading \ - || line.is ==:heading_insert) \ - && line.ln==4 - @seg=line.name - end - if line.ocn.to_s =~/\d+/ then toy=line.ocn.to_s - end - if toy =~/\d+/ \ - and toy !~/^0$/ - line.obj=line.obj.split(@rgx_splitlist).join(' ') #%take in word or other match - for word in line.obj.scan(@rgx_scanlist) #%take in word or other match - word=word.gsub(/#{Mx[:lnk_o]}|#{Mx[:lnk_c]}|#{Mx[:url_o]}|#{Mx[:url_c]}/,''). - gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,''). - gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). - gsub(/#{Mx[:gl_o]}#[a-z]+#{Mx[:gl_c]}/,''). - gsub(/#{Mx[:gl_o]}#[0-9]+#{Mx[:gl_c]}/,''). - gsub(/^\S$/,'') - word=nil if word.empty? - word=nil if word =~@rxp_excluded0 #watch - word=nil if word =~@rxp_excluded1 #watch - word=nil if word =~/^\S$/ - if word - word=word.gsub(/#{Mx[:br_nl]}|#{Mx[:br_line]}/,' '). - gsub(/#{Mx[:fa_o]}[a-z]{1,7}#{Mx[:fa_o_c]}|#{Mx[:fa_c_o]}[a-z]{1,7}#{Mx[:fa_c]}/,''). - gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}:[0-9a-f]{32}|[0-9a-f]{64}:[0-9a-f]{64})#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}|[0-9a-f]{64})#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:en_a_o]}(?:\d|[*+])*|#{Mx[:en_b_o]}(?:\d|[*+])*|#{Mx[:en_a_c]}|#{Mx[:en_b_c]}/mi,''). - gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,'').gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). - gsub(/<\/?\S+?>/,''). - gsub(/^\@+/,''). - strip. - gsub(/#{Mx[:tc_p]}.+/,''). - gsub(/[\.,;:"]$/,''). - gsub(/["]/,''). - gsub(/^\s*[\(]/,''). - gsub(/[\(]\s*$/,''). - gsub(/^(?:See|e\.?g\.?).+/,''). - gsub(/^\s*[.,;:]\s*/,''). - strip. - gsub(/^\(?[a-zA-Z]\)$/,''). - gsub(/^\d+(st|nd|rd|th)$/,''). - gsub(/^(\d+\.?)+$/, ''). - gsub(/#{Mx[:mk_o]}|#{Mx[:mk_c]}/,''). - gsub(/:name#\S+/,''). - gsub(/^\S$/,'') - word=nil if word =~/^\S$/ - word=nil if word =~/^\s*$/ #watch - if word - unless word =~/[A-Z][A-Z]/ \ - or word =~/\w+\s\w+/ - word=word.capitalize - end - @freq[word] +=1 - @word_map[word] ||= [] - if line !~@rxp_lv1 \ - and line !~@rxp_lv2 \ - and line !~@rxp_lv3 - @word_map[word] << location_seg("#{@seg}\##{toy}",toy) - else - @word_map[word] << case line - when @rxp_lv1; location_seg('T1',toy) - when @rxp_lv2; location_seg('T2',toy) - when @rxp_lv3; location_seg('T3',toy) - end - end - end - end - end - end - end - end - seg='' - @file_concordance << SiSU_EPUB_Concordance::Source::DocTitle.new(@particulars).create - alph=%W[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] - @file_concordance << '

' - alph.each {|x| @file_concordance << %{#{x},#{$ep[:hsp]}}} - @file_concordance << '

' - letter=alph.shift - @file_concordance << %{\n

A

} - for word in @freq.keys.sort! {|a,b| a.downcase<=>b.downcase} - f=/^(\S)/.match(word)[1] - if letter < f.upcase - while letter < f.upcase - if alph.length > 0 - letter=alph.shift - @file_concordance << %{\n

#{letter}

} - else break - end - end - end - keyword=SiSU_EPUB_Concordance::Source::Word.new(word,@freq[word]).html - if keyword !~ @rxp_excluded0 - if @word_map[word][0] =~ /\d+/ - @file_concordance << %{#{keyword}#{seg}#{@word_map[word].uniq.compact.join}} - end - @file_concordance << '

' - end - # special cases endnotes and header levels 1 - 3 - end - credits=@vz.credits_sisu_epub - @file_concordance << %{>#{credits}\n} # footer - end - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_format.rb b/lib/sisu/v5/epub_format.rb deleted file mode 100644 index 1c57cd20..00000000 --- a/lib/sisu/v5/epub_format.rb +++ /dev/null @@ -1,2236 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: epub formating, css template - -=end -module SiSU_EPUB_Format - include SiSU_Viz - class ParagraphNumber - def initialize(md,ocn) - @md,@ocn=md,ocn.to_s - @ocn ||='' - end - def ocn_display - make=SiSU_Env::ProcessingSettings.new(@md) - if make.build.ocn? - ocn_class='ocn' - if @ocn==nil \ - or @ocn.to_i==0 \ - or @ocn.empty? - %{} - else - @ocn.gsub(/^(\d+|)$/, - %{}) - end - else - %{} - end - end - def name - (@ocn==nil || @ocn.empty?) ? '' : %{} - end - def id #w3c? "tidy" complains about numbers as identifiers ! annoying - (@ocn==nil || @ocn.empty?) ? '' : %{id="o#{@ocn}"} - end - def goto - (@ocn==nil || @ocn.empty?) ? '' : %{} - end - end - class CSS - def css_epub_xhtml - <<-WOK -/* SiSU epub css default stylesheet */ - body { - color: black; - background: #ffffff; - background-color: #ffffff; - } -/* - table { - margin-left: 5%; - display: block; - } - tr { - display: block; - } - th,td { - display: inline; - vertical-align: top; - } -*/ - a:link { - color: #003399; - text-decoration: none; - } - a:visited { - color: #003399; - text-decoration: none; - } - a:hover { - color: #000000; - background-color: #f9f9aa; - } -/* - a:hover { - border-bottom: 2px solid #777777; - background-color: #fff3b6; - } -*/ - a:hover img { - background-color: #ffffff; - } - a:active { - color: #003399; - text-decoration: underline; - } - a.lnkocn:link { - color: #777777; - text-decoration: none; - } - div { - margin-left: 0; - margin-right: 0; - } - div.p { - margin-left: 5%; - margin-right: 1%; - } - - .norm, .bold, .verse, .group, .block, .alt { - line-height: 133%; - margin-left: 0em; - margin-right: 2em; - margin-top: 12px; - margin-bottom: 0px; - padding-left: 0em; - text-indent: 0mm; - } - p, h0, h1, h2, h3, h4, h5, h6 { - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-size: 100%; - font-weight: normal; - line-height: 133%; - text-align: justify; - margin-left: 0em; - margin-right: 2em; - text-indent: 0mm; - margin-top: 0.8em; - margin-bottom: 0.8em; - } - p.norm { } - p.i1 {padding-left: 1em;} - p.i2 {padding-left: 2em;} - p.i3 {padding-left: 3em;} - p.i4 {padding-left: 4em;} - p.i5 {padding-left: 5em;} - p.i6 {padding-left: 6em;} - p.i7 {padding-left: 7em;} - p.i8 {padding-left: 8em;} - p.i9 {padding-left: 9em;} - - p.h0i0 { - padding-left: 0em; - text-indent: 0em; - } - p.h0i1 { - padding-left: 1em; - text-indent: -1em; - } - p.h0i2 { - padding-left: 2em; - text-indent: -2em; - } - p.h0i3 { - padding-left: 3em; - text-indent: -3em; - } - p.h0i4 { - padding-left: 4em; - text-indent: -4em; - } - p.h0i5 { - padding-left: 5em; - text-indent: -5em; - } - p.h0i6 { - padding-left: 6em; - text-indent: -6em; - } - p.h0i7 { - padding-left: 7em; - text-indent: -7em; - } - p.h0i8 { - padding-left: 8em; - text-indent: -8em; - } - p.h0i9 { - padding-left: 9em; - text-indent: -9em; - } - - p.h1i0 { - padding-left: 0em; - text-indent: 1em; - } - p.h1i1 { - padding-left: 1em; - text-indent: 0em; - } - p.h1i2 { - padding-left: 2em; - text-indent: -1em; - } - p.h1i3 { - padding-left: 3em; - text-indent: -2em; - } - p.h1i4 { - padding-left: 4em; - text-indent: -3em; - } - p.h1i5 { - padding-left: 5em; - text-indent: -4em; - } - p.h1i6 { - padding-left: 6em; - text-indent: -5em; - } - p.h1i7 { - padding-left: 7em; - text-indent: -6em; - } - p.h1i8 { - padding-left: 8em; - text-indent: -7em; - } - p.h1i9 { - padding-left: 9em; - text-indent: -8em; - } - - p.h2i0 { - padding-left: 0em; - text-indent: 2em; - } - p.h2i1 { - padding-left: 1em; - text-indent: 1em; - } - p.h2i2 { - padding-left: 2em; - text-indent: 0em; - } - p.h2i3 { - padding-left: 3em; - text-indent: -1em; - } - p.h2i4 { - padding-left: 4em; - text-indent: -2em; - } - p.h2i5 { - padding-left: 5em; - text-indent: -3em; - } - p.h2i6 { - padding-left: 6em; - text-indent: -4em; - } - p.h2i7 { - padding-left: 7em; - text-indent: -5em; - } - p.h2i8 { - padding-left: 8em; - text-indent: -6em; - } - p.h2i9 { - padding-left: 9em; - text-indent: -7em; - } - - p.h3i0 { - padding-left: 0em; - text-indent: 3em; - } - p.h3i1 { - padding-left: 1em; - text-indent: 2em; - } - p.h3i2 { - padding-left: 2em; - text-indent: 1em; - } - p.h3i3 { - padding-left: 3em; - text-indent: 0em; - } - p.h3i4 { - padding-left: 4em; - text-indent: -1em; - } - p.h3i5 { - padding-left: 5em; - text-indent: -2em; - } - p.h3i6 { - padding-left: 6em; - text-indent: -3em; - } - p.h3i7 { - padding-left: 7em; - text-indent: -4em; - } - p.h3i8 { - padding-left: 8em; - text-indent: -5em; - } - p.h3i9 { - padding-left: 9em; - text-indent: -6em; - } - - p.h4i0 { - padding-left: 0em; - text-indent: 4em; - } - p.h4i1 { - padding-left: 1em; - text-indent: 3em; - } - p.h4i2 { - padding-left: 2em; - text-indent: 2em; - } - p.h4i3 { - padding-left: 3em; - text-indent: 1em; - } - p.h4i4 { - padding-left: 4em; - text-indent: 0em; - } - p.h4i5 { - padding-left: 5em; - text-indent: -1em; - } - p.h4i6 { - padding-left: 6em; - text-indent: -2em; - } - p.h4i7 { - padding-left: 7em; - text-indent: -3em; - } - p.h4i8 { - padding-left: 8em; - text-indent: -4em; - } - p.h4i9 { - padding-left: 9em; - text-indent: -5em; - } - - p.h5i0 { - padding-left: 0em; - text-indent: 5em; - } - p.h5i1 { - padding-left: 1em; - text-indent: 4em; - } - p.h5i2 { - padding-left: 2em; - text-indent: 3em; - } - p.h5i3 { - padding-left: 3em; - text-indent: 2em; - } - p.h5i4 { - padding-left: 4em; - text-indent: 1em; - } - p.h5i5 { - padding-left: 5em; - text-indent: 0em; - } - p.h5i6 { - padding-left: 6em; - text-indent: -1em; - } - p.h5i7 { - padding-left: 7em; - text-indent: -2em; - } - p.h5i8 { - padding-left: 8em; - text-indent: -3em; - } - p.h5i9 { - padding-left: 9em; - text-indent: -4em; - } - - p.h6i0 { - padding-left: 0em; - text-indent: 6em; - } - p.h6i1 { - padding-left: 1em; - text-indent: 5em; - } - p.h6i2 { - padding-left: 2em; - text-indent: 4em; - } - p.h6i3 { - padding-left: 3em; - text-indent: 3em; - } - p.h6i4 { - padding-left: 4em; - text-indent: 2em; - } - p.h6i5 { - padding-left: 5em; - text-indent: 1em; - } - p.h6i6 { - padding-left: 6em; - text-indent: 0em; - } - p.h6i7 { - padding-left: 7em; - text-indent: -1em; - } - p.h6i8 { - padding-left: 8em; - text-indent: -2em; - } - p.h6i9 { - padding-left: 9em; - text-indent: -3em; - } - - p.h7i0 { - padding-left: 0em; - text-indent: 7em; - } - p.h7i1 { - padding-left: 1em; - text-indent: 6em; - } - p.h7i2 { - padding-left: 2em; - text-indent: 5em; - } - p.h7i3 { - padding-left: 3em; - text-indent: 4em; - } - p.h7i4 { - padding-left: 4em; - text-indent: 3em; - } - p.h7i5 { - padding-left: 5em; - text-indent: 2em; - } - p.h7i6 { - padding-left: 6em; - text-indent: 1em; - } - p.h7i7 { - padding-left: 7em; - text-indent: 0em; - } - p.h7i8 { - padding-left: 8em; - text-indent: -1em; - } - p.h7i9 { - padding-left: 9em; - text-indent: -2em; - } - - p.h8i0 { - padding-left: 0em; - text-indent: 8em; - } - p.h8i1 { - padding-left: 1em; - text-indent: 7em; - } - p.h8i2 { - padding-left: 2em; - text-indent: 6em; - } - p.h8i3 { - padding-left: 3em; - text-indent: 5em; - } - p.h8i4 { - padding-left: 4em; - text-indent: 4em; - } - p.h8i5 { - padding-left: 5em; - text-indent: 3em; - } - p.h8i6 { - padding-left: 6em; - text-indent: 2em; - } - p.h8i7 { - padding-left: 7em; - text-indent: 1em; - } - p.h8i8 { - padding-left: 8em; - text-indent: 0em; - } - p.h8i9 { - padding-left: 9em; - text-indent: -1em; - } - - p.h9i0 { - padding-left: 0em; - text-indent: 9em; - } - p.h9i1 { - padding-left: 1em; - text-indent: 8em; - } - p.h9i2 { - padding-left: 2em; - text-indent: 7em; - } - p.h9i3 { - padding-left: 3em; - text-indent: 6em; - } - p.h9i4 { - padding-left: 4em; - text-indent: 5em; - } - p.h9i5 { - padding-left: 5em; - text-indent: 4em; - } - p.h9i6 { - padding-left: 6em; - text-indent: 3em; - } - p.h9i7 { - padding-left: 7em; - text-indent: 2em; - } - p.h9i8 { - padding-left: 8em; - text-indent: 1em; - } - p.h9i9 { - padding-left: 9em; - text-indent: 0em; - } - - p.it0 { - margin-left: 0em; - margin-top: 6px; - margin-bottom: 0px; - line-height: 100%; - } - p.it1 { - margin-left: 1em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it2 { - margin-left: 2em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it3 { - margin-left: 3em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it4 { - margin-left: 4em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it5 { - margin-left: 5em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it6 { - margin-left: 6em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it7 { - margin-left: 7em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it8 { - margin-left: 8em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it9 { - margin-left: 9em; - margin-bottom: 0px; - margin-top: 0px; - line-height: 100%; - } - - p.group { } - - p.block { } - - p.alt { } - - p.verse { - margin-bottom: 6px; - } - - p.code { - font-family: inconsolata, andale mono, courier new, courier, monospace; - font-size: 90%; - text-align: left; - background-color: #eeeeee; - } - - p.caption { - text-align: left; - font-size: 80%; - display: inline; - } - - p.endnote { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-right: 2em; - } - p.endnote_indent { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-left: 2em; - margin-right: 2em; - } - - p.center { - text-align: center; - } - p.align_right { - text-align: right; - } - p.bold { - font-weight: bold; - } - p.bold_left { - font-weight: bold; - text-align: left; - } - p.centerbold { - text-align: center; - font-weight: bold; - } - p.em { - font-weight: bold; - font-style: normal; - background: #fff3b6; - } - - p.small { - font-size: 80%; - margin-top: 0px; - margin-bottom: 0px; - margin-right: 6px; - text-align: left; - } - - .tiny, .tiny_left, .tiny_right, .tiny_center { - font-size: 10px; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 6px; - text-align: left; - } - p.tiny { } - p.tiny_left { - margin-left: 0px; - margin-right: 0px; - text-align: left; - } - p.tiny_right { - margin-right: 1em; - text-align: right; - } - p.tiny_center { - margin-left: 0px; - margin-right: 0px; - text-align: center; - } - - p.concordance_word { - line-height: 150%; - font-weight: bold; - display: inline; - margin-top: 4px; - margin-bottom: 1px; - } - p.concordance_count { - font-size: 80%; - color: #777777; - display: inline; - margin-left: 0em; - } - p.concordance_object { - font-size: 80%; - line-height: 120%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - p.book_index_lev1 { - line-height: 100%; - margin-top: 4px; - margin-bottom: 1px; - } - p.book_index_lev2 { - line-height: 100%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - - p.quickref { - font-size: 10px; - font-style: italic; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 5px; - text-align: left; - } - p.bigref { - font-size: 11px; - font-weight: bold; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 5px; - text-align: center; - } - - p.letter { - font-weight: bold; - font-size: 80%; - margin-left: 0em; - margin-top: 2px; - margin-bottom: 2px; - margin-right: 6px; - text-align: left; - color: white; - background: #880000; - } - - tt { - font-family: inconsolata, andale mono, courier new, courier, monospace; - background-color: #eeeeee; - } - - label.ocn { - width: 2%; - float: right; - top: 0; - font-size: 10px; - margin-top: 0px; - margin-bottom: 5px; - color: #777777; - margin-right: 5px; - text-align: right; - background-color: #ffffff; - } - - table { } - tr { } - th,td { - vertical-align: top; - text-align: left; - } - th { - font-weight: bold; - } - - p.left, th.left, td.left { - text-align: left; - } - p.small_left, th.small_left, td.small_left { - text-align: left; - font-size: 80%; - } - p.right, th.right, td.right { - text-align: right; - } - - #horizontal_links { - background: #eeeeee; - margin-left: 5%; - margin-right: 5%; - } - #horizontal { - margin: 0; - padding: 0 0 0 10px; - border-top: 1px solid #000077; - border-bottom: 1px solid #000077; - } - #horizontal li { - margin: 0 0 0 0; - padding: 0 16px 0 0; - display: inline; - list-style-type: none; - text-align: left; - background: none; - } - #horizontal a { - line-height: 12px; - margin: 0 0 0 0; - text-decoration: none; - color: #000077; - } - #horizontal a.active, #horizontal a:hover { - border-bottom: 2px solid #777777; - padding-bottom: 2px; - color: #000077; - } - #horizontal a:hover { - color: #000077; - } - - #document_versions { - position: absolute; - top: 10mm; - right: 2%; - width: 12%; - float: right; - } - - #vertical_links { - position: absolute; - top: 10mm; - right: 0px; - width: 20%; - background: #dddddd; - float: right; - } - #vertical { - padding: 0 12px 0px 0px; - margin-left: 2%; - margin-right: 2%; - } - #vertical li { - display: block; - list-style-type: none; - } - #vertical a { - line-height: 12px; - text-decoration: none; - color: #000077; - } - #vertical a.active, #vertical a:hover { - border-bottom: 2px solid #777777; - padding-bottom: 2px; - color: #000077; - } - - ul, li { - list-style-type: none; - list-style: none; - padding-left: 20px; - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-weight: normal; - line-height: 150%; - text-align: justify; - text-indent: 0mm; - margin-left: 1em; - margin-right: 2em; - margin-top: 3px; - margin-bottom: 3px; - } - - li { - background: url(../image/bullet_09.png) no-repeat 0px 6px; - } - - ul { - } - li.bullet { margin-left: 0em; } - li.i1 { margin-left: 1em; } - li.i2 { margin-left: 2em; } - li.i3 { margin-left: 3em; } - li.i4 { margin-left: 4em; } - li.i5 { margin-left: 5em; } - li.i6 { margin-left: 6em; } - li.i7 { margin-left: 7em; } - li.i8 { margin-left: 8em; } - li.i9 { margin-left: 9em; } - - li.doc, li.ref, li.refcenter { - margin-top: 0px; - margin-bottom: 0px; - margin-right: 0px; - font-size: 8px; - font-style: normal; - text-align: left; - } - li.doc { - background: url(../image/bullet_09.png) no-repeat 0px 6px; - padding-left: 16px; - margin-left: 10px; - margin-right: 0px; - } - li.ref { - background: none; - padding-left: 0; - margin-left: 0; - color: #777777; - } - li.refcenter { - background: url(../image/bullet_09.png) no-repeat 0px 6px; - padding-left: 20px; - margin-left: 10%; - font-size: 9px; - color: #777777; - text-align: center; - } - li.refbold { - list-style-type: none; - padding-left: 16px; - margin-left: 0; - margin-right: 10mm; - font-weight: bold; - } - - h0, h1, h2, h3, h4, h5, h6 { - font-weight: bold; - line-height: 120%; - text-align: left; - margin-top: 20px; - margin-bottom: 10px; - } - h4.norm, h5.norm, h6.norm { - margin-top: 10px; - margin-bottom: 0px; - } - h1.center, h2.center, h3.center, h4.center, h5.center, h6.center { - text-align: center; - } - h1 { font-size: 120%; } - h2 { font-size: 115%; } - h3 { font-size: 110%; } - h4 { font-size: 105%; } - h5 { font-size: 100%; } - h6 { font-size: 100%; } - h0 { font-size: 80%; } - - h1.i {margin-left: 2em;} - h2.i {margin-left: 3em;} - h3.i {margin-left: 4em;} - h4.i {margin-left: 5em;} - h5.i {margin-left: 6em;} - h6.i {margin-left: 7em;} - h7.i {margin-left: 8em;} - h8.i {margin-left: 9em;} - h9.i {margin-left: 10em;} - - .toc { - font-weight: normal; - margin-top: 6px; - margin-bottom: 6px; - } - h1.toc { - margin-left: 1em; - font-size: 115%; - line-height: 150%; - } - h2.toc { - margin-left: 2em; - font-size: 110%; - line-height: 140%; - } - h3.toc { - margin-left: 3em; - font-size: 105%; - line-height: 120%; - } - h4.toc { - margin-left: 4em; - font-size: 100%; - line-height: 120%; - } - h5.toc { - margin-left: 5em; - font-size: 95%; - line-height: 110%; - } - h6.toc { - margin-left: 6em; - font-size: 90%; - line-height: 110%; - } - - .microtoc { - margin-top: 2px; - margin-bottom: 2px; - } - - h1.microtoc { - margin-left: 0mm; - font-size: 115%; - } - h2.microtoc { - margin-left: 5mm; - font-size: 110%; - } - h3.microtoc { - margin-left: 10mm; - font-size: 105%; - } - h4.microtoc { - margin-left: 15mm; - font-weight: normal; - font-size: 100%; - } - h5.microtoc { - margin-left: 20mm; - font-weight: normal; - font-size: 95%; - } - h6.microtoc { - margin-left: 25mm; - font-weight: normal; - font-size: 90%; - } - - .subtoc { - margin-right: 34%; - font-weight: normal; - } - h5.subtoc { - margin-left: 2em; - font-size: 80%; - margin-top: 2px; - margin-bottom: 2px; - } - h6.subtoc { - margin-left: 3em; - font-size: 75%; - margin-top: 0px; - margin-bottom: 0px; - } - - div.substance { - width: 100%; - background-color: #ffffff; - } - div.ocn { - width: 5%; - float: right; - top: 0; - background-color: #ffffff; - } - div.endnote { - width: 100%; - background-color: #fffffff; - } - div.toc { - position: absolute; - float: left; - margin: 0; - padding: 0; - padding-top: 0.5em; - border: 0; - width: 5%; - background-color: #eeeeee; - margin-right:1em; - } - div.summary { - margin: 0; - padding: 0; - border-left: 2em solid #eeeeee; - padding-left: 0em; - background-color: #eeeeee; - } - div.content, div.main_column { - margin: 0; - padding: 0; - border-left: 0% solid #ffffff; - padding-left: 5%; - } - div.content:after { - content:' '; - clear:both; - display:block; - height:0; - overflow:hidden - } - div.footer { - clear:left; - padding: 0.5em; - font-size: 80%; - margin: 0; - } - div.toc ul { - list-style: none; - padding: 0; - margin: 0; - } - div.toc li ul a, li ul span.currentlink - { - font-weight: normal; - font-size: 90%; - padding-left: 2em; - background-color: #eeeeee; - } - div.toc a, span.currentlink{ - display:block; - text-decoration: none; - padding-left: 0.5em; - color: #0000aa; - } - hr { - width: 90%; - } - - span.currentlink { - text-decoration: none; - background-color: #aaaaf9; - } - - div.toc a:visited { - color: #0000aa; - } - div.toc a:hover { - color: #000000; - background-color: #f9f9aa; - } - - h1.c, h2.c, h3.c, h4.c, h5.c, h6.c, p.c { - text-align: center - } - h1.red, h2.red, h3.red, h4.red, h5.red, h6.red { - text-align: center; - color: #ff0000; - margin-left: 5mm; - text-indent: 5mm; - margin-top: 30px; - margin-bottom: 20px; - margin-right: 15mm; - } - h1.ruby, h2.ruby, h3.ruby, h4.ruby, h5.ruby, h6.ruby { - text-align: center; - color: #990000; - margin-left: 5mm; - text-indent: 5mm; - margin-top: 30px; - margin-bottom: 20px; - margin-right: 15mm; - } - WOK - end - end - module SanitizeXML - def self.xml(x) - if x.is_a?(String) - x=x.gsub(/ /,' ') if Ep[:alt]==:on - x.gsub(/&/,'&'). - gsub(//,">"). - gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). - #gsub(//,'>'). - gsub(/\\\\/,'
'). - gsub(/<br(?: \/)?>/,'
') - else x - end - end - end - class HeadInformation - include SiSU_Viz - attr_reader :md,:rdf,:vz - def initialize(md) - @md=md - # DublinCore 1 - title - @vz=SiSU_Viz::Defaults.new - @css=SiSU_Env::CSS_Stylesheet.new(md) - @seg_name_xhtml=(SiSU_EPUB::Source::Seg.new.seg_name_xhtml || []) - @seg_name_xhtml_tracker=(SiSU_EPUB::Source::Seg.new.seg_name_xhtml_tracker || []) - @tocband_scroll,@tocband_segtoc=nil,nil - @index,@metalink='index','#metadata' - end - def doc_type_xhtml - <<-WOK - - - WOK - end -=begin -~/epub - |-- META-INF - | `-- container.xml # simple, make sure full-path of rootfile points to metadata.opf - |-- content - | |-- 1.xhtml - | |-- 2.xhtml - | |-- 3.xhtml - | |-- ... .xhtml - | |-- concordance.xhtml - | |-- css - | | `-- xhtml.css - | |-- endnotes.xhtml - | |-- image - | | |-- arrow_next_red.png - | | |-- arrow_prev_red.png - | | |-- arrow_up_red.png - | | `-- bullet_09.png - | |-- index.xhtml - | |-- meta.xhtml - | |-- metadata.xhtml - | `-- toc.xhtml - |-- metadata.opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) - |-- mimetype # application/epub+zip - `-- toc.ncx #(i) head (ii) doc title (iii) navmap, list of navigation points (like chapters) -=end - def doc_type - doc_type_xhtml - end - def mimetype - <<-WOK -application/epub+zip - WOK - end - def metainf_container #container.xml file in META-INF directory - #simple, make sure full-path of rootfile points to metadata.opf - #epub_metadata.opf content.opf - <<-WOK - - - - - - - WOK - end - def sections(dob,fn_base) - name=fn_base + Sfx[:epub_xhtml] - dir_epub_cont=@md.env.processing_path.epub + '/' + Ep[:d_oebps] - segfilename=dir_epub_cont + '/' + name - output_epub_cont_seg=File.new(segfilename,'w') - output_epub_cont_seg << %{#{doc_type} - - - #{dob.obj} - - #{@md.html_title} - - - #{@css.xhtml_epub} - - #{@vz.color_body} -
-
- #{dob.ocn} -

- #{dob.obj} -

-
-
- - } -output_epub_cont_seg.close - end - def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map - def structure - open - head_open - head - head_close - doc_title - doc_author - navmap_open - #navmap ... - navmap_close - close - end - def open - <<-WOK - - - WOK - end - def close - <<-WOK - - WOK - end - def head_open - <<-WOK - - WOK - end - def head - depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4] - title=SanitizeXML.xml(@md.title.full) - author=SanitizeXML.xml(@md.author) - <<-WOK - - #{title} by #{author} - - - - - - - WOK - end - def head_close - <<-WOK - - WOK - end - def doc_title - txt=SanitizeXML.xml(@md.title.full) - <<-WOK - - #{txt} - - WOK - end - def doc_author - txt=SanitizeXML.xml(@md.author) - <<-WOK - - #{txt} - - WOK - end - def navmap_open - <<-WOK - - WOK - end - def navmap_sisu_toc(no) - id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ - ? '' - : "-#{no}" - <<-WOK - - - Table of Contents - - - - WOK - end - def navpoint(dob,no,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ - ? '' - : "-#{no}" - <<-WOK - - - #{dob.obj} - - - WOK - end - def navpoint_close - <<-WOK - - WOK - end - def navmap_close - <<-WOK - - WOK - end - self - end - def metadata_opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) - def structure - package_open - metadata_open - metadata_close - manifest_open - manifest_close - spine_open - spine_close - guide_open - guide_close - package_close - end - def package_open - <<-WOK - - - WOK - end - def package_close - <<-WOK - - WOK - end - def metadata #metadata dc - cover_image=if defined? @md.make.cover_image \ - and @md.make.cover_image.is_a?(Hash) \ - and @md.make.cover_image[:cover] =~/\S+/ - %{\n <#{$ep[:o]}meta name="cover" content="cover_image" />} - else '' - end - author=if defined? @md.creator.author \ - and @md.creator.author =~/\S+/ - m='' - @md.creator.author_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.author.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - editor=if defined? @md.creator.editor \ - and @md.creator.editor =~/\S+/ - m='' - @md.creator.editor_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.editor.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - translator=if defined? @md.creator.translator \ - and @md.creator.translator =~/\S+/ - m='' - @md.creator.translator_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.translator.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - illustrator=if defined? @md.creator.illustrator \ - and @md.creator.illustrator =~/\S+/ - m='' - @md.creator.illustrator_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.illustrator.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - date_published=if defined? @md.date.published \ - and @md.date.published =~/\S+/ - x=@md.date.published.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - subject=if defined? @md.classify.subject \ - and @md.classify.subject =~/\S+/ - x=@md.classify.subject.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - language=if defined? @md.opt.lng \ - and @md.opt.lng =~/\S+/ - language=@md.opt.lng.gsub(/
/,'
') - %{\n #{language}} - else '' - end - rights=if defined? @md.rights.all \ - and @md.rights.all =~/\S+/ - rights=SanitizeXML.xml(@md.rights.all) - rights=rights.gsub(//,' ') - %{\n #{rights}} - else '' - end - f=SiSU_Env::FileOp.new(@md) - <<-WOK - <#{$ep[:o]}metadata - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:opf="http://www.idpf.org/2007/opf" - xmlns:dcterms="http://purl.org/dc/terms/" - xmlns:dc="http://purl.org/dc/elements/1.1/" - unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0"> - #{@md.title.full} - #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} - #{f.output_path.epub.url.gsub(/http:\/\//,'')}/#{f.base_filename.epub} - urn:uuid:#{@md.dgst[1]} - - - WOK - end - def manifest_open - <<-WOK - - - - - - - WOK - end - def manifest_content_sisu_toc - <<-WOK - - WOK - end - def manifest_cover_image_information(md) - if defined? md.make.cover_image \ - and @md.make.cover_image.is_a?(Hash) \ - and md.make.cover_image[:cover] =~/\S+/ - <<-WOK - - WOK - else '' - end - end - def manifest_content(dob,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - <<-WOK - - WOK - end - def manifest_images(imgs) - imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png'] - images=[" \n"] - imgs.each do |i| - image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2] - type=type.sub(/jpg/,'jpeg') - images<<<<-WOK - - WOK - end - images=images.join('') - images - end - def manifest_close - <<-WOK - - WOK - end - def spine_open - #spine: reading order of XHTML files from manifest, idref attribute refers back to id in manifest (exclude images, CSS etc.). - <<-WOK - - WOK - end - def spine_cover_image - <<-WOK - - WOK - end - def spine_sisu_toc - <<-WOK - - WOK - end - def spine(dob,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - <<-WOK - - WOK - end - def spine_close - <<-WOK - - WOK - end - def guide_open - #guide: presentation order of XHTML files by reader). - <<-WOK - - WOK - end - def guide_cover_image - <<-WOK - - WOK - end - def guide_sisu_toc - <<-WOK - - WOK - end - def guide(dob,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - name=name ? name : dob.name - guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) - <<-WOK - - WOK - end - def guide_close - <<-WOK - - WOK - end - self - end - def table_close - %{ -#{@vz.table_close}} - end - def xhtml_close - %{#{@vz.credits_sisu_epub} - -} - end - end - class HeadToc < HeadInformation - def initialize(md) - super(md) - @md=md - @tocband_segtoc=make_seg - end - def manifest_link(text) - %{ #{text}} - end - def concordance_link(text) - if @md.concord_make - %{ - #{text} - } - else '' - end - end - def head - %{#{doc_type} - - - #{@css.xhtml_epub} - - #{@vz.color_body}} - end - def concordance - if @md.concord_make - %{#{@vz.margin_css} -

- - Concordance - -

-#{@vz.table_close}} - else - %{#{@vz.margin_css} -#{@vz.table_close}} - end - end - def links_guide_open(type='horizontal') - (type=='vertical') \ - ? links_guide_vertical_open - : links_guide_horizontal_open - end - def prefix_a - end - def rights - def all - rights=SanitizeXML.xml(@md.rights.all) - %{

Rights: #{rights}

} - end - self - end - def prefix_b - %{

Prefix: #{@md.prefix_b}} - end - def make_seg - concord=concordance_link(@vz.nav_txt_concordance) - %{ - -
- #{@vz.nav_txt_toc_link} - - - #{concord} -#{@vz.table_close}} - end - def manifest #check structure - manifest=manifest_link(@vz.nav_txt_manifest) - %{#{@vz.margin_txt_3} - #{@vz.paragraph_font_small} - #{manifest} - -#{@vz.table_close}} - end - def concordance #check structure - concord=concordance_link(@vz.nav_txt_concordance) - %{#{@vz.margin_txt_3} - #{@vz.paragraph_font_small} - #{concord} - -#{@vz.table_close}} - end - def metadata - %{#{@vz.margin_css} -

- - MetaData - -

-#{@vz.table_close}} - end - end - class HeadSeg < HeadInformation - def initialize(md) - super(md) - end - def head - %{#{doc_type} - - - #{@seg_name_xhtml[@seg_name_xhtml_tracker]} - - #{@md.html_title} - - - #{@css.xhtml_epub} - - #{@vz.color_body}} - end - def endnote_mark -%{ -
-} - end - end - class HeadScroll < HeadToc - def initialize(md) - super(md) - end - def toc_owner_details - %{#{@vz.margin_txt_3} -#{@vz.paragraph_font_small} - - Owner Details - - #{$ep[:hsp]*3} - - - -#{@vz.table_close}} - end - end - class FormatTextObject - @vz=SiSU_Viz::Defaults.new - attr_accessor :md,:t_o,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url - def initialize(md,t_o) - @md,@t_o=md,t_o - if t_o.is_a?(Hash) - @txt =t_o[:txt] || nil - @ocn =t_o[:ocn] || nil - @ocn_display =t_o[:ocn_display] || nil - @headname =t_o[:headname] || nil - @trailer =t_o[:trailer] || nil - @endnote_part_a =t_o[:endnote_part_a] || nil - @endnote_part_b =t_o[:endnote_part_b] || nil - @lnk_url =t_o[:lnk_url] || nil - @lnk_txt =t_o[:lnk_txt] || nil - @format =t_o[:format] || nil - @target =t_o[:target] || nil #occasionally passed but not used - if @format and not @format.empty? - if @format=~/^\d:(\S+)/ #need more reliable marker #if @format =~ /#{Rx[:lv]}/ - headname=$1 #format[/\d~(\S+)/m,1] - @headname=(headname =~/^[a-zA-Z]/) \ - ? %{} - : %{} - @headname=(headname =~/^[a-zA-Z]/) \ - ? %{} - : %{} - end - end - elsif t_o.class.inspect =~/Object/ - @dob=t_o if defined? t_o.is - @named=nametags_seg(@dob) - @txt=((defined? t_o.obj) ? t_o.obj : nil) - @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil) - @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil) - else - if @md.opt.act[:maintenance][:set]==:on - p __FILE__ << ':' << __LINE__.to_s - p t_o.class - p caller - end - end - if @txt and not @txt.empty? - @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'') - end - @p_num=ParagraphNumber.new(@md,@ocn) - @vz=SiSU_Viz::Defaults.new - end - def nametags_seg(dob) #FIX - tags='' - if defined? dob.tags \ - and dob.tags.length > 0 # insert tags "hypertargets" - dob.tags.each do |t| - tags=tags << %{} - end - end - tags - end - def endnote_body - %{ -

- #{@txt} -

-} - end - def endnote_body_indent - %{ -

- #{@txt} -

-} - end - def no_paranum - %{ -
- -

- #{@txt} -

-
-} - end - def para_form_css(tag,attrib,txt) # regular paragraphs shaped here - ul=ulc='' - ul,ulc="
    \n ","\n
" if @tag =~/li/ - %{ -
- #{@p_num.ocn_display} - #{ul}<#{tag} class="#{attrib}" #{@p_num.id}> - #{@named}#{txt} - #{ulc} -
-} - end - def para - para_form_css('p','norm',@txt) - end - def group - para_form_css('p','group',@txt) - end - def block - para_form_css('p','block',@txt) - end - def alt - para_form_css('p','alt',@txt) - end - def verse - para_form_css('p','verse',@txt) - end - def code - para_form_css('p','code',@txt) - end - def center - para_form_css('p','center',@txt) - end - def bold - para_form_css('p','bold',@txt) - end - def bullet - para_form_css('li','bullet',@txt) - end - def table - @txt=if @t_o.obj !~/^
'). - gsub(/#{Mx[:br_obj]}/,'

') - para_form_css('p','norm',@txt) - end - def format(tag,attrib) - para_form_css(tag,attrib,@txt) - end - def title_heading(tag,attrib) - %{ -
-<#{tag} class="#{attrib}"> - #{@named}#{@txt} - -
-} - end - def title_heading1 - DISABLE[:epub][:per_section_title] \ - ? '' - : title_heading('h1','tiny') - end - def title_heading2 - DISABLE[:epub][:per_section_title] \ - ? '' - : title_heading('h2','tiny') - end - def title_heading3 - DISABLE[:epub][:per_section_title] \ - ? '' - : title_heading('h3','tiny') - end - def title_heading4 - '' - end - def seg_heading_sub(tag,attrib,txt) - txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - %{ -
- #{@p_num.ocn_display} - <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} - #{@named}#{@txt} - -
-} - end - def seg_heading4 - %{ -
- #{@p_num.ocn_display} -

- #{@txt} -

-
-} - end - def seg_heading5 - seg_heading_sub('p','bold',@txt) - end - def seg_heading6 - seg_heading_sub('p','bold',@txt) - end - def dl #check :trailer - "
#{@txt} #{@trailer}
" - end - def table_css_end - '
-

- ' - end - def gsub_body #unused - @txt=case @txt - when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\((i+|iv|v|vi+|ix|x|xi+)\)/ - @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'(\1)'). - gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((i+|iv|v|vi+|ix|x|xi+)\)/,'\1(\2)') - when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\(?(\d|[a-z])+\)/ - @txt.gsub(/^\((\d+|[a-z])+\)/,'(\1)'). - gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((\d+|[a-z])+\)/,'\1(\2)') - when /^\s*\d{1,3}\.\s/ - @txt.gsub(/^\s*(\d+\.)/,'\1') - when /^\s*[A-Z]\.\s/ - @txt.gsub(/^\s*([A-Z]\.)/,'\1') - else @txt - end - end - def bold_para - %{#{@vz.margin_txt_0} -

- #{@txt} -

-#{@vz.margin_num_css} - #{$ep[:hsp]*3} -#{@vz.table_close}} - end - def bold_heading #unused - @txt=@txt.gsub(/[1-9]~\S+/,''). - gsub(/[1-9]~/,'') - %{

- #{@txt} -

-#{@vz.margin_num_css} - #{$ep[:hsp]*3} -#{@vz.table_close}} - end - def toc_head_copy_at - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - def center - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - def bold - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - def center_bold - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - end - class FormatScroll < FormatTextObject - def initialize(md,txt) - super(md,txt) - @vz=SiSU_Viz::Defaults.new - end - end - class FormatSeg < FormatTextObject - def initialize(md,txt) - super(md,txt) - end - def endnote_seg_body(fn='') #FIX #url construction keep within single line... BUG WATCH 200408 - fn='doc' if fn.to_s.empty? #you may wish to reconsider, sends to 'doc' where no segment info - %{ -

- #{@endnote_part_a}#{fn}#{Sfx[:epub_xhtml]}#{@endnote_part_b} -

-} - end - def clean(txt) - txt=txt.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/,''). - gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'') - end - def subtoc_lev(tag,attrib) - @txt=clean(@txt) - txt=if @txt \ - and @txt =~/<\/?i>|/mi - @txt.gsub(/<\/?i>|/mi,'') #removes name markers from subtoc, go directly to substantive text - else @txt - end - note='' - if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end - note=$1 - note=note.gsub(/[\n\s]+/m,' ') - txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove - end - %{<#{tag} class="#{attrib}"> - #{txt} #{note} - } - end - def subtoc_lev5 - subtoc_lev('h5','subtoc') if @txt - end - def subtoc_lev6 - subtoc_lev('h6','subtoc') if @txt - end - def heading_sub(tag,attrib,txt) - txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - %{ -
- #{@p_num.ocn_display} - <#{tag} class="#{attrib}" #{@p_num.id}> #{@headname} - #{@txt} - -
-} - end - def heading4 - %{ -
- #{@p_num.ocn_display} -

- #{@t_o[:format]} - #{@txt} -

-
-} - end - def heading5 - heading_sub('p','bold',@txt) - end - def heading6 - heading_sub('p','bold',@txt) - end - def navigation_heading4 - %{ -
-

- #{@txt} -

-#{@vz.table_close}} - end - def navigation_heading5 - %{

- #{@txt} -

} - end - def navigation_heading6 - %{

- #{@txt} -

} - end - def navigation_center - %{

#{@txt}

} - end - end - class FormatToc < FormatTextObject - def initialize(md,txt) - super(md,txt) - end - def links_guide - %{
  • - - #{@lnk_txt} - -
  • -} - end - def lev(tag,attrib) - if @txt - %{<#{tag} class="#{attrib}"> - #{@txt} - -} - else '' - end - end - def lev1 - lev('h1','toc') - end - def lev2 - lev('h2','toc') - end - def lev3 - lev('h3','toc') - end - def lev4 - lev('h4','toc') - end - def lev5 - lev('h5','toc') - end - def lev6 - lev('h6','toc') - end - def lev0 #docinfo - lev('h0','toc') - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_segments.rb b/lib/sisu/v5/epub_segments.rb deleted file mode 100644 index 16e26855..00000000 --- a/lib/sisu/v5/epub_segments.rb +++ /dev/null @@ -1,543 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: epub segment generation, processing - -=end -module SiSU_EPUB_Seg - require_relative 'shared_xhtml' # shared_xhtml.rb - require_relative 'epub' # epub.rb - require_relative 'shared_metadata' # shared_metadata.rb - class Output - def initialize(md,outputfile,seg,type='') - @md,@output_epub_cont_seg,@seg,@type=md,outputfile,seg,type - end - def output #CONSIDER - if @seg[:title] =~/\S/ - filename_seg=[] - filename_seg << @seg[:title] << @seg[:nav] - if @type=='endnotes' - @seg[:headings]=[] #watch - txt_obj={ txt: 'Endnotes', ocn_display: ''} - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_endnotes] << @seg[:headings] << %{\n
    \n} << @seg[:endnote_all] << '
    ' - elsif @type=='idx' - @seg[:headings]=[] - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << @seg[:idx] << '
    ' - elsif @type=='metadata' - metadata=SiSU_Metadata::Summary.new(@md).xhtml_display.metadata - @seg[:headings]=[] - txt_obj={ txt: 'Metadata', ocn_display: ''} - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << metadata << '
    ' - elsif @type=='sisu_manifest' - env=SiSU_Env::InfoEnv.new(@md.fns) - path_and_name,url_and_name="#{env.path.output}/#{@md.fnb}/sisu_manifest.html","#{env.url.root}/#{@md.fnb}/sisu_manifest.html" - manifest=if FileTest.file?("#{path_and_name}")==true - <A list of available output types may be available at the following url:

    -

    #{url_and_name}

    -WOK - else '' - end - @seg[:headings]=[] - txt_obj={ txt: 'Manifest', ocn_display: ''} - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << manifest << '
    ' - else - filename_seg << @seg[:headings] << @seg[:main] << "\n\n" - end - filename_seg << @seg[:tail] << @seg[:nav] << @seg[:close] - filename_seg=filename_seg.flatten.compact #watch - filename_seg.each do |str| - unless str =~/\A\s*\Z/ - @output_epub_cont_seg << str.strip - end - end - @output_epub_cont_seg.close - end - end - end - class Seg - @@seg,@@seg_subtoc,@@seg_endnotes,@@seg_ad={},{},{},{} - @@seg_name,@@seg_name_xhtml=[],[] - @@seg_url=@@fn=@@get_hash_to=@@get_hash_fn='' - @@loop_count=@@seg_total=@@tracker=0 - @@is4=@@is3=@@is2=@@is1=0 - @@heading1=@@heading2=@@heading3=@@heading4=0 - @@seg[:headings],@@seg[:main],@@seg[:idx],@@seg[:tail],@@seg_subtoc_array,@@seg_endnotes_array,@@seg[:endnote_all]=Array.new(7){[]} - @@seg[:heading_endnotes]='' - @@tablehead,@@number_of_cols=0,0 - @@fns_previous='' - attr_reader :seg_name_xhtml,:seg_name_xhtml_tracker - def initialize(md='',data='') - @md,@data=md,data - @vz=SiSU_Viz::Defaults.new - @seg_name_xhtml=@@seg_name_xhtml || nil - @seg_name_xhtml_tracker=@@tracker || nil - @make=SiSU_Env::ProcessingSettings.new(@md) if @md - end - def songsheet - begin - data=get_subtoc_endnotes(@data) - data=articles(data) - SiSU_EPUB_Seg::Seg.new.cleanup # (((( added )))) - #### (((( END )))) #### - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - @@seg_name=[] - end - end - protected - def articles(data) - tracking,newfile=0,0 - @@is4=@@is3=@@is2=@@is1=0 - printed_endnote_seg='n' - idx_xhtml=nil - if @md.book_idx - idx_xhtml=SiSU_Particulars::CombinedSingleton.instance.get_idx_xhtml(@md).xhtml_idx - idx_xhtml.each {|x| @@seg[:idx] << x } - @@seg[:heading_idx]='' - end - data.each do |dob| - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 - @@seg_name << dob.name - dob.name - end - end - @@seg_name_xhtml=@@seg_name - @@seg_total=@@seg_name.length - testforartnum=@@seg_name_xhtml - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],@@seg_name.length) - end - SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags - data.each do |dob| - #if defined? dob.obj \ - #and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/ - # ##Consider: remove, reinstate earlier? - # #while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/ - # # m=$1 - # # if map_nametags[m][:segname] - # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#{map_nametags[m][:segname]}#{Sfx[:html]}#\\1"}) - # # else - # # p "NOT FOUND name_tags: #{m}" - # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#\\1"}) # not satisfactory - # # end - # #end - #end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 - if dob.ocn==0 - @@heading4=dob.obj - else @@heading4=dob.obj - end - @@is4=newfile=1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==3 - @@heading3=dob.obj - @@is4,@@is3=0,1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==2 - @@heading2=dob.obj - @@is4,@@is3,@@is2=0,0,1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==1 - @@heading1=dob.obj - @@is4,@@is3,@@is2,@@is1=0,0,0,1 - end - if (@@is1 && !@@is2 && !@@is3 && !@@is4) - if not (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==1 - $_ #; check - end - end - if @@is4==1 - dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}" - if newfile==1 \ - or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/ - newfile=0 - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 - if tracking != 0 - SiSU_EPUB_Seg::Seg.new(@md).tail - segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking-1]}#{Sfx[:epub_xhtml]}" - output_epub_cont_seg=File.new(segfilename,'w') if @@seg_name_xhtml[tracking-1] - if dob.is==:heading \ - or @@seg_name_xhtml[tracking-1] !~/endnotes|book_index|metadata/ - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg).output - elsif dob.is==:heading_insert - if @@seg_name_xhtml[tracking-1]=='endnotes' - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'endnotes').output - elsif @@seg_name_xhtml[tracking-1]=='book_index' - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'idx').output - @@seg[:idx]=[] - elsif @@seg_name_xhtml[tracking-1]=='metadata' # navigation bug FIX - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output - else puts "#{__FILE__}::#{__LINE__}" - end - else puts "#{__FILE__}::#{__LINE__}" - end - SiSU_EPUB_Seg::Seg.new.reinitialise - heading_art(dob) - head(dob) - if @@seg_name_xhtml[tracking] =='metadata' - segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking]}#{Sfx[:epub_xhtml]}" - output_epub_cont_seg=File.new(segfilename,'w') - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output - SiSU_EPUB_Seg::Seg.new.reinitialise #BUG navigation bug with items following metadata, and occurring before manifest, this becomes a bug ... work area for book index, FIX - end - #@output_epub_cont_seg.close #%(((( EOF )))) --> - end - if tracking==0 - heading_art(dob) - head(dob) - end - end - tracking=tracking+1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 \ - and dob.name - @@get_hash_to=dob.name - @@get_hash_fn=dob.name - end - if dob.obj.is_a?(String) - markup(dob) - elsif dob.obj.is_a?(Array) - dob.obj.each do |pg| - markup(pg) - end - end - if testforartnum[tracking-1] =~/endnote/ - if printed_endnote_seg=='n' - printed_endnote_seg='y' - end - end - end - end - data - end - def heading_art(dob) - @@seg[:title]=SiSU_EPUB_Format::HeadSeg.new(@md).head - end - def head(dob) - clean=/|<:.*?>$/ - @p_num ||= '' - if @@is1==1 - if defined? @md.creator.author \ - and @md.creator.author - @author=%{#{@md.creator.author}\n} - end - ocn=(@@heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: @@heading1, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading1.gsub(clean,'') - @@heading1=@@heading1.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') - end - if @@is2==1 - heading2=@@heading2 - ocn=(heading2[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading2.gsub(clean,'') - @@heading2=@@heading2.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') - end - if @@is3==1 - heading3=@@heading3 - ocn=(heading3[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading3.gsub(clean,'') - @@heading3=@@heading3.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') - end - if @@is4==1 - heading4=@@heading4 - ocn=(heading4[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading4.gsub(clean,'') - end - @@tracker=@@tracker+1 - end - def markup(dob) - @debug=[] - if dob.is ==:heading \ - || dob.is ==:heading_insert \ - || dob.is ==:para - #extend as necessary FIX - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,dob.ocn) - end - sto=SiSU_EPUB_Format::FormatTextObject.new(@md,dob) - dob_xhtml=if dob.is==:heading \ - || dob.is==:heading_insert \ - || dob.is==:para - dob_xhtml=if dob.is==:heading \ - or dob.is==:heading_insert - if dob.ln==4 - sto.seg_heading4 # work on see SplitTextObject - elsif dob.ln==5 - sto.seg_heading5 - elsif dob.ln==6 - sto.seg_heading6 - end - elsif dob.is==:para - if dob.indent \ - and dob.hang \ - and dob.indent =~/[0-9]/ \ - and dob.hang =~/[0-9]/ - if dob.bullet_ - (dob.indent =~/[1-9]/) \ - ? sto.format('li',"i#{dob.indent}") - : sto.format('li','bullet') - elsif dob.indent == dob.hang - sto.format('p',"i#{dob.indent}") - elsif dob.indent != dob.hang - sto.format('p',"h#{dob.hang}i#{dob.indent}") - else sto.para - end - else sto.para - end - end - elsif dob.is ==:block \ - || dob.is ==:group \ - || dob.is ==:alt - sto.para #fix this should be block type specific #FIX - elsif dob.is==:verse - sto.verse - elsif dob.is==:code - sto.code - elsif dob.is==:table - sto.table - elsif dob.is==:break - sto.break - end - if @md.flag_separate_endnotes # may need to revisit, check - dob.obj=dob.obj.gsub(/"\s+href="#note_ref(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}#note_ref\\1">}) #endnote- twice #removed file type - end - if (dob.is ==:heading \ - || dob.is==:heading_insert \ - || dob.is==:para) \ - && (not dob.ocn or dob.ocn.to_s.empty?) - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,dob) - end - if (dob.is==:heading \ - || dob.is==:heading_insert \ - || dob.is==:para) \ - and dob.note_ #dob.obj =~/ \n} - @@seg[:main] << dob_xhtml - if @make.build.segsubtoc? - @@seg[:main] << @@seg_subtoc[@@get_hash_fn] #% insertion of sub-toc - end - else - @@seg[:main] << dob_xhtml - end - end - def tail - format_head_seg=SiSU_EPUB_Format::HeadSeg.new(@md) - if @md.flag_auto_endnotes \ - and @@seg_endnotes[@@get_hash_fn] - @@seg[:tail] << %{\n
    \n
    \n} - if @@seg_endnotes[@@get_hash_fn].flatten.length > 0 - @@seg[:tail] << format_head_seg.endnote_mark - @@seg[:tail] << @@seg_endnotes[@@get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES| - end - @@seg[:tail] << '
    ' - @@seg[:tail] << '
    ' #this div closes div class content - end - @@seg[:close]=[] - @@seg[:close] << format_head_seg.xhtml_close - end - def reinitialise - @@seg[:headings],@@seg[:main],@@seg[:tail],@@seg[:credits]=Array.new(4){[]} - end - def cleanup - reinitialise - @@seg_total,@@tracker=0,0 - @@seg_endnotes,@@seg_subtoc={},{} - @@seg_endnotes_array,@@seg_subtoc_array=[],[] - @@seg[:endnote_all]=[] - end - def get_subtoc_endnotes(data) #get endnotes & sub-table of contents subtoc - data.each do |dob| - dob.obj=dob.obj.gsub(/
    (.+?)<\/a>/mi,'\1') - if @md.flag_auto_endnotes - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln.to_s =~/^[1234]/ \ - and not @@fn.to_s.empty? - @@seg_endnotes[@@fn]=[] - @@seg_endnotes[@@fn] << @@seg_endnotes_array - @@seg_endnotes_array=[] if dob.ln==4 - @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/ - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs - @@seg_subtoc[@@fn]=@@seg_subtoc_array - @@seg_subtoc_array=[] - if dob.name \ - and dob.obj - @@fn=dob.name - else - @@fn=(dob.name =~/\S+/) \ - ? dob.name - : '' - end - end - end - if dob.is==:heading \ - and dob.ln.to_s =~/^[56]/ - case dob.ln - when 5 - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,dob) - subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc - when 6 - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,dob) - subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc - end - @@seg_subtoc_array << subtoc - end - if @md.flag_auto_endnotes - ast,pls='*','+' - if dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(?:\d|#{ast}|#{pls})+ / \ - and dob.is !=:code # endnote- - endnote_array=[] - if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m) - end - if dob.obj=~/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m) - end - if dob.obj=~/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m) - end - endnote_array=endnote_array.flatten #.compact #check compacting - endnote_array.each do |note| - note_match=note.dup - note_match_seg=note.dup - e_n=note_match_seg[/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1] - try=e_n.split(/
    /) - try.each do |e| - txt_obj={ txt: e } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/ - format_seg.endnote_body_indent - else format_seg.endnote_body - end - @@seg_endnotes_array << note_match - end - try.join('
    ') - #% creation of separate end segment/page of all endnotes referenced back to reference segment - m=/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?href=")(#note_ref(?:\d|_a|_b)+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi - endnote_part_a=note_match_seg[m,1] - endnote_part_b=note_match_seg[m,2] - txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - note_match_all_seg=format_seg.endnote_seg_body(@@fn) #BUG WATCH 200408 - @@seg[:endnote_all] << note_match_all_seg - end - dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_tune.rb b/lib/sisu/v5/epub_tune.rb deleted file mode 100644 index 5ec5fa56..00000000 --- a/lib/sisu/v5/epub_tune.rb +++ /dev/null @@ -1,333 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: epub generation, epub pre-processing - -=end -require_relative 'param' -module SiSU_EPUB_Tune - require_relative 'sysenv' # sysenv.rb - include SiSU_Env; include SiSU_Screen - require_relative 'epub_format' # epub_format.rb #watch - @@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 - @file=SiSU_Env::FileOp.new(@md) - @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX - end - def hard_output - @filename_tune=@file.write_file_processing.html_tune - data=[] - @data.each {|x| x.obj.strip; data << x if not x.obj.empty?} #1.9 array? - data.each do |dob| - @filename_tune.puts dob, "\n" #check - end - end - def marshal - File.open(@file.marshal.html_tune,'w') {|f| Marshal.dump(@data.to_a,f)} - end - end - class CleanXHTML - def initialize(html='') - @html=html - end - def clean - html=@html - str=if html.is_a?(String) - html - else html.obj - end - str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/
    /u,'
    '). - gsub(/#{Mx[:nbsp]}/u,$ep[:hsp]) - end - end - class Tune - def initialize(data,md) - @data,@md=data,md - @vz=SiSU_Viz::Defaults.new - @env=SiSU_Env::InfoEnv.new(@md.fns) - @sys=SiSU_Env::SystemCall.new - @env=SiSU_Env::InfoEnv.new(@md.fns) - @brace_url=SiSU_Viz::Defaults.new.url_decoration - end - def songsheet - begin - @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Tune').txt_grey - end - data=SiSU_EPUB_Tune::Tune.new(@data,@md).amp_angle_brackets - data=SiSU_EPUB_Tune::Tune.new(data,@md).endnotes_html - data=SiSU_EPUB_Tune::Tune.new(data,@md).url_markup - data=SiSU_EPUB_Tune::Tune.new(data,@md).markup - if @md.opt.act[:maintenance][:set]==:on #Hard Output Tune Optional on/off here - data=SiSU_EPUB_Tune::Output.new(data,@md).hard_output - SiSU_EPUB_Tune::Output.new(data,@md).marshal - end - SiSU_EPUB_Tune::Tune.new(@data,@md).output - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - def markup - @tuned_file=[] - @data.each do |dob| - dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table - dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). - gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). - gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd - gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/m,"●#{$ep[:hsp]*2}"). - gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). - gsub(/#{Mx[:nbsp]}/,$ep[:hsp]). - gsub(/<(p|br)>/,'<\1 />') - dob.obj=SiSU_EPUB_Tune::CleanXHTML.new(dob.obj).clean - @tuned_file << dob - end - end - def urls(data) - @words=[] - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags - data.each do |word| - @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - http_=true - if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ - http_=false - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures - end - case m - when /\.png|\.jpg|\.gif|c=|\s\d+x\d+/ - w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\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=@md.file.output_path.epub.rel_image #image_path=@env.url.images_epub - ins=if u \ - and u.strip !~/^image$/ - %{
    #{caption}} - else %{#{caption}} - end - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) - else - link=m[/(.+)/m] - png=m.scan(/\S+/)[0].strip - link=link.strip - u=u.sub(/^#*/,'') #make neater - if map_nametags[u] \ - and map_nametags[u][:segname] - u=unless http_ - u=if u=~/^\d+$/ - u.gsub(/^(\d+)$/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#o\\1") if u !~/\// - else - u.gsub(/(\S+)/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#\\1") if u !~/\// - end - else u - end - elsif u =~/^:/ - u=u.gsub(/^:/,"#{@env.url.root}/") - elsif u =~/^\.\.\// - u=u.gsub(/^\.\.\//,"#{@env.url.root}/") - elsif u =~/https?:\/\// - else p "NOT FOUND name_tags: #{u}" - end - ins=%{#{link}} - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). - gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) - end - word - else word - end - word - end - @words=@words.join(' ') - end - def url_markup - data=@data - @tuned_file=[] - data.each do |dob| - unless dob.is==:code - if dob.obj =~/<::\s+/ #watch - dob.obj=dob.obj.gsub(/<::\s+(\S+?)\s+!>/, - %{\\1}) - end - if dob.obj =~/<:image\s+/ - dob.obj=dob.obj.gsub(/<:image\s+(http\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, - %{}). - gsub(/<:image\s+(http\S+)\s+(\S+)\s+>/, - %{}). - gsub(/<:image\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, - %{}). - gsub(/<:image\s+(\S+)\s+>/, - %{}) - end - if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - @word_mode=dob.obj.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)[()\[\]]*[,.;:!?'"]{0,2}|(?:#{Mx[:gl_o]}\S+?#{Mx[:gl_c]})+|[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+/mu) - words=urls(@word_mode) - dob.obj=dob.obj.gsub(/.+/m,words) - end - dob.obj=dob.obj.gsub(/\\copyright/i,%{©}) - dob.obj=if (dob.obj !~/\<:ad\s+\.\.\//) - dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, - %{\n
    \\3
    \n}) - else - dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, - %{\n
    \\3
    \n}) - end - dob.obj=dob.obj.gsub(/!pick/,%{stellar}). - gsub(/!new/,%{#{$ep[:hsp]}new}). - gsub(/<:h(.{1,7}?)>/,'\1'). - gsub(/<:to(\d{1,7}?)>/,%{to#{$ep[:hsp]}\{#{$ep[:hsp]}\\1#{$ep[:hsp]}\} }). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). #http ftp matches escaped, no decoration - gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration - if dob.obj =~/..\/\S+/ \ - and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ - dob.obj=dob.obj.gsub(/(\.\.\/\S+)/,'\1') - end - dob.obj=dob.obj.gsub(//m,'>') - end - @tuned_file << dob - end - end - def amp_angle_brackets - data,data_new=@data,[] - data.each do |dob| - dob.obj=dob.obj. - gsub(/&/u,'&'). - gsub(//u,'>') - data_new << dob - end - data_new - end - def endnotes_html - data=@data - @tuned_file=[] - a,s='_a','_s' - ast,pls='*','+' - data.each do |dob| - unless dob.is ==:code - dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) - gsub(/(#{Mx[:en_b_o]})[*](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) - gsub(/(#{Mx[:en_b_o]})[+](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug - if dob.obj =~/#{Mx[:en_a_o]}([*+]+)\s+.+?#{Mx[:en_a_c]}/ - m=$1.length.to_i - dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]})[*]+\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) - gsub(/(#{Mx[:en_a_o]})([+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) - end - end - @tuned_file << dob - end - end - def output - data=@data - @tuned_file=[] - data.each do |dob| - dob.obj=dob.obj.strip.chomp - @tuned_file << dob - end - @tuned_file << "\n" if (@md.fns =~/\.sst0/) #remove - @tuned_file - end - end -end -__END__ diff --git a/lib/sisu/v5/html_format.rb b/lib/sisu/v5/html_format.rb index 3a20ef67..db9fb449 100644 --- a/lib/sisu/v5/html_format.rb +++ b/lib/sisu/v5/html_format.rb @@ -93,7 +93,7 @@ module SiSU_HTML_Format end class HeadInformation require_relative 'css' # css.rb - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_Viz attr_reader :md,:rdf,:vz def initialize(md) diff --git a/lib/sisu/v5/html_lite_shared.rb b/lib/sisu/v5/html_lite_shared.rb new file mode 100644 index 00000000..20e07f8c --- /dev/null +++ b/lib/sisu/v5/html_lite_shared.rb @@ -0,0 +1,325 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: modules shared by db and flatfile output generators, mostly + xml/xhtml/html formatting + +=end +module SiSU_FormatShared + require_relative 'defaults' # defaults.rb + include SiSU_Viz + class CSS_Format + require_relative 'defaults' # defaults.rb + require_relative 'particulars' # particulars.rb + @@fns=nil + def initialize(md,t_o) + @md,@t_o=md,t_o + @txt=@t_o.obj + @id=@ocn=@t_o.ocn if defined? @t_o.ocn + @lv=@t_o.lv.to_s if @t_o.is==:heading + if @md.fns != @@fns + @@fns,@@hname=@md.fns,'' + end + @hname=if defined? @t_o.name \ + and not @t_o.name.to_s.empty? + @@hname=@t_o.name + else @@hname + end + @tab="\t" + @brace_url=SiSU_Viz::Defaults.new.url_decoration + @@tablehead,@@tablefoot=[],[] + @vz=SiSU_Viz::Defaults.new + @env=SiSU_Env::InfoEnv.new(@md.fns) + @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" + end + def urls(data) + @words=[] + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map + data.each do |word| + @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures + 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] + ins=if u \ + and u.strip !~/^image$/ + %{[#{png}]#{caption}} + else %{[#{png}] #{caption}} + end + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) + else + u=case u + when /^https?:\/\// + u + when /^:/ + u=u.gsub(/^:/,'') + "#{@env.url.root}/#{u}" + when /^\.\.\// # can remove + u=u.gsub(/^\.\.\//,'') + "#{@env.url.root}/#{u}" + else + "#{@env.url.root}/#{@md.fnb}/#{map_nametags[u][:segname]}#{Sfx[:html]}##{u}" + end + link=m[/(.+)/m] + png=m.scan(/\S+/)[0].strip + link=link.strip + ins=%{#{link}} + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). + gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) + word + end + word + else word + end + word + end + @words=@words.join(' ') + end + def markup_generic(s) + s=s.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_c]}/,'-{\1}-'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~') + end + def markup_object(t_o) + s=t_o.obj + s=if t_o.is !=:code + s=markup_generic(s) + if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) + words=urls(wm) + s=s.gsub(/.+/m,words) + end + s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:url_o]}[_\\](\S+?)#{Mx[:url_c]}/,'\1'). #http ftp matches escaped, no decoration + gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url + gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{\\1#{@brace_url.xml_open}\\2#{@brace_url.xml_close}\\3}) #http ftp matches with decoration + else + s.gsub(//m,'>') + end + s + end + def markup_note(s) + s=markup_generic(s) + if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) + words=urls(wm) + s=s.gsub(/.+/m,words) + end + s=s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1\2'). #http ftp matches escaped, no decoration + gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + end + def paragraph + %{

    #{@txt}

    \n} # << "\n" + end + def endnote(nr,en) #used only by db + txt=markup_note(en) + < +#{nr}. #{txt} +

    +GSUB + end + def tag_header(h) + %{

    #{h[:txt]}

    \n} # << "\n" + end + def tag_para(h) + %{

    #{h[:txt]}

    \n} << "\n" + end + def lev_toc_hname + %{

    #{@txt}

    \n} #<< "\n" + end + def lev_toc + h={ txt: txt, class: "toc#{@lv}", type: 'toc' } + tag_para(h) + end + def lev4_plus + txt=markup_object(@t_o) + h={ txt: txt, class: "h#{@lv}", type: 'substantive', id: @ocn, header: @hname } + tag_header(h) + end + def lev4_minus + txt=markup_object(@t_o) + h={ txt: txt, class: "h#{@t_o.ln}", type: 'substantive', id: @ocn } + tag_para(h) + end + def norm_comment + h={ txt: @t_o.obj, class: 'norm', type: 'comment' } + tag_para(h) + end + def norm + txt=markup_object(@t_o) + h={ txt: txt, class: 'norm', type: 'substantive', id: @ocn } + tag_para(h) + end + def code + txt=markup_object(@t_o) + h={ txt: "#{txt}", class: 'code', type: 'substantive', id: @ocn } + tag_para(h) + end + def indent(t) + txt=markup_object(@t_o) + h={ txt: txt, class: "indent#{t}", type: 'substantive', id: @ocn } + tag_para(h) + end + def hang_indent(f,t) + txt=markup_object(@t_o) + h={ txt: txt, class: "hang#{f}indent#{t}", type: 'substantive', id: @ocn } + #h={ txt: txt, class: "h#{f}i#{t}", type: 'substantive', id: @ocn } + tag_para(h) + end + def para_table + %{

    } + end + def ocn + %{} << "\n" + end + def html_table # get rid of use html_table + @new_content=[] + @txt.split(/\n/).each do |parablock| + m=parablock[//,1] + @@tablefoot << m if m + parablock=parablock.gsub(//,'') + @@tablehead=1 if parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u + parablock=parablock.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+)#{Mx[:gr_c]}/, + %{}) + if parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ + tablefoot=[] + @@tablefoot.each {|x| tablefoot << %{

    #{x}

    \n}} + @@tablefoot=[] + parablock=parablock.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/, + %{#{@vz.table_close}\n}) # + + end + if @@tablehead==1 + if parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u + parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{\n} + + %{\n') + @@tablehead=0 + end + parablock + else + parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{\n} + + %{\n') + parablock + end + @new_content << parablock + end + @new_content.join + end + end + class CSS_FormatGeneric #does CSS_Format in one definition, needs to be told about attrib, despite brevity of generic, easier to see structure with CSS_Format + def initialize(attrib='',txt='',id=nil,ocnd=nil,ocns=nil,lv='',hname=nil) + @tab="\t" + @attrib=attrib + @txt=txt + @lv=lv.to_s + @hname=hname.to_s + @id=@ocn=id + end + def paragraph + attrib=%{class="#{@attrib}" } + if @ocn + id=%{id="#{@ocn}" } + type=%{type="substantive" } + else + id=%{id="none" } + type=%{type="comment" } + end + header=%{header="#{@hname}" } if @hname + %{

    #{@txt}

    \n} #<< "\n" + end + def para + paragraph + end + end +end +__END__ diff --git a/lib/sisu/v5/html_scroll.rb b/lib/sisu/v5/html_scroll.rb index 3ac75aaa..f525b462 100644 --- a/lib/sisu/v5/html_scroll.rb +++ b/lib/sisu/v5/html_scroll.rb @@ -60,7 +60,7 @@ =end module SiSU_HTML_Scroll - require_relative 'shared_html' # shared_html.rb + require_relative 'html_shared' # html_shared.rb require_relative 'html' # html.rb require_relative 'shared_metadata' # shared_metadata.rb require_relative 'html_promo' # html_promo.rb diff --git a/lib/sisu/v5/html_segments.rb b/lib/sisu/v5/html_segments.rb index 79dda0e2..d6b341ac 100644 --- a/lib/sisu/v5/html_segments.rb +++ b/lib/sisu/v5/html_segments.rb @@ -60,7 +60,7 @@ =end module SiSU_HTML_Seg - require_relative 'shared_html' # shared_html.rb + require_relative 'html_shared' # html_shared.rb require_relative 'html' # html.rb require_relative 'html_promo' # html_promo.rb require_relative 'shared_metadata' # shared_metadata.rb diff --git a/lib/sisu/v5/html_shared.rb b/lib/sisu/v5/html_shared.rb new file mode 100644 index 00000000..63a8964e --- /dev/null +++ b/lib/sisu/v5/html_shared.rb @@ -0,0 +1,68 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: shared html parts + +=end +module SiSU_HTML_Shared + require_relative 'defaults' # defaults.rb + require_relative 'html_table' # html_table.rb + class TableHTML < SiSU_HTML_Table::TableHTML + end +end +__END__ diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 9390d517..a4fd408f 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -299,8 +299,8 @@ module SiSU SiSU_DigestView::Source.new(@opt).read end if @opt.act[:txt][:set]==:on #% --txt, -t -a - require_relative 'plaintext' # plaintext.rb - SiSU_Plaintext::Source.new(@opt).read + require_relative 'txt_plain' # txt_plain.rb + SiSU_Txt_Plain::Source.new(@opt).read end if @opt.act[:html][:set]==:on #% --html, -h -H require_relative 'html' # html.rb @@ -320,12 +320,12 @@ module SiSU SiSU_Concordance::Source.new(@opt).read end if @opt.act[:epub][:set]==:on #% --epub, -e - require_relative 'epub' # epub.rb - SiSU_EPUB::Source.new(@opt).read + require_relative 'xhtml_epub2' # xhtml_epub2.rb + SiSU_XHTML_EPUB2::Source.new(@opt).read end if @opt.act[:odt][:set]==:on #% --odt, -o opendocument - require_relative 'odf' # odf.rb - SiSU_ODF::Source.new(@opt).read + require_relative 'xml_odf_odt' # xml_odf_odt.rb + SiSU_XML_ODF_ODT::Source.new(@opt).read end if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml require_relative 'xhtml' # xhtml.rb @@ -391,12 +391,12 @@ module SiSU or @opt.act[:sisupod][:set]==:on \ or @opt.act[:git][:set]==:on begin - require_relative 'shared_sisupod_source' + require_relative 'src_shared' OptionLoopFiles.new(@opt).loop_files_on_given_option do SiSU_Source::SiSUpodSource.new(@opt).read end if @opt.act[:share_source][:set]==:on - require_relative 'share_src' # -s share_src.rb + require_relative 'src_share' # -s src_share.rb begin ensure OptionLoopFiles.new(@opt).loop_files_on_given_option_bundle do @@ -405,7 +405,7 @@ module SiSU end end if @opt.act[:sisupod][:set]==:on #% --sisupod, -S make sisupod - require_relative 'sisupod_make' # -S sisupod_make.rb + require_relative 'src_sisupod_make' # -S src_sisupod_make.rb begin ensure OptionLoopFiles.new(@opt).loop_files_on_given_option_bundle do diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 905cf87f..ccdd829c 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -69,7 +69,7 @@ module SiSU_Manpage require_relative 'manpage_format' # manpage_format.rb include SiSU_ManpageFormat require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 @@tablefoot='' class Source @@ -112,7 +112,7 @@ module SiSU_Manpage private class Scroll . - - 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: opendocument text generation - -=end -module SiSU_ODF - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'ao' # ao.rb - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - include SiSU_Viz - require_relative 'odf_format' # odf_format.rb - include SiSU_ODF_Format - require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'shared_txt' # shared_txt.rb - @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 - class Source - require 'zlib' - require 'find' - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - @@endnotes_para=[] - end - def read - begin - @md,@env,@ao_array=@particulars.md,@particulars.env,@particulars.ao_array - unless @opt.act[:quiet][:set]==:on - tool=(@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? "#{@env.program.odf_viewer} file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}" - : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Opendocument (ODF:ODT)',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Opendocument (ODF:ODT)',tool).green_title_hi - if (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}").flow - end - end - SiSU_ODF::Source::Scroll.new(@particulars).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class Scroll appropriately within odf, consider - n=n.dup.to_s - if n =~/#{Mx[:br_line]}/ - fix=n.split(/#{Mx[:br_line]}/) #watch #added - fix.each do |x| - if x =~/\S+/ then @n << x - end - end - else @n << n - end - end - end - def odf_book_idx - if @md.book_idx - idx_arr,idx_raw=[],SiSU_Particulars::CombinedSingleton.instance.get_idx_raw(@md.opt).raw_idx - idx_raw.each do |x| - x=if x.is_a?(String) - SiSU_ODF_Format::FormatBookIndex.new(x).book_idx_bookmark - else nil - end - idx_arr << x.strip if x.is_a?(String) - end - @@odf[:book_idx]=idx_arr.join - end - end - def odf_metadata - @@odf[:metadata]=SiSU_Metadata::Summary.new(@md).odf.metadata - end - def odf_tail - manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" - @@odf[:tail] << %{Available document outputs:
    <#{manifest}>
    } - @@odf[:tail] << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} - @@odf[:tail] << "\n" - end - def set_bookmark_tag(dob) - SiSU_ODF_Format::Tags.new.set_bookmark_tag(dob) - end - def heading(dob,p_num) - dob=footnote(dob) - m=/#{$1}/ - breakpage='' - if @md.fns \ - and @md.fns != '' \ - and @md.fns !=@@fns - @@docstart=true - @@fns=@md.fns - end - unless @@docstart - breakpage=if (@md.pagenew || @md.pagebreak) \ - and (@md.pagenew =~m or @md.pagebreak =~m) - ' ' - elsif @md.pageline \ - and @md.pageline =~m #fix - else '' - end - end - @@docstart=false - dob.tmp=dob.obj - dob.obj=%{#{breakpage}#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} - dob - end - def toc(dob,p_num) - hardspace=(dob.lv =~/[A-C]/i) \ - ? '' - : '' - toc_heading=dob.ocn \ - ? %{#{dob.tmp}} - : dob.tmp - dob.obj=%{#{toc_heading}#{hardspace}} - dob - end - def image_src(i) - if @md.fns =~/\.ss[tm]$/ \ - and FileTest.file?("#{@env.path.image_source_include}/#{i}") #review - @env.path.image_source_include - elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ - pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] - img_src=pt + '/image' - if FileTest.file?("#{img_src}/#{i}") - img_src - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"ERROR - image:",%{"#{i}" missing},"search locations: #{@env.path.image_source_include_local},#{@env.path.image_source_include_remote} and #{@env.path.image_source_include}").error2 unless @md.opt.act[:quiet][:set]==:on - nil - end - elsif @md.fns =~/\.ss[tm]$/ \ - and FileTest.file?("#{@env.path.image_source_include_local}/#{i}") #review - @env.path.image_source_include_local - elsif @md.fns =~/\.ss[tm]$/ \ - and FileTest.file?("#{@env.path.image_source_sisu_includes}/#{i}") - @env.path.image_source_sisu_includes - elsif @md.fns =~/\.-ss[tm]$/ \ - and FileTest.file?("#{@env.path.image_source_include_remote}/#{i}") - @env.path.image_source_include_remote - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"ERROR - image:",%{"#{i}" missing},"search locations: #{@env.path.image_source_include_local},#{@env.path.image_source_include_remote} and #{@env.path.image_source_include}").error2 unless @md.opt.act[:quiet][:set]==:on - nil - end - end - def image_odf(img) - # copy image to od image directory (unless exists) - # divide pixel dimension by 37.79485 and retain 3 decimal places - m=img[1] - i=/^(\S+?\.(?:png|jpg|gif))/.match(m).captures.join if m =~/^(\S+?\.(?:png|jpg|gif))/ - c=/^\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"/.match(m).captures.join if m =~/^\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"/ - w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\d+x\d+/ - w=(w.to_i/37.79485).to_s - h=(h.to_i/37.79485).to_s - h=/([0-9]+\.\d{0,3})/.match(h).captures.join - w=/([0-9]+\.\d{0,3})/.match(w).captures.join - image_source=image_src(i) - if image_source - if FileTest.file?("#{image_source}/#{i}") - FileUtils::cp("#{image_source}/#{i}","#{@env.processing_path.odt}/Pictures/#{i}") - else STDERR.puts %{\t*WARN* did not find image - "#{image_source}/#{i}" [#{__FILE__}:#{__LINE__}]} - end - end - img=if i.to_s =~/jpg|png|gif/ \ - and h.to_s =~/\d/ \ - and w.to_s =~/\d/ - @@img_count +=1 - %{#{c}} #anchor-type: as-char or paragraph or char or ... - else %{[image omitted]} - end - end - def image(dob) - m=if dob.obj =~/#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - dob.obj.scan(/(#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) - elsif dob.obj =~/#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}image/ - dob.obj.scan(/(#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}(image))/) - else nil - end - if m then m.each do |i| - cont,url=i[1],i[2] - cont=cont.gsub(/([)(\]\[])/,"\\\\\\1"). - gsub(/([+?])/,"\\\\\\1") # incorrect handling of + - url=url.gsub(/([+?])/,"\\\\\\1") - dob.obj=dob.obj.sub(/#{Mx[:lnk_o]}[ ]*#{cont}[ ]*#{Mx[:lnk_c]}image/m,image_odf(i)). - sub(/#{Mx[:lnk_o]}[ ]*#{cont}[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}#{url}#{Mx[:url_c]}/m,image_odf(i)). - sub(/\\([)(\]\[?])/,'\1') #clumsy fix - end - m=nil - end - dob - end - def text_link_odf(txt,url,trail) - txt=txt.gsub(/(\\\+)/,'+') #this is convoluted, and risky :-( - url=url.gsub(/(\\\+)/,'+') #this is convoluted, and risky :-( - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map - t=case url - when /^https?:/ - %{#{txt.strip}#{trail}} - when /^:/ # site same document collection html link - url=url.gsub(/^:/,"#{@env.url.root}/") - %{#{txt.strip}#{trail}} - when /^\.\.\// # site same document collection html link - url=url.gsub(/^\.\.\//,"#{@env.url.root}/") - %{#{txt.strip}#{trail}} - else # document internal link - if map_nametags[url] \ - and map_nametags[url][:segname] - else p "NOT FOUND name_tags: #{url}" - end - t=map_nametags[url] \ - && map_nametags[url][:segname] \ - ? %{#{txt.strip}#{trail}} - : %{#{txt.strip}#{trail}} - end - t - end - def text_link_odf_bookmark(txt,url,trail) - SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map - %{#{txt.strip}#{trail}} - end - def text_link(dob) - m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) #sort - if m - m.each do |i| - txt,url,trail=i[1],i[2] - txt=txt.gsub(/([)(\]\[])/,"\\\\\\1"). - gsub(/([+?*])/,"\\\\\\1") # problems with + - url=url.gsub(/([+?])/,"\\\\\\1") # problems with + - dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:url_o]}#{url}#{Mx[:url_c]}/m,text_link_odf(txt,url,trail)). #make sure trailing ']' are not caught in url - gsub(/\\([)(\]\[?])/,'\1') #clumsy fix - end - m=nil - end - dob - end - def text_link_relative(dob) - m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort - if m - m.each do |i| - txt,url,trail=i[1],i[2] - txt=txt.gsub(/([)(\]\[])/,"\\\\\\1"). - gsub(/([+?*])/,"\\\\\\1") # problems with + - url=url.gsub(/([+?])/,"\\\\\\1") # problems with + - dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m,text_link_odf_bookmark(txt,url,trail)). #make sure trailing ']' are not caught in url - gsub(/\\([)(\]\[?])/,'\1') #clumsy fix - end - m=nil - end - dob - end - def text_link_relative_(dob) - m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort - if m - m.each do |i| - txt,url,trail=i[1],i[2] - txt=txt.gsub(/([)(\]\[])/,"\\\\\\1") - dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m,text_link_odf(txt,url,trail)). #make sure trailing ']' are not caught in url - gsub(/\\([)(\]\[?])/,'\1') #clumsy fix - end - m=nil - end - dob - end - def normal(dob,p_num) #P1 - P3 - dob=footnote(dob) - dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1'). #http ftp matches escaped, no decoration - gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration - dob.obj= if dob.is==:para \ - and dob.indent.to_s =~/[0-9]/ \ - and dob.indent == dob.hang - %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} - elsif dob.is==:para \ - and dob.hang.to_s =~/[0-9]/ \ - and dob.indent != dob.hang - %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} - else %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} - end - dob - end - def fontface(dob) - end - def footnote_urls(str) - str=str.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) - str=text_link(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - str=text_link_relative(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ - str - end - def footnote(t_o) - str=if defined? t_o.obj then t_o.obj - elsif t_o.is_a?(String) then t_o - end - if str - @astx||=10000 - @astxs||=20000 - if str =~/#{Mx[:en_a_o]}\d+\s+/ - str=str.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/,'\1 \2') - end - if str =~/#{Mx[:en_a_o]}([*]+)\s+/ - a=$1.gsub(/([*])/,"\\\\\\1") - str=str.gsub(/#{Mx[:en_a_o]}([*]+)\s+(.+?)#{Mx[:en_a_c]}/,%{\\1 \\2}) - @astxs+=1 - end - if str=~/#{Mx[:en_a_o]}[*+]+\s/ - asterisk=str.scan(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/) - asterisk.each do |x| - a=x[0].gsub(/([*+])/,"\\\\\\1") - str=group_clean(str) - str=footnote_urls(str) - str=str.gsub(/#{Mx[:en_a_o]}(#{a})\s+(.+?)#{Mx[:en_a_c]}/,%{\\1 \\2}) - @astx+=1 - end - end - if str=~/#{Mx[:en_b_o]}[*+]\d+\s/ - asterisk=str.scan(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/) - asterisk.each do |x| - a=x[0].gsub(/([*+])/,"\\\\\\1") - str=group_clean(str) - str=footnote_urls(str) - str=str.gsub(/#{Mx[:en_b_o]}(#{a})\s+(.+?)#{Mx[:en_b_c]}/,%{\\1 \\2}) - @astx+=1 - end - end - end - if defined? t_o.obj then t_o.obj=str - elsif t_o.is_a?(String) then t_o=str - end - t_o - end - def group_clean(str) - str=str.gsub(/&nbsp;| |#{Mx[:nbsp]}/,' '). - gsub(//,'>'). - gsub(/<(text:span text:style-name="Span_\S+?"|\/text:span)>/,'<\1>'). #works, not ideal - gsub(/#{Mx[:br_line]}/,'
    '). - gsub(/<br(?:\s+\/)?>/,'
    ') - end - def poem(dob,p_num) #P4 #same as group - parray=[] - dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| - set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' - parablock=group_clean(parablock) - parablock=footnote(parablock) - parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ - end - dob.obj=parray.join \ - + %{#{p_num[:display]}} \ - + '' - dob - end - def group(dob,p_num) #P4 #same as verse - parray=[] - dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1'). #http ftp matches escaped, no decoration - gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration - dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| - set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' - parablock=group_clean(parablock) - parablock=parablock.gsub(/<text:a xl:type="simple" xl:href="(.+?)">/m,''). - gsub(/<(\/text:a)>/,'<\1>'). - gsub(/<(text:note text:id=.+?)>/,'<\1>'). - gsub(/<(text:p text:style-name="Footnote")>/,'<\1>'). - gsub(/<(\/?text:(?:note-citation|note-body|note|p))>/,'<\1>') - parablock=footnote(parablock) - parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ - end - dob.obj=parray.join \ - + %{#{p_num[:display]}} \ - + '' - dob - end - def block(dob,p_num) #P4 #same as verse - parray=[] - dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1'). #http ftp matches escaped, no decoration - gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration - dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| - set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' - parablock=group_clean(parablock) - parablock=parablock.gsub(/<text:a xl:type="simple" xl:href="(.+?)">/m,''). - gsub(/<(\/text:a)>/,'<\1>'). - gsub(/<(text:note text:id=.+?)>/,'<\1>'). - gsub(/<(text:p text:style-name="Footnote")>/,'<\1>'). - gsub(/<(\/?text:(?:note-citation|note-body|note|p))>/,'<\1>') - parablock=footnote(parablock) - parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ - end - dob.obj=parray.join \ - + %{#{p_num[:display]}} \ - + '' - dob - end - def code(dob,p_num) #P5 - if dob.is==:code - dob.obj=dob.obj.gsub(/\s\s/,'  ') - parray=[] - dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| - set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' - parablock=group_clean(parablock) - parablock=parablock.gsub(/^\s*$/,'
    '). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1') #http ftp matches escaped, no decoration - parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ - end - dob.obj=parray.join \ - + %{#{p_num[:display]}} \ - + '' - end - dob - end - def table(dob,p_num) # - if dob.is ==:table - dob=footnote(dob) #check - table=SiSU_ODF_Format::Table.new(@md,dob,p_num) - dob=table.table - end - dob - end - def obj_break(dob) - if dob.is ==:break - br=SiSU_ODF_Format::FormatObjBreak.new(@md,dob) - if dob.obj==Mx[:br_page] \ - or dob.obj==Mx[:br_page_new] - dob=br.br_page - elsif dob.obj==Mx[:br_page_line] - dob=br.br_page_line - elsif dob.obj==Mx[:br_obj] - dob=br.obj_sep - end - end - dob - end - def odf_structure(md,dob) - @md,@dob=md,dob - dob=if dob.is !=:code - dob=image(dob) if dob.obj =~/#{Mx[:lnk_o]}[ ]*\S+?\.(?:png|jpg|gif)\s.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ - dob=text_link(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - dob=text_link_relative(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ - dob - else dob - end - p_num={ display: '', set_ref: '' } - if dob.is !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - if @env.odt_ocn? - if defined? dob.ocn \ - and dob.ocn.is_a?(Fixnum) - p_num=SiSU_ODF_Format::ParagraphNumber.new(dob.ocn).set_bookmark_and_display - end - end - end - if dob.is==:heading - @@odf[:body] << heading(dob,p_num).obj << break_line*2 - if SiSU_Env::ProcessingSettings.new(md).build.toc? - if dob.lv =~/[A-C1]/i - @@odf[:toc] << toc(dob,p_num).obj - end - end - elsif dob.is ==:verse - @@odf[:body] << poem(dob,p_num).obj << break_line*2 - elsif dob.is==:group - @@odf[:body] << group(dob,p_num).obj << break_line*2 - elsif dob.is==:block - @@odf[:body] << block(dob,p_num).obj << break_line*2 - elsif dob.is==:code - @@odf[:body] << code(dob,p_num).obj << break_line*2 - elsif dob.is==:table #elsif dob.obj =~ /<\-_&!@%~#\]\[*=$| \n+`#{Mx[:tc_p]}]/u - dir=SiSU_Env::InfoEnv.new(@md.fns) - dir.path.odt_bld - @data_mod,@endnotes,@level,@cont,@copen,@odf_contents_close=Array.new(6){[]} - @rcdc=false - (0..6).each { |x| @cont[x]=@level[x]=false } - (4..6).each { |x| @odf_contents_close[x]='' } - odf_tail #($1,$2) - bullet=image_src('bullet_09.png') - if bullet - if FileTest.file?("#{bullet}/bullet_09.png") - FileUtils::cp("#{bullet}/bullet_09.png","#{@env.processing_path.odt}/Pictures/.") - else STDERR.puts %{\t*WARN* did not find image - "#{bullet}/bullet_09.png" [#{__FILE__}:#{__LINE__}]} - end - end - odf_book_idx - odf_metadata - data.each do |dob| - #p dob.obj if dob.obj =~safe_characters and @md.opt.cmd =~/V/ #KEEP - dob.obj='' if dob.obj =~/#{Mx[:lv_o]}\d+:.*?#{Mx[:lv_c]}.+?#{Mx[:pa_non_object_dummy_heading]}/ #fix Mx[:lv_o] - para_array=[] - dob.obj=dob.obj.gsub(//,'>') - word=dob.obj.scan(/\S+|\n/) - if word - word.each do |w| # _ - / # | : ! ^ ~ - unless dob =~/^(?:#{Rx[:meta]}|%+ )/m - w=w.gsub(/&#(?:126|152);/,'~'). #126 usual - gsub(/ /,' ') - if w !~/(?:&\S{2,7}?;)+/ - w=w.gsub(/&/,'&') - end - if w !~/&\S{1,7}?;(?:&\S{1,7}?;)+/ #imperfect - w=w.gsub(/(&\S{1,7};)+&/,'\1&') - end - end - para_array << w - end - dob.obj=para_array.join(' ') - dob.obj=dob.obj.strip - end - if dob.is==:code #{Mx[:gr_o]}code#{Mx[:gr_c]}/ #fix #code-block: angle brackets special characters #fix - dob.obj=dob.obj.gsub(/(^|[^}])_(?:<|<)/m,'\1<').gsub(/(^|[^}])_(?:>|>)/m,'\1>'). - gsub(/(^|[^}])_(?:<|<)/m,'\1<').gsub(/(^|[^}])_(?:>|>)/m,'\1>') - end - if dob.of==:block - dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') - end - dob.obj=dob.obj.gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). - gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/,''). #check - gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/#{Mx[:mk_o]}[~-]##{Mx[:mk_c]}/,'') - if dob.is==:para \ - and dob.bullet_ - dob.obj=' ' + - dob.obj - end - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/,'
    '). - gsub(/©/,'©'). #too arbitrary - gsub(/.+?<-#>/,''). # remove dummy headings (used by html) #check - gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, - '\1'). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, - '\1'). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, - '\1'). - gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, - '\1'). - gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, - '\1'). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, - '\1'). - gsub(/­/u,'-'). - gsub(/ /u, ' '). # space identify - gsub(/ /u, ' '). # space identify - gsub(/·/u,'*'). - gsub(/[­–—]/u,'-'). #— – chk - gsub(/ < /i,'<'). - gsub(/\\copy(?:right)?\b/,'©'). - gsub(/\\trademark\b|\\tm\b/,'®'). - gsub(/\44/,'$'). #$ watch - gsub(/(.+?)<\/a>/,'\1'). - gsub(/#{Mx[:mk_o]}name#\S+?#{Mx[:mk_c]}/,'') # remove name links - wordlist=dob.obj.scan(/\S+/) - dob.obj=tidywords(wordlist).join(' ').strip - @rcdc=true if @rcdc==false \ - and (dob.obj =~/~metadata/ or dob =~/#{Mx[:lv_o]}1:meta#{Mx[:lv_x]}\s*Document Information/) #fix Mx[:lv_o] - if dob.is !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ #check - if defined? dob.ocn and dob.ocn =~/\d+/ - @p_num=SiSU_ODF_Format::ParagraphNumber.new(dob.ocn) - end - if dob.is ==:heading \ - || dob.is ==:para \ - || dob.is ==:group \ - || dob.is ==:verse \ - || dob.is ==:code \ - || dob.is ==:table \ - || dob.is ==:break - odf_structure(@md,dob) - end - if dob.obj ## Clean Prepared Text - dob.obj=dob.obj.gsub(//,' '). - gsub(/#{Mx[:tc_o]}.+?#{Mx[:tc_c]}/,' '). - gsub(/<:\S+>/,' ') - end - end - end - end - def pre - table=if @md.flag_tables - x=< - - - - - - - - - - - - - - - - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - else '' - end - x=< - - - -#{table} - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - @@odf[:head] << x - end - def publish - content=[] - br_pg=' ' - content << - @@odf[:head] << - @@odf[:toc] << - br_pg << - @@odf[:body] << - @@odf[:book_idx] << - br_pg << - @@odf[:metadata] << - @@odf[:tail] - SiSU_ODF::Source::Output.new(content,@md,@env).odf - @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } - end - end - class Output . - - 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: opendocument formatting, default opendocument template - -=end -module SiSU_ODF_Format - require_relative 'param' # param.rb - include SiSU_Param - include SiSU_Viz - class ParagraphNumber - def initialize(paranum) - @paranum=/(\d+)/m.match(paranum.to_s)[1] - end - def set_ref_and_display - set_ref=@paranum.gsub(/(\d+)/,' ') - disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) - { display: disp, set_ref: set_ref } - end - def set_bookmark_and_display - set_ref=@paranum.gsub(/(\d+)/,' ') - disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) - { display: disp, set_ref: set_ref } - end - def name - @paranum.gsub(/(\d+)/,'') - end - def goto - @paranum.gsub(/(\d+)/,'') - end - end - class FormatBookIndex - def initialize(idx_str) - @idx_str=idx_str - end - def book_idx_bookmark - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags - rgx_bookmark=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m - while @idx_str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m - link,url=$1,$2 - link,url=link.strip,url.strip - @idx_str=@idx_str.gsub(/&/m,"&") - ocn_lnk=if map_nametags[url] \ - and map_nametags[url][:ocn] - map_nametags[url][:ocn] - else nil - end - ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk) - if ocn_lnk and not ocn_lnk.empty? - @idx_str=@idx_str.sub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, - '\1'). - sub(rgx_bookmark, - %{#{link.strip}}) - else - puts %{name tag: "#{url}" not found} - @idx_str.sub!(rgx_bookmark,"#{link}") - end - end - @idx_str=@idx_str.gsub(/#{Xx[:protect]}/m,''). - sub(/,\s*$/m,''). - gsub(/\n/,'') - @idx_str='' + @idx_str + '' - end - end - class Tags - def set_bookmark_tag(dob) - tags='' - if dob.tags.length > 0 - dob.tags.each do |tag| - tags +=%{ } - end - end - tags - end - end - class FormatTextObject - def initialize(md,t_o) - @md,@t_o=md,t_o - if t_o.is_a?(Hash) - @txt =t_o[:txt] || nil - else - p t_o.class - p caller - end - rgx=/#{Mx[:en_a_o]}\d+\s+(.+?)#{Mx[:en_a_c]}/ - @txt=@txt.gsub(rgx,'\1') if @txt =~rgx - @vz=SiSU_Viz::Defaults.new - end - def scr_endnote_body - "#{@txt} " - end - def heading_body1 - end - def heading_body2 - end - def heading_body3 - end - def heading_body4 - end - def heading_body5 - end - def heading_body6 - end - end - class Table - @@tablehead,@@table_counter=0,0 #reinitialise on new file - @@tablefoot=[] #watch - @@fns='' - def initialize(md,dob,p_num) - @md,@dob,@p_num=md,dob,p_num - @txt=dob.obj - @vz=SiSU_Viz::Defaults.new - if @md.fns != @@fns - @@table_counter=0 - @@fns=@md.fns - end - end - def break_line - (@md.opt.act[:maintenance][:set]==:on) \ - ? "\n" : '' - end - def table_head_open(count) - type=(@dob.head_) \ - ? 1 - : 2 - alpha=case @dob.cols - when 1; 'A' - when 2; 'B' - when 3; 'C' - when 4; 'D' - when 5; 'E' - when 6; 'F' - when 7; 'G' - when 8; 'H' - when 9; 'I' - when 10; 'J' - when 11; 'K' - when 12; 'L' - when 13; 'M' - when 14; 'N' - else 'D' - end - tag=SiSU_ODF_Format::Tags.new.set_bookmark_tag(@dob) - %{#{@p_num[:set_ref]}#{tag}#{break_line}} + - %{#{break_line}} - end - def table_close(tablefoot='') - '' \ - + %{#{@p_num[:display]}} - end - def table_tag_cell(str,i) - txt_name_cell=if i==0 \ - and @dob.head_ - 'Table_Heading' - else 'P_table_cell' - end - str=str.gsub(/^~$/,'') # tilde / empty cell - %{#{break_line}} + - %{#{break_line}} + - %{#{str}} + - %{#{break_line}} + - %{#{break_line}} - end - def table_tag_row(str,i) - %{#{break_line}} + - %{#{str}} + - %{#{break_line}} - end - def table_tag_row_dump(str,i) - txt_name_row=if i==0 \ - and @dob.head_ - 'Table_Heading' - else 'P_table_cell' - end - %{#{break_line}} + - %{#{break_line}} + - %{#{break_line}} + - %{#{str}} + - %{#{break_line}} + - %{#{break_line}} + - %{#{break_line}} - end - def table_row(row,i) - row='' if row =~/^/,1] - @@tablefoot << m if m - row=row.gsub(//,'') - @cells=[] - row.split(/\s*#{Mx[:tc_p]}/).each do |cell| - @cells << table_tag_cell(cell,i) - end - row=@cells.join - row=table_tag_row(row,i) - row - end - def table - @@table_counter+=1 - table_head_open(@@table_counter) - @table=[] - @dob.obj.split(/\s*#{Mx[:tc_c]}/).each_with_index do |r,i| - @table << table_row(r,i) - end - @dob.obj= table_head_open(@@table_counter) + @table.join + table_close - @dob - end - end - class ODT_Head_1_2 - def initialize(md) - @md=md - @generator="#{@md.sisu_version[:project]} #{@md.sisu_version[:version]} #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" - end - def manifest_rdf - x=< - - - - - - - - - - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def meta_inf_manifest_xml(md) - images=[' '] - if md.ec[:image].length > 0 - md.ec[:image].each do |i| - images<<< -WOK - end - end - images=images.join('') - x=< - - - - - #{images} - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def meta_xml - x=< - - - #{@generator} - #{@md.generated} - #{@md.generated} - en-US - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def settings_xml - x=< - - - - 0 - 0 - 0 - 0 - true - false - - - view2 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 2 - true - 100 - false - - - - - true - false - false - true - true - false - true - false - false - - false - false - false - true - true - 0 - false - false - false - false - true - false - false - false - false - true - true - false - false - true - false - true - false - high-resolution - 1 - 0 - true - - - false - true - - false - true - false - true - false - true - false - - true - true - false - true - true - true - false - false - - false - 0 - false - false - true - true - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def styles_xml - x=< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def mimetype - x=<#{sep*60}
    } - @t_o - end - def obj_sep #center later - sep='--- ' - @t_o.obj=%{#{sep*20}} - @t_o - end - end - class XML - end -end -__END__ diff --git a/lib/sisu/v5/plaintext.rb b/lib/sisu/v5/plaintext.rb deleted file mode 100644 index 57838342..00000000 --- a/lib/sisu/v5/plaintext.rb +++ /dev/null @@ -1,576 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: plaintext text generation, stripped plaintext output (unix, - linefeed) - -=end -module SiSU_Plaintext - require_relative 'ao' # ao.rb - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'plaintext_format' # plaintext_format.rb - include SiSU_Plaintext_Format - require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'shared_txt' # shared_txt.rb - include SiSU_Param - include SiSU_Viz - @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 - @@tablefoot='' - class Source - def initialize(opt) - @opt=opt - unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ - puts "#{sf} not a processed file type" - end - end - def read - begin - md=SiSU_Param::Parameters.new(@opt).get - env=SiSU_Env::InfoEnv.new(@opt.fns) - unless @opt.act[:quiet][:set]==:on - tool=(@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? "#{env.program.text_editor} #{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}" - : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Plaintext',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Plaintext',tool).green_title_hi - if (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow - end - end - ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here - wrap_width=if defined? md.make.plaintext_wrap \ - and md.make.plaintext_wrap - md.make.plaintext_wrap - elsif defined? env.plaintext_wrap \ - and env.plaintext_wrap - env.plaintext_wrap - else 78 - end - #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 - SiSU_Plaintext::Source::Scroll.new(md,ao_array,wrap_width).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class Scroll appropriately within plaintext, consider - n=n.dup.to_s - if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ - fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added - fix.each do |x| - unless x.empty?; @n << x - end - end - else @n << n - end - end - notes=@n.flatten - notes.each do |e| - util=(e.to_s =~/^\[[\d*+]+\]:/) \ - ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) - : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) - wrap=util.line_wrap - wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m - wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB -\\1[\\2]: \\3 - GSUB - ) - else - wrap.gsub(/^(.+)\Z/m, <<-GSUB -\\1 - GSUB - ) - end - @@endnotes[:para] << "-#{wrap}" - @@endnotes[:end] << '' << wrap - end - @@endnotes - end - def plaintext_metadata - array=SiSU_Metadata::Summary.new(@md).plaintext.metadata - array.each do |meta| - tag,inf=meta.scan(/^.+?:\s|.+/) - if tag and inf - util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) - txt=util.line_wrap - @plaintext[:metadata] <<< @wrap_width - @plaintext[:body] << case lv - when 1; wrapped.upcase << break_line << decorate.heading_underscore.l1*times + p_num << break_line*2 - when 2; wrapped.upcase << break_line << decorate.heading_underscore.l2*times + p_num << break_line*2 - when 3; wrapped.upcase << break_line << decorate.heading_underscore.l3*times + p_num << break_line*2 - when 4; wrapped.upcase << break_line << decorate.heading_underscore.l4*times + p_num << break_line*2 - when 5; wrapped.upcase << break_line << decorate.heading_underscore.l5*times + p_num << break_line*2 - when 6; wrapped.upcase << break_line << decorate.heading_underscore.l6*times + p_num << break_line*2 - end - else - @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP - end - if @@endnotes[:para] \ - and not @@endnotes_ - @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} - elsif @@endnotes[:para] \ - and @@endnotes_ - end - @@endnotes[:para]=[] - end - def markup(data) # Used for major markup instructions - SiSU_Env::InfoEnv.new(@md.fns) - @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} - (0..6).each { |x| @cont[x]=@level[x]=false } - (4..6).each { |x| @plaintext_contents_close[x]='' } - plaintext_tail #($1,$2) - plaintext_metadata - table_message='[table omitted, see other document formats]' - data.each do |dob| - dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix - gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# - gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, - "#{decorate.bold.open}\\1#{decorate.bold.close}"). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, - "#{decorate.italics.open}\\1#{decorate.italics.close}"). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, - "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). - gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, - "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). - gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, - "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, - "#{decorate.insert.open}\\1#{decorate.insert.close}"). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, - "#{decorate.cite.open}\\1#{decorate.cite.close}"). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, - "#{decorate.strike.open}\\1#{decorate.strike.close}"). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, - "#{decorate.monospace.open}\\1#{decorate.monospace.close}") - unless dob.is==:code - dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") - extract_endnotes(dob) - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up - gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up - gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). - gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). - gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). - gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). - gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). - gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). - gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). - gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). - gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). - gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). - gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). - gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). - gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). - gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') - end - dob.obj=if dob.of==:block # watch - dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). - gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) - else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) - end - if dob.is==:code - dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< - gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< - end - dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). - gsub(/(.+?)<\/a>/m,'\1'). - gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links - gsub(/ |#{Mx[:nbsp]}/,' '). # decide on - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). - gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') - if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - p_num='' - if @env.plaintext_ocn? - if defined? dob.ocn \ - and dob.ocn.is_a?(Fixnum) - p_num=SiSU_Plaintext_Format::ParagraphNumber.new(dob.ocn).display - end - end - if dob.is==:heading \ - or dob.is==:para - plaintext_structure(dob,p_num) - elsif dob.is==:group \ - or dob.is==:block \ - or dob.is==:verse \ - or dob.is==:code \ - or dob.is==:table - @plaintext[:body] << dob.obj + p_num << break_line - elsif dob.is==:break - sp=' ' - ln='-' - @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ - or dob.obj==Mx[:br_page_new] \ - or dob.obj==Mx[:br_page_line] - "#{break_line}#{ln*40}#{break_line*2}" - elsif dob.obj ==Mx[:br_obj] - "#{break_line}#{sp*20}* * *#{break_line*2}" - end # following empty line (break_line) missing, fix - end - dob='' if (dob.obj =~// \ - and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote - if dob ## Clean Prepared Text - dob.obj=dob.obj.gsub(//,' '). - gsub(/<:\S+>/,' ') - end - end - end - @plaintext - end - def publish(plaintext) - divider='=' - content=[] - content << plaintext[:open] - content << plaintext[:head] - content << plaintext[:body] - content << @@endnotes[:end] if @@endnotes_ - content << "#{break_line}#{divider*@wrap_width}#{break_line}" - content << plaintext[:metadata] - content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? - content << plaintext[:tail] - Output.new(content,@md).plaintext - @@endnotes={ para: [], end: [] } - end - end - class Output 0 - para.each do |line| - if line - line=line.gsub(/[ \t]+$/m,''). - gsub(/^\A[ ]*\Z/m,'') - (line=~/^\A\Z/) \ - ? (emptyline+=1) - : emptyline=0 - if emptyline < 2 #remove additional empty lines - file_plaintext.puts line - end - end - end - else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ - end - end - file_plaintext.close - end - end - end -end -__END__ - bold_o: '*', bold_c: '*', - #bold_o: '!', bold_c: '!', - #emphasis_o: '*', emphasis_c: '*', - italics_o: '/', italics_c: '/', - underscore_o: '_', underscore_c: '_', - cite_o: '"', cite_c: '"', - insert_o: '+', insert_c: '+', - strike_o: '-', strike_c: '-', - superscript_o: '^', superscript_c: '^', - subscript_o: '[', subscript_c: ']', - hilite_o: '*', hilite_c: '*', - monospace_o: '', monospace_c: '', - po_bold_o: '!{', po_bold_c: '}!', - po_italics_o: '/{', po_italics_c: '}/', - po_underscore_o: '_{', po_underscore_c: '}_', - po_cite_o: '"{', po_cite_c: '}"', - po_insert_o: '+{', po_insert_c: '}+', - po_strike_o: '-{', po_strike_c: '}-', - po_superscript_o: '^{', po_superscript_c: '}^', - po_subscript_o: ',{', po_subscript_c: '},', - po_hilite_o: '*{', po_hilite_c: '}*', - po_monospace_o: '#{', po_monospace_c: '}#', diff --git a/lib/sisu/v5/plaintext_format.rb b/lib/sisu/v5/plaintext_format.rb deleted file mode 100644 index acad8828..00000000 --- a/lib/sisu/v5/plaintext_format.rb +++ /dev/null @@ -1,104 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: plaintext formatting template - -=end -module SiSU_Plaintext_Format - require_relative 'param' # param.rb - include SiSU_Param - include SiSU_Viz - class ParagraphNumber - def initialize(paranum) - @paranum=/(\d+)/m.match(paranum.to_s)[1] - end - def display - @paranum.gsub(/(\d+)/,"\n#{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}") - end - def name #unused - @paranum.gsub(/(\d+)/,'\1') - end - def goto #unused - @paranum.gsub(/(\d+)/,'"#\1"') - end - end - class FormatTextObject - def initialize(md,t_o) - @md,@t_o=md,t_o - if t_o.is_a?(Hash) - @txt =t_o[:txt] || nil - @lnk_url =t_o[:lnk_url] || nil - @lnk_txt =t_o[:lnk_txt] || nil - else - p t_o.class - p caller - end - rgx=/^#{Rx[:lv]}/ - @txt=@txt.gsub(rgx,'') if @txt =~rgx - rgx=/#{Mx[:en_a_o]}[\d*+]+\s+(.+?)#{Mx[:en_a_c]}/ - @txt=@txt.gsub(rgx,'\1') if @txt =~rgx - @vz=SiSU_Viz::Defaults.new - end - def scr_endnote_body - "#{@txt} " - end - end - class XML - end -end -__END__ diff --git a/lib/sisu/v5/share_src.rb b/lib/sisu/v5/share_src.rb deleted file mode 100644 index 69dd7bb9..00000000 --- a/lib/sisu/v5/share_src.rb +++ /dev/null @@ -1,102 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: share sisu source markup file, copy it to output directory! - -=end -module SiSU_Markup - require_relative 'shared_sisupod_source' # shared_sisupod_source.rb - include SiSU_Source - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - class Source < SiSU_Source::SiSUpodSource - def initialize(opt,build=nil,place=nil) - super(opt,build,place) - @opt=opt - end - def read - unless @opt.act[:quiet][:set]==:on - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share document markup text source',@opt.fns).cyan_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share document markup text source',@opt.fns).cyan_title_hi - end - if FileTest.directory?(@path_pod[:fnb]) - FileUtils::mkdir_p(@file.output_path.src.dir) unless FileTest.directory?(@file.output_path.src.dir) - v=(@opt.act[:maintenance][:set]==:on) \ - ? 'v' : '' - system(%{ - rsync -a#{v} #{@path_pod[:fnb]} #{@file.output_path.sisupod.dir} - chbk=`pwd` - cd #{@file.output_path.sisupod.dir} - for I in `find -type d` ; do chmod 755 $I ; done - for I in `find -type f` ; do chmod 644 $I ; done - cd ${chbk} - }) - else - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new('',"#{@opt.fno} not available").blue_tab - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/share_src_kdissert.rb b/lib/sisu/v5/share_src_kdissert.rb deleted file mode 100644 index b696891e..00000000 --- a/lib/sisu/v5/share_src_kdissert.rb +++ /dev/null @@ -1,90 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: share sisu source markup file, copy it to output directory! - -=end -module SiSU_KdiSource - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - class Source - require 'fileutils' - include FileUtils - def initialize(opt) - @opt=opt - @env=SiSU_Env::InfoEnv.new(@opt.fns) - @output_path="#{@env.path.output}/#{@opt.fnb}" - end - def read - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share Kdissert Source Document!',@opt.fnb).green_hi_blue unless @opt.act[:quiet][:set]==:on - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Copy kdissert file to output directory","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on - FileUtils::mkdir_p(@env.path.output) unless FileTest.directory?(@env.path.output) - FileUtils::mkdir_p(@output_path) unless FileTest.directory?(@output_path) - if FileTest.directory?(@output_path) - if @opt.fns =~/\.kdi\._sst$/ \ - and FileTest.file?(@opt.fnb) - FileUtils::cp(@opt.fnb,@output_path) - end - else - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Output directory does not exist","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on - exit - end - end - end -end -__END__ diff --git a/lib/sisu/v5/shared_html.rb b/lib/sisu/v5/shared_html.rb deleted file mode 100644 index 84c89ecf..00000000 --- a/lib/sisu/v5/shared_html.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: shared html parts - -=end -module SiSU_HTML_Shared - require_relative 'defaults' # defaults.rb - require_relative 'html_table' # html_table.rb - class TableHTML < SiSU_HTML_Table::TableHTML - end -end -__END__ diff --git a/lib/sisu/v5/shared_html_lite.rb b/lib/sisu/v5/shared_html_lite.rb deleted file mode 100644 index e46510ea..00000000 --- a/lib/sisu/v5/shared_html_lite.rb +++ /dev/null @@ -1,325 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: modules shared by db and flatfile output generators, mostly - xml/xhtml/html formatting - -=end -module SiSU_FormatShared - require_relative 'defaults' # defaults.rb - include SiSU_Viz - class CSS_Format - require_relative 'defaults' # defaults.rb - require_relative 'particulars' # particulars.rb - @@fns=nil - def initialize(md,t_o) - @md,@t_o=md,t_o - @txt=@t_o.obj - @id=@ocn=@t_o.ocn if defined? @t_o.ocn - @lv=@t_o.lv.to_s if @t_o.is==:heading - if @md.fns != @@fns - @@fns,@@hname=@md.fns,'' - end - @hname=if defined? @t_o.name \ - and not @t_o.name.to_s.empty? - @@hname=@t_o.name - else @@hname - end - @tab="\t" - @brace_url=SiSU_Viz::Defaults.new.url_decoration - @@tablehead,@@tablefoot=[],[] - @vz=SiSU_Viz::Defaults.new - @env=SiSU_Env::InfoEnv.new(@md.fns) - @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" - end - def urls(data) - @words=[] - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map - data.each do |word| - @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures - 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] - ins=if u \ - and u.strip !~/^image$/ - %{
    [#{png}]#{caption}} - else %{[#{png}] #{caption}} - end - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) - else - u=case u - when /^https?:\/\// - u - when /^:/ - u=u.gsub(/^:/,'') - "#{@env.url.root}/#{u}" - when /^\.\.\// # can remove - u=u.gsub(/^\.\.\//,'') - "#{@env.url.root}/#{u}" - else - "#{@env.url.root}/#{@md.fnb}/#{map_nametags[u][:segname]}#{Sfx[:html]}##{u}" - end - link=m[/(.+)/m] - png=m.scan(/\S+/)[0].strip - link=link.strip - ins=%{#{link}} - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). - gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) - word - end - word - else word - end - word - end - @words=@words.join(' ') - end - def markup_generic(s) - s=s.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"'). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_c]}/,'-{\1}-'). - gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). - gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd - gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~') - end - def markup_object(t_o) - s=t_o.obj - s=if t_o.is !=:code - s=markup_generic(s) - if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) - words=urls(wm) - s=s.gsub(/.+/m,words) - end - s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:url_o]}[_\\](\S+?)#{Mx[:url_c]}/,'\1'). #http ftp matches escaped, no decoration - gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url - gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{\\1#{@brace_url.xml_open}\\2#{@brace_url.xml_close}\\3}) #http ftp matches with decoration - else - s.gsub(//m,'>') - end - s - end - def markup_note(s) - s=markup_generic(s) - if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) - words=urls(wm) - s=s.gsub(/.+/m,words) - end - s=s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1\2'). #http ftp matches escaped, no decoration - gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration - end - def paragraph - %{

    #{@txt}

    \n} # << "\n" - end - def endnote(nr,en) #used only by db - txt=markup_note(en) - < -#{nr}. #{txt} -

    -GSUB - end - def tag_header(h) - %{

    #{h[:txt]}

    \n} # << "\n" - end - def tag_para(h) - %{

    #{h[:txt]}

    \n} << "\n" - end - def lev_toc_hname - %{

    #{@txt}

    \n} #<< "\n" - end - def lev_toc - h={ txt: txt, class: "toc#{@lv}", type: 'toc' } - tag_para(h) - end - def lev4_plus - txt=markup_object(@t_o) - h={ txt: txt, class: "h#{@lv}", type: 'substantive', id: @ocn, header: @hname } - tag_header(h) - end - def lev4_minus - txt=markup_object(@t_o) - h={ txt: txt, class: "h#{@t_o.ln}", type: 'substantive', id: @ocn } - tag_para(h) - end - def norm_comment - h={ txt: @t_o.obj, class: 'norm', type: 'comment' } - tag_para(h) - end - def norm - txt=markup_object(@t_o) - h={ txt: txt, class: 'norm', type: 'substantive', id: @ocn } - tag_para(h) - end - def code - txt=markup_object(@t_o) - h={ txt: "#{txt}", class: 'code', type: 'substantive', id: @ocn } - tag_para(h) - end - def indent(t) - txt=markup_object(@t_o) - h={ txt: txt, class: "indent#{t}", type: 'substantive', id: @ocn } - tag_para(h) - end - def hang_indent(f,t) - txt=markup_object(@t_o) - h={ txt: txt, class: "hang#{f}indent#{t}", type: 'substantive', id: @ocn } - #h={ txt: txt, class: "h#{f}i#{t}", type: 'substantive', id: @ocn } - tag_para(h) - end - def para_table - %{

    } - end - def ocn - %{} << "\n" - end - def html_table # get rid of use html_table - @new_content=[] - @txt.split(/\n/).each do |parablock| - m=parablock[//,1] - @@tablefoot << m if m - parablock=parablock.gsub(//,'') - @@tablehead=1 if parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u - parablock=parablock.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+)#{Mx[:gr_c]}/, - %{

    } + + %{#{para_table}}). + gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{} + + %{#{para_table}}). + gsub(/#{Mx[:tc_c]}/, '
    } + + %{#{para_table}}). + gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{} + + %{#{para_table}}). + gsub(/#{Mx[:tc_c]}/, '
    }) - if parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ - tablefoot=[] - @@tablefoot.each {|x| tablefoot << %{

    #{x}

    \n}} - @@tablefoot=[] - parablock=parablock.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/, - %{#{@vz.table_close}\n}) # + - end - if @@tablehead==1 - if parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u - parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{\n
    } + - %{\n') - @@tablehead=0 - end - parablock - else - parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{\n} + - %{\n') - parablock - end - @new_content << parablock - end - @new_content.join - end - end - class CSS_FormatGeneric #does CSS_Format in one definition, needs to be told about attrib, despite brevity of generic, easier to see structure with CSS_Format - def initialize(attrib='',txt='',id=nil,ocnd=nil,ocns=nil,lv='',hname=nil) - @tab="\t" - @attrib=attrib - @txt=txt - @lv=lv.to_s - @hname=hname.to_s - @id=@ocn=id - end - def paragraph - attrib=%{class="#{@attrib}" } - if @ocn - id=%{id="#{@ocn}" } - type=%{type="substantive" } - else - id=%{id="none" } - type=%{type="comment" } - end - header=%{header="#{@hname}" } if @hname - %{

    #{@txt}

    \n} #<< "\n" - end - def para - paragraph - end - end -end -__END__ diff --git a/lib/sisu/v5/shared_sisupod_source.rb b/lib/sisu/v5/shared_sisupod_source.rb deleted file mode 100644 index 021d2e0f..00000000 --- a/lib/sisu/v5/shared_sisupod_source.rb +++ /dev/null @@ -1,312 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: create sisupod filetype and copy it to output directory! - -=end -module SiSU_Source - include SiSU_Env - class SiSUpodSource - require_relative 'sysenv' # sysenv.rb - require_relative 'particulars' # particulars.rb - def initialize(opt,build=nil,place=nil) - @opt=opt - @date=SiSU_Env::InfoDate.new.dt - @env=SiSU_Env::InfoEnv.new(opt.fns) - @ver=SiSU_Env::InfoVersion.instance.get_version - @v=(@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? 'v' : '' - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - @file=@particulars.file - @local_path="#{@file.output_path.sisupod.dir}" - processing_sisupod=@env.processing_path.processing_sisupod(opt) - processing_sisupod.make - path_pod=processing_sisupod.paths[:sisupod] - path_pod_fnb=processing_sisupod.paths[:fnb] - FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod) - @path_pod={ - fnb: path_pod_fnb, - pod: path_pod, - doc: path_pod + '/' + Gt[:doc] + '/' + opt.lng, - po: path_pod + '/' + Gt[:po] + '/' + opt.lng, - pot: path_pod + '/' + Gt[:pot], - conf: path_pod + '/' + Gt[:conf], - image: path_pod + '/' + Gt[:image], - audio: path_pod + '/' + Gt[:audio], - video: path_pod + '/' + Gt[:video], - } - end - def read - unless @opt.act[:quiet][:set]==:on - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble SiSU source',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_hi_blue - : '' - end - unless @opt.fns.empty? - directories - pod_source_build #this needs to be built in case of multi-lingual for all of them, before single pass tar - end - end - def directories - SiSU_Env::InfoEnv.new.sisupod_v4(@opt) - end - def images_extract(f,images) # consider using param info - rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m - if f !~/^%+\s/ \ - and f =~rgx_image - images << f.scan(rgx_image).uniq - end - images.flatten - end - def pod_source_build - @pwd=Dir.pwd - @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/ - @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ - @rgx_doc_import=/^<<\s*(\S+?\.ss[ti])/ - file_array=IO.readlines(@opt.fno,'') - images,doc_import=[],[] - doc_import_dir=@opt.sub_location - file_array.each do |f| #% work area - if f !~/^%+\s/ - f=f.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image) - if f !~/^%+\s/ \ - and f =~@rgx_image - images=images_extract(f,images) - end - if @opt.fno =~/\.ssm$/ - doc_import << f.scan(@rgx_doc_import) if f =~@rgx_doc_import - end - end - end - if doc_import.length > 0 - doc_import=doc_import.uniq.flatten - doc_import.each do |fn| - file_array=IO.readlines(fn,'') - file_array.each do |f| #% work area - if f !~/^%+\s/ \ - and f =~@rgx_image - images=images_extract(f,images) - end - end - end - end - gi=SiSU_Env::GetInit.new - unless FileTest.file?("#{@path_pod[:conf]}/#{gi.makefile_name}") - if gi.makefile \ - && FileTest.file?(gi.makefile) - FileUtils::mkdir_p(@path_pod[:conf]) unless FileTest.directory?(@path_pod[:conf]) - FileUtils::cp(gi.makefile,"#{@path_pod[:conf]}/#{gi.makefile_name}") - end - #get images from makefile, consider placing in param - end - if images \ - and images.length > 1 - images=images.flatten.uniq - images.delete_if {|x| x =~/https?:\/\// } - #images=images.sort - FileUtils::mkdir_p(@path_pod[:image]) - #unattractive hard coding ... ! - image_path='_sisu/image' - images_pwd="#{@opt.base_path}/#{image_path}" - ##sequence copies base images, defaults used in all html outputs - #image_source_base='/usr/share/sisu/image' - #dir_pwd=Dir.pwd - #Dir.chdir(image_source_base) - #base_images=Dir.glob('*') - #base_images.each do |i| - # FileUtils::cp_r(i,"#{images_path_pod}/#{i}") - #end - #Dir.chdir(dir_pwd) - if FileTest.directory?(images_pwd) - images=images.uniq - images.each do |i| - if FileTest.file?("#{images_pwd}/#{i}") - FileUtils::cp("#{images_pwd}/#{i}","#{@path_pod[:image]}/#{i}") - else STDERR.puts %{\t*WARN* did not find image - "#{images_pwd}/#{i}" [#{__FILE__}:#{__LINE__}]} - end - end - else STDERR.puts %{\t*WARN* did not find - #{images_pwd} #{@path_pod[:image]} [#{__FILE__}:#{__LINE__}]} - end - end - if doc_import.length > 0 \ - and @opt.fno =~/\.ssm$/ - doc_import.each do |f| - if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}") - FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f}","#{@path_pod[:doc]}/#{f}") - else STDERR.puts %{\t*WARN* did not find image - "#{@opt.base_path}#{doc_import_dir}/#{f}" [#{__FILE__}:#{__LINE__}]} - end - end - end - x=@env.document_language_versions_found #check multiple document language versions (param not used) - if x[:f] \ - and x[:f].length > 0 #store multiple document language versions, sisupod - x[:f].each do |f| - FileUtils::mkdir_p(@path_pod[:doc]) unless FileTest.directory?(@path_pod[:doc]) - if f[:f] =~/\~(\S{2,3})\.ss[tm]$/ - lng_f=$1 - if @opt.lng == lng_f - if @opt.fno =~/\.ssm$/ - if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") - FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - else - if FileTest.file?("#{@opt.base_path}/#{f[:f]}") - cpy= :no - cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ - or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ - :yes - elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ - and @opt.f_pth[:lng_is] == 'en' - :yes - else :no - end - if cpy == :yes - FileUtils::cp("#{@opt.base_path}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - end - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - end - end - else - if @opt.fno =~/\.ssm$/ - if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") - FileUtils::cp_r("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - else - if FileTest.file?("#{@opt.base_path}/#{f[:f]}") - cpy= :no - cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ - or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ - :yes - elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ - and @opt.f_pth[:lng_is] == 'en' - :yes - else :no - end - if cpy == :yes - FileUtils::cp("#{@opt.base_path}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - end - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - end - end - end - end #NB not all possibilies met, revisit, also in case of composite file may wish to add README - end - end -end -__END__ -question?: should you permit the packing of multiple documents in single .xz ? - - open @opt.fns, parse file - extract from file content: - images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image - - remove previously existing contents of _/sisu/sisupod & - make directory structure: - -v3 --> - _sisu - sisupod - doc - manifest.txt - en/content.sst [file content] - fr/content.sst - _sisu - conf - image (ln -s ../../image) - audio (ln -s ../../audio) - video (ln -s ../../video) - image [all images for specific document gathered here] - audio - video - -v2 --> - _sisu - sisupod - content.sst [file content] - filename.sst [link to content.sst] - _sisu/ - image/ [all images for specific document gathered here] - -sisu - _sisu - sisurc.yml - convert/ - standard_terms/ - image - processing - ao/ - tex/ - texinfo/ - tune/ - sisupod - -special case - -composite file (master), e.g. -SiSU.ssm diff --git a/lib/sisu/v5/shared_txt.rb b/lib/sisu/v5/shared_txt.rb deleted file mode 100644 index 0e3b6018..00000000 --- a/lib/sisu/v5/shared_txt.rb +++ /dev/null @@ -1,236 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: modules shared by flatfile output generators - -=end -module SiSU_TextUtils - class Wrap - def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil) - @para,@n_char_max,@n_indent=para,n_char_max,n_indent - @n_char_max_extend = n_char_max - @n_hang=n_hang ? n_hang : @n_indent - end - def break_line - "\n" - end - def line_wrap - space=' ' - spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang - line=0 - out=[] - out[line]='' - @para=@para.gsub(/
    /,' \\ '). - gsub(/#{Mx[:br_nl]}/,"\n\n") - words=@para.scan(/\n\n|\s+\\\s+|
    |\S+/m) - while words != '' - word=words.shift - if not word - out[line] unless out[line].empty? #check - break - elsif word =~/
    / - word=nil - out[line]=out[line].gsub(/
    /,'') - line=line - elsif word =~/\n\n/ - word="\n" - @n_char_max_extend = @n_char_max - line += 1 - elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ - and out[line] =~/\S+/ - @n_char_max_extend = @n_char_max - out[line].squeeze!(' ') - line += 1 - end - if word - out[line]=if out[line] \ - and out[line] !~/\S+$/m - "#{out[line]}#{word}" - elsif out[line] \ - and out[line] =~/\S+/ - "#{out[line]} #{word}" - else "#{word.strip}" - end - end - @oldword=word if word =~/\S+/ - end - spaces_hang + out.join(spaces_indent) - end - def line_wrap_indent1 - @n_indent,@n_hang=2,2 - line_wrap - end - def line_wrap_endnote - @n_indent,@n_hang=4,2 - line_wrap - end - def array_wrap - if @para.is_a?(Array) - @arr=[] - @para.each do |line| - @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap - end - end - @arr - end - end - class HeaderScan - def initialize(md,para) - @md,@p=md,para - end - def extract(tag,tag_content,type,attrib) - if dc_tag \ - and dc_content - [dc_tag,dc_content,{dc_tag=>dc_content}] - else nil - end - end - def header(tag,tag_content,type='',attrib='') #this will break stuff and must be tested thoroughly 20060825 - @tag,@tag_content,@type,@attrib=tag,tag_content,type,attrib - def label #element - @tag - end - def type - @type - end - def text - @tag_content - end - def info #element text - @tag_content - end - def attribute - @attrib - end - def element - @tag - end - def attrib - @attrib - end - def el - @tag - end - self - end - def start_is_match - case @p - when /^#{Mx[:meta_o]}(title)#{Mx[:meta_c]}\s*(.+?)$/; header($1,@md.title.full,'meta','dc') #dc 1 - when /^#{Mx[:meta_o]}(creator|author)#{Mx[:meta_c]}\s*(.+?)$/; header('creator',$2,'meta','dc') #dc 2 - when /^#{Mx[:meta_o]}(subject)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 3 - when /^#{Mx[:meta_o]}(description)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 4 - when /^#{Mx[:meta_o]}(publisher)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 5 - when /^#{Mx[:meta_o]}(contributor)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 6 - when /^#{Mx[:meta_o]}(date)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 7 - when /^#{Mx[:meta_o]}(date\.created)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.issued)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.available)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.valid)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.modified)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(type)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 8 - when /^#{Mx[:meta_o]}(format)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 9 - when /^#{Mx[:meta_o]}(identifier)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 10 - when /^#{Mx[:meta_o]}(source)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 11 - when /^#{Mx[:meta_o]}(language)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 12 - when /^#{Mx[:meta_o]}(relation)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 13 - when /^#{Mx[:meta_o]}(coverage)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 14 - when /^#{Mx[:meta_o]}(rights)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 15 - when /^#{Mx[:meta_o]}(keywords)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(copyright)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(translator|translated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('translator',$2) - when /^#{Mx[:meta_o]}(illustrator|illustrated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('illustrator',$2) - when /^#{Mx[:meta_o]}(prepared_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(digitized_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(comments?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(abstract)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(tags?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(catalogue)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_loc)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_loc',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_dewey)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_dewey',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_pg)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_pg',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_isbn)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_isbn',$2,'meta','extra') - when /^#{Mx[:meta_o]}(toc|structure)#{Mx[:meta_c]}\s*(.+?)$/; header('structure',$2,'process','instruct') - when /^#{Mx[:meta_o]}(level|page|markup)#{Mx[:meta_c]}\s*(.+?)$/; header('markup',$2,'process','instruct') - when /^#{Mx[:meta_o]}(bold)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(italics|itali[sz]e)#{Mx[:meta_c]}\s*(.+?)$/; header('italicize',$2,'process','instruct') - when /^#{Mx[:meta_o]}(vocabulary|wordlist)#{Mx[:meta_c]}\s*(.+?)$/; header('vocabulary',$2,'process','instruct') - when /^#{Mx[:meta_o]}(css|stylesheet)#{Mx[:meta_c]}\s*(.+?)$/; header('css',$2,'process','instruct') - when /^#{Mx[:meta_o]}(links)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(prefix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') #add a & b - when /^#{Mx[:meta_o]}(suffix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(information)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(contact)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(rcs|cvs)#{Mx[:meta_c]}\s*(.+?)$/; header('version',$2,'process','instruct') - else nil - end - end - def dublin - if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ - start_is_match - else nil - end - end - def meta - if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ - start_is_match - else nil - end - end - end -end -__END__ diff --git a/lib/sisu/v5/shared_xhtml.rb b/lib/sisu/v5/shared_xhtml.rb deleted file mode 100644 index c9534823..00000000 --- a/lib/sisu/v5/shared_xhtml.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: shared html parts - -=end -module SiSU_XHTML_Shared - require_relative 'defaults' # defaults.rb - require_relative 'xhtml_table' # xhtml_table.rb - class TableXHTML < SiSU_XHTML_Table::TableXHTML - end -end -__END__ diff --git a/lib/sisu/v5/shared_xml.rb b/lib/sisu/v5/shared_xml.rb deleted file mode 100644 index 76b5374b..00000000 --- a/lib/sisu/v5/shared_xml.rb +++ /dev/null @@ -1,721 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: common file for xml generation -=end -module SiSU_XML_Munge - class Trans - require_relative 'defaults' # defaults.rb - def initialize(md) - @md=md - @sys=SiSU_Env::SystemCall.new - @dir=SiSU_Env::InfoEnv.new(@md.fns) - @brace_url=SiSU_Viz::Defaults.new.url_decoration - if @md.sem_tag - @ab ||=semantic_tags.default - end - end - def semantic_tags - def default - { - pub: 'publication', - conv: 'convention', - vol: 'volume', - pg: 'page', - cty: 'city', - org: 'organization', - uni: 'university', - dept: 'department', - fac: 'faculty', - inst: 'institute', - co: 'company', - com: 'company', - conv: 'convention', - dt: 'date', - y: 'year', - m: 'month', - d: 'day', - ti: 'title', - au: 'author', - ed: 'editor', #editor? - v: 'version', #edition - n: 'name', - fn: 'firstname', - mn: 'middlename', - ln: 'lastname', - in: 'initials', - qt: 'quote', - ct: 'cite', - ref: 'reference', - ab: 'abreviation', - def: 'define', - desc: 'description', - trans: 'translate', - } - end - self - end - def char_enc #character encode - def utf8(dob='') - if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn - str=if defined? dob.obj then dob.obj - elsif dob.is_a?(String) then dob - end - if str - #¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûü - #¢£¥§©ª«®°±²³µ¶¹º»¼½¾×÷ - str=str.gsub(//um,'>'). # '>' # > - gsub(/¢/um,'¢'). # '¢' # ¢ - gsub(/£/um,'£'). # '£' # £ - gsub(/¥/um,'¥'). # '¥' # ¥ - gsub(/§/um,'§'). # '§' # § - gsub(/©/um,'©'). # '©' # © - gsub(/ª/um,'ª'). # 'ª' # ª - gsub(/«/um,'«'). # '«' # « - gsub(/®/um,'®'). # '®' # ® - gsub(/°/um,'°'). # '°' # ° - gsub(/±/um,'±'). # '±' # ± - gsub(/²/um,'²'). # '²' # ² - gsub(/³/um,'³'). # '³' # ³ - gsub(/µ/um,'µ'). # 'µ' # µ - gsub(/¶/um,'¶'). # '¶' # ¶ - gsub(/¹/um,'¹'). # '¹' # ¹ - gsub(/º/um,'º'). # 'º' # º - gsub(/»/um,'»'). # '»' # » - gsub(/¼/um,'¼'). # '¼' # ¼ - gsub(/½/um,'½'). # '½' # ½ - gsub(/¾/um,'¾'). # '¾' # ¾ - gsub(/×/um,'×'). # '×' # × - gsub(/÷/um,'÷'). # '÷' # ÷ - gsub(/¿/um,'¿'). # '¿' # ¿ - gsub(/À/um,'À'). # 'À' # À - gsub(/Á/um,'Á'). # 'Á' # Á - gsub(/Â/um,'Â'). # 'Â' #  - gsub(/Ã/um,'Ã'). # 'Ã' # à - gsub(/Ä/um,'Ä'). # 'Ä' # Ä - gsub(/Å/um,'Å'). # 'Å' # Å - gsub(/Æ/um,'Æ'). # 'Æ' # Æ - gsub(/Ç/um,'Ç'). # 'Ç' # Ç - gsub(/È/um,'È'). # 'È' # È - gsub(/É/um,'É'). # 'É' # É - gsub(/Ê/um,'Ê'). # 'Ê' # Ê - gsub(/Ë/um,'Ë'). # 'Ë' # Ë - gsub(/Ì/um,'Ì'). # 'Ì' # Ì - gsub(/Í/um,'Í'). # 'Í' # Í - gsub(/Î/um,'Î'). # 'Î' # Î - gsub(/Ï/um,'Ï'). # 'Ï' # Ï - gsub(/Ð/um,'Ð'). # 'Ð' # Ð - gsub(/Ñ/um,'Ñ'). # 'Ñ' # Ñ - gsub(/Ò/um,'Ò'). # 'Ò' # Ò - gsub(/Ó/um,'Ó'). # 'Ó' # Ó - gsub(/Ô/um,'Ô'). # 'Ô' # Ô - gsub(/Õ/um,'Õ'). # 'Õ' # Õ - gsub(/Ö/um,'Ö'). # 'Ö' # Ö - gsub(/Ø/um,'Ø'). # 'Ø' # Ø - gsub(/Ù/um,'Ù'). # 'Ù' # Ù - gsub(/Ú/um,'Ú'). # 'Ú' # Ú - gsub(/Û/um,'Û'). # 'Û' # Û - gsub(/Ü/um,'Ü'). # 'Ü' # Ü - gsub(/Ý/um,'Ý'). # 'Ý' # Ý - gsub(/Þ/um,'Þ'). # 'Þ' # Þ - gsub(/ß/um,'ß'). # 'ß' # ß - gsub(/à/um,'à'). # 'à' # à - gsub(/á/um,'á'). # 'á' # á - gsub(/â/um,'â'). # 'â' # â - gsub(/ã/um,'ã'). # 'ã' # ã - gsub(/ä/um,'ä'). # 'ä' # ä - gsub(/å/um,'å'). # 'å' # å - gsub(/æ/um,'æ'). # 'æ' # æ - gsub(/ç/um,'ç'). # 'ç' # ç - gsub(/è/um,'è'). # 'è' # è - gsub(/é/um,'é'). # '´' # é - gsub(/ê/um,'ê'). # 'ˆ' # ê - gsub(/ë/um,'ë'). # 'ë' # ë - gsub(/ì/um,'ì'). # 'ì' # ì - gsub(/í/um,'í'). # '´' # í - gsub(/î/um,'î'). # 'î' # î - gsub(/ï/um,'ï'). # 'ï' # ï - gsub(/ð/um,'ð'). # 'ð' # ð - gsub(/ñ/um,'ñ'). # 'ñ' # ñ - gsub(/ò/um,'ò'). # 'ò' # ò - gsub(/ó/um,'ó'). # 'ó' # ó - gsub(/ô/um,'ô'). # 'ô' # ô - gsub(/õ/um,'õ'). # 'õ' # õ - gsub(/ö/um,'ö'). # 'ö' # ö - gsub(/ø/um,'ø'). # 'ø' # ø - gsub(/ù/um,'ú'). # 'ù' # ú - gsub(/ú/um,'û'). # 'ú' # û - gsub(/û/um,'ü'). # 'û' # ü - gsub(/ü/um,'ý'). # 'ü' # ý - gsub(/þ/um,'þ'). # 'þ' # þ - gsub(/ÿ/um,'ÿ'). # 'ÿ' # ÿ - gsub(/‘/um,'‘'). # '‘' # ‘ - gsub(/’/um,'’'). # '’' # ’ - gsub(/“/um,'“'). # “ # “ - gsub(/”/um,'”'). # ” # ” - gsub(/–/um,'–'). # – # – - gsub(/—/um,'—'). # — # — - gsub(/∝/um,'∝'). # ∝ # ∝ - gsub(/∞/um,'∞'). # ∞ # ∞ - gsub(/™/um,'™'). # ™ # ™ - gsub(/✠/um,'✠'). # ✗ # ✠ - gsub(/ /um,' '). # space identify - gsub(/ /um,' ') # space identify - end - dob=if defined? dob.obj - dob.obj=str - dob - elsif dob.is_a?(String) - str - end - dob - end - end - def html(dob='') - if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn - dob.obj=dob.obj.gsub(/ /u,' '). # space identify - gsub(/ /u,' ') # space identify - else - dob.obj=dob.obj.gsub(/¢/u,'¢'). # ¢ - gsub(/£/u,'£'). # £ - gsub(/¥/u,'¥'). # ¥ - gsub(/§/u,'§'). # § - gsub(/©/u,'©'). # © - gsub(/ª/u,'ª'). # ª - gsub(/«/u,'«'). # « - gsub(/®/u,'®'). # ® - gsub(/°/u,'°'). # ° - gsub(/±/u,'±'). # ± - gsub(/²/u,'²'). # ² - gsub(/³/u,'³'). # ³ - gsub(/µ/u,'µ'). # µ - gsub(/¶/u,'¶'). # ¶ - gsub(/¹/u,'¹'). # ¹ - gsub(/º/u,'º'). # º - gsub(/»/u,'»'). # » - gsub(/¼/u,'¼'). # ¼ - gsub(/½/u,'½'). # ½ - gsub(/¾/u,'¾'). # ¾ - gsub(/×/u,'×'). # × - gsub(/÷/u,'÷'). # ÷ - gsub(/¿/u,'¿'). # ¿ - gsub(/À/u,'À'). # À - gsub(/Á/u,'Á'). # Á - gsub(/Â/u,'Â'). #  - gsub(/Ã/u,'Ã'). # à - gsub(/Ä/u,'Ä'). # Ä - gsub(/Å/u,'Å'). # Å - gsub(/Æ/u,'Æ'). # Æ - gsub(/Ç/u,'Ç'). # Ç - gsub(/È/u,'È'). # È - gsub(/É/u,'É'). # É - gsub(/Ê/u,'Ê'). # Ê - gsub(/Ë/u,'Ë'). # Ë - gsub(/Ì/u,'Ì'). # Ì - gsub(/Í/u,'Í'). # Í - gsub(/Î/u,'Î'). # Î - gsub(/Ï/u,'Ï'). # Ï - gsub(/Ð/u,'Ð'). # Ð - gsub(/Ñ/u,'Ñ'). # Ñ - gsub(/Ò/u,'Ò'). # Ò - gsub(/Ó/u,'Ó'). # Ó - gsub(/Ô/u,'Ô'). # Ô - gsub(/Õ/u,'Õ'). # Õ - gsub(/Ö/u,'Ö'). # Ö - gsub(/Ø/u,'Ø'). # Ø - gsub(/Ù/u,'Ù'). # Ù - gsub(/Ú/u,'Ú'). # Ú - gsub(/Û/u,'Û'). # Û - gsub(/Ü/u,'Ü'). # Ü - gsub(/Ý/u,'Ý'). # Ý - gsub(/Þ/u,'Þ'). # Þ - gsub(/ß/u,'ß'). # ß - gsub(/à/u,'à'). # à - gsub(/á/u,'á'). # á - gsub(/â/u,'â'). # â - gsub(/ã/u,'ã'). # ã - gsub(/ä/u,'ä'). # ä - gsub(/å/u,'å'). # å - gsub(/æ/u,'æ'). # æ - gsub(/ç/u,'ç'). # ç - gsub(/è/u,'è'). # è - gsub(/é/u,'´'). # é - gsub(/ê/u,'ˆ'). # ê - gsub(/ë/u,'ë'). # ë - gsub(/ì/u,'ì'). # ì - gsub(/í/u,'´'). # í - gsub(/î/u,'î'). # î - gsub(/ï/u,'ï'). # ï - gsub(/ð/u,'ð'). # ð - gsub(/ñ/u,'ñ'). # ñ - gsub(/ò/u,'ò'). # ò - gsub(/ó/u,'ó'). # ó - gsub(/ô/u,'ô'). # ô - gsub(/õ/u,'õ'). # õ - gsub(/ö/u,'ö'). # ö - gsub(/ø/u,'ø'). # ø - gsub(/ù/u,'ù'). # ú - gsub(/ú/u,'ú'). # û - gsub(/û/u,'û'). # ü - gsub(/ü/u,'ü'). # ý - gsub(/þ/u,'þ'). # þ - gsub(/ÿ/u,'ÿ'). # ÿ - gsub(/‘/u,'&#lsquo;'). # ‘ # ‘ - gsub(/’/u,'&#rsquo;'). # ’ # ’ - gsub(/“/u,'“'). # “ # “ - gsub(/”/u,'”'). # ” # ” - gsub(/–/u,'–'). # – # – - gsub(/—/u,'—'). # — # — - gsub(/∝/u,'∝'). # ∝ # ∝ - gsub(/∞/u,'∞'). # ∞ # ∞ - gsub(/™/u,'™'). # ™ # ™ - gsub(/✠/u,'✠'). # ✠ - #gsub(/✠/u '†'). # † # † incorrect replacement † - gsub(/ /u,' '). # space identify - gsub(/ /u,' ') # space identify - end - end - self - end - def tidywords(wordlist) - wordlist_new=[] - wordlist.each do |x| - #imperfect solution will not catch all possible cases - x=x.gsub(/&/,'&') unless x =~/&\S+;/ - x=x.gsub(/&([A-Z])/,'&\1') - wordlist_new << x - end - wordlist_new - end - def markup(dob='') - wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 - dob.obj=tidywords(wordlist).join(' ').strip - unless dob.is==:table - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/u,'
    '). - gsub(/#{Mx[:br_paragraph]}/u,'
    '). - gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') - end - dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/(^|#{Mx[:gl_c]}|\s+)<\s+/,'\1< ').gsub(/\s+>(\s+|$)/,' >\1'). - #gsub(/#{Mx[:fa_emphasis_o]}(.+?)#{Mx[:fa_emphasis_c]}/,'\1'). #reinstate - gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/m,'\1'). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/m,'\1'). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). - gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). - gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). - gsub(/<:pb>\s*/,''). #Fix - gsub(/<+[-~]#>+/,'') - if dob.is !=:code - #embeds a red-bullet image --> - dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1') - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table - dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*/,''). - gsub(/#{Mx[:br_page_new]}\s*/,''). - gsub(/#{Mx[:br_page_line]}\s*/,''). - gsub(/#{Mx[:pa_non_object_no_heading]}|#{Mx[:pa_non_object_dummy_heading]}/,''). - gsub(/<[-~]#>/,''). - gsub(/href="#{Xx[:segment]}/m,'href="'). - gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/, - '\1'). - gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/, - '\1'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/, - '\1'). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{[\\1] \\4}). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{\\1}). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}image/, - %{[\\1] \\4}). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}image/, - %{\\1}). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - '\1'). #watch, compare html_tune - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1') #escaped urls not linked, deal with later - else - dob.obj=dob.obj.gsub(//m,'>') - end - if dob.of==:block - dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') - end - dob.obj=dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Dx[:url_o]}/,"#{Dx[:url_o_xml]}"). - gsub(/#{Dx[:url_c]}/,"#{Dx[:url_c_xml]}"). - gsub(/ |#{Mx[:nbsp]}/m,' ') - dob - end - def markup_light(dob='') - dob.obj=dob.obj.gsub(/\/\{(.+?)\}\//,'\1'). - gsub(/[*!]\{(.+?)\}[*!]/,'\1'). - gsub(/_\{(.+?)\}_/,'\1'). - gsub(/-\{(.+?)\}-/,'\1'). - gsub(//,'
    '). - gsub(/<:pb>\s*/,''). - gsub(/<[-~]#>/,''). - gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort - gsub(/&([^;]{1,5})/,'&\1'). #sort, rough estimate, revisit #WATCH found in node not sax - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/, - "#{@md.file.output_path.xml.rel_image}\/\\1"). - gsub(/ |#{Mx[:nbsp]}/,' ') - wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 - dob.obj=tidywords(wordlist).join(' ').strip - dob - end - def markup_fictionbook(dob='') - dob.obj.gsub(/~\{([\d*+]+).+?\}~/,'[\1]'). - gsub(/\/\{(.+?)\}\//,'\1'). - gsub(/[*!]\{(.+?)\}[*!]/,'\1'). - gsub(/_\{(.+?)\}_/,'\1'). - gsub(/-\{(.+?)\}-/,'\1'). - gsub(//,'
    '). - gsub(/<:pb>\s*/,''). - gsub(/<[-~]#>/,''). - #temporary --> - gsub(/<:\S+?>/,''). - #<-- temporary - gsub(/<[-~]#>/,''). - gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort - gsub(/&([^;]{1,5})/,'&\1') #sort, rough estimate, revisit #WATCH found in node not sax - gsub(/(#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/, - "#{@md.file.output_path.xml.rel_image}\/\\1"). - gsub(/ |#{Mx[:nbsp]}/,' ') - wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 - dob.obj=tidywords(wordlist).join(' ').strip - dob - end - def markup_group(dob='') - dob.obj=dob.obj.gsub(//,'>'). - gsub(/<:?br(?:\s+\/)?>/,'
    '). - gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). - gsub(/<(\/link)>/,'<\1>'). - gsub(/<(\/?en)>/,'<\1>') - dob - end - def markup_block(dob='') - dob.obj=dob.obj.gsub(//,'>'). - gsub(/<:?br(?:\s+\/)?>/,'
    '). - gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). - gsub(/<(\/link)>/,'<\1>'). - gsub(/<(\/?en)>/,'<\1>') - dob - end - def xml_sem_block_paired(matched) # colon depth: many, recurs - matched=matched.gsub(/\b(au):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(vol):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(pub):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(ref):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(desc):\{(.+?)\}:\1\b/m,%{\\2}). - gsub(/\b(conv):\{(.+?)\}:\1\b/m,%{\\2}). - gsub(/\b(ct):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(cty):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(org):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(dt):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(n):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m,'\2') - end - def xml_semantic_tags(dob) - if @md.sem_tag - dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } - dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } - dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } - dob.obj=dob.obj.gsub(/:\{(.+?)\}:au\b/m, %{\\1}). - gsub(/:\{(.+?)\}:n\b/m, %{\\1}). - gsub(/:\{(.+?)\}:ti\b/m, %{\\1}). - gsub(/:\{(.+?)\}:ref\b/m, %{\\1}). - gsub(/:\{(.+?)\}:desc\b/m, %{\\1}). - gsub(/:\{(.+?)\}:cty\b/m, %{\\1}). - gsub(/:\{(.+?)\}:org\b/m, %{\\1}). - gsub(/:\{(.+?)\}:([a-z]+(?:[_:.][a-z]+)*)/m,'\1'). - gsub(/;\{([^}]+(?![;]))\};ti\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};qt\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ref\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ed\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};v\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};desc\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};def\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};trans\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};y\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ab\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};pg\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};fn?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};mn?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ln?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};in\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};uni\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};fac\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};inst\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};dept\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};org\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};com?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};cty\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};([a-z]+(?:[_:.][a-z]+)*)/m,'\1') - end - dob - end - end -end -module SiSU_XML_Tags #Format - require_relative 'param' # param.rb - include SiSU_Param - include SiSU_Viz - class RDF - def initialize(md='',seg_name=[],tracker=0) - @full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords='' - @md=md - @rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n} - if defined? @md.title.full \ - and @md.title.full # DublinCore 1 - title - @rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n} - @full_title=%{ \n} - end - if defined? @md.creator.author \ - and @md.creator.author=~/\S+/ # DublinCore 2 - creator/author (author) - @rdf_author=%{ dc.author="#{@md.creator.author}"\n} - content=meta_content_clean(@md.creator.author) - @author=%{ \n} - end - if defined? @md.publisher \ - and @md.publisher # DublinCore 5 - publisher (current copy published by) - @rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n} - content=meta_content_clean(@md.publisher) - @publisher=%{ \n} - end - if defined? @md.creator.contributor \ - and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor - @rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n} - content=meta_content_clean(@md.creator.contributor) - @contributor=%{ \n} - end - if defined? @md.date.published \ - and @md.date.published=~/\S+/ # DublinCore 7 - date year-mm-dd - @rdf_date=%{ dc.date="#{@md.date.published}"\n} - @date=%{ \n} # fix @md.date_scheme - end - if defined? @md.date.created \ - and @md.date.created=~/\S+/ # DublinCore 7 - date.created year-mm-dd - @rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n} - @date_created=%{ \n} - end - if defined? @md.date.issued \ - and @md.date.issued=~/\S+/ # DublinCore 7 - date.issued year-mm-dd - @rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n} - @date_issued=%{ \n} - end - if defined? @md.date.available \ - and @md.date.available=~/\S+/ # DublinCore 7 - date.available year-mm-dd - @rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n} - @date_available=%{ \n} - end - if defined? @md.date.valid \ - and @md.date.valid=~/\S+/ # DublinCore 7 - date.valid year-mm-dd - @rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n} - @date_valid=%{ \n} - end - if defined? @md.date.modified \ - and @md.date.modified=~/\S+/ # DublinCore 7 - date.modified year-mm-dd - @rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n} - @date_modified=%{ \n} - end - if defined? @md.rights.all \ - and @md.rights.all # DublinCore 15 - rights - @rdf_rights=%{ dc.rights="#{@md.rights.all}"\n} - content=meta_content_clean(@md.rights.all) - @rights=%{ \n} - end - if defined? @md.classify.subject \ - and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???) - @rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n} - content=meta_content_clean(@md.classify.subject) - @subject=%{ \n} - end - if defined? @md.notes.description \ - and @md.notes.description=~/\S+/ # DublinCore 4 - description - @rdf_description=%{ dc.description="#{@md.notes.description}"\n} - content=meta_content_clean(@md.notes.description) - @description=%{ \n} - end - if defined? @md.notes.coverage \ - and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage - @rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n} - content=meta_content_clean(@md.notes.coverage) - @coverage=%{ \n} - end - if defined? @md.notes.relation \ - and @md.notes.relation=~/\S+/ # DublinCore 13 - relation - @rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n} - content=meta_content_clean(@md.notes.relation) - @relation=%{ \n} - end - if defined? @md.notes.type \ - and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc) - @rdf_type=%{ dc.type="#{@md.notes.type}"\n} - content=meta_content_clean(@md.notes.type) - @type=%{ \n} - end - if defined? @md.notes.format \ - and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type) - @rdf_format=%{ dc.format="#{@md.notes.format}"\n} - content=meta_content_clean(@md.notes.format) - @format=%{ \n} - end - #if defined? @md.identifier.sisupod \ - #and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free) - # @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n} - # content=meta_content_clean(@md.identifier.sisupod) - # @identifier=%{ \n} - #end - if defined? @md.original.source \ - and @md.original.source=~/\S+/ # DublinCore 11 - source (document source) - @rdf_source=%{ dc.source="#{@md.original.source}"\n} - content=meta_content_clean(@md.original.source) - @source=%{ \n} - end - if defined? @md.title.language \ - and @md.title.language=~/\S+/ # DublinCore 12 - language (English) - @rdf_language=%{ dc.language="#{@md.title.language}"\n} - @language=%{ \n} - end - if defined? @md.original.language \ - and @md.original.language=~/\S+/ - @rdf_language_original=%{ dc.language="#{@md.original.language}"\n} - @language_original=%{ \n} - end - content=meta_content_clean(@md.keywords) - @keywords=%{ \n} if @md.keywords - @vz=SiSU_Viz::Defaults.new - end - def meta_content_clean(content='') - content=if not content.nil? - content=content.tr('"',"'") - content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content) - else content - end - end - def rdfseg #segHead - rdftoc - end - def comment_xml(extra='') - generator="Generated by: #{@md.sisu_version[:project]} #{@md.sisu_version[:version]} of #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" if @md.sisu_version[:version] - lastdone="Last Generated on: #{Time.now}" - rubyv="Ruby version: #{@md.ruby_version}" - sc=if @md.sc_info - "Source file: #{@md.sc_filename} version: #{@md.sc_number} of: #{@md.sc_date}" - else '' - end - if extra.empty? -< -WOK - else -< -WOK - end - end - def comment_xml_sax - desc='SiSU XML, SAX type representation' - comment_xml(desc) - end - def comment_xml_node - desc='SiSU XML, Node type representation' - comment_xml(desc) - end - def comment_xml_dom - desc='SiSU XML, DOM type representation' - comment_xml(desc) - end - def metatag_html #values strung together, because some empty, and resulting output (line breaks) is much better -<. - - 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: create sisupod filetype and copy it to output directory! - -=end -module SiSU_Doc - require_relative 'shared_sisupod_source' # shared_sisupod_source.rb - include SiSU_Source - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - class Source < SiSU_Source::SiSUpodSource - require_relative 'response' # response.rb - def initialize(opt,build=nil,place=nil) - super(opt,build,place) - @zipfile=@opt.fno.gsub(/(?:\~\S{2,3})?(\.ss[tm])$/,'\1') - unless @opt.act[:quiet][:set]==:on - pthinfo="#{@file.output_path.sisupod.dir}/#{@zipfile}.txz" - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble source for sisu document',"#{@opt.fns} -> file://#{pthinfo}").cyan_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble source for sisu document',pthinfo).cyan_title_hi - end - end - def sisupod_tar_xz - begin - FileUtils::mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir) - tree=((@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - && SiSU_Env::SystemCall.new.program_found?('tree')) \ - ? 'tree sisupod' - : '' - if FileTest.directory?(@path_pod[:fnb]) - Dir.chdir(@path_pod[:fnb]) - system(%{ - #{tree} - tar -cJf #{@zipfile}.txz sisupod - #echo "#{@file.place_file.sisupod.dir}" - }) - FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir) - Dir.chdir(@env.path.pwd) - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab - end - else - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab - end - end - rescue - ensure - end - end - end -end -__END__ -question?: should you permit the packing of multiple documents in single .xz ? - - open @opt.fns, parse file - extract from file content: - images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image - - remove previously existing contents of _/sisu/sisupod & - make directory structure: - -v3 --> - _sisu - sisupod - doc - manifest.txt - en/content.sst [file content] - fr/content.sst - _sisu - conf - image (ln -s ../../image) - audio (ln -s ../../audio) - video (ln -s ../../video) - image [all images for specific document gathered here] - audio - video - -v2 --> - _sisu - sisupod - content.sst [file content] - filename.sst [link to content.sst] - _sisu/ - image/ [all images for specific document gathered here] - -sisu - _sisu - sisurc.yml - convert/ - standard_terms/ - image - processing - ao/ - tex/ - texinfo/ - tune/ - sisupod - -special case - -composite file (master), e.g. -SiSU.ssm diff --git a/lib/sisu/v5/sitemaps.rb b/lib/sisu/v5/sitemaps.rb index 8e4d1410..6e81369a 100644 --- a/lib/sisu/v5/sitemaps.rb +++ b/lib/sisu/v5/sitemaps.rb @@ -64,7 +64,7 @@ module SiSU_Sitemaps include SiSU_Param require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge class Source def initialize(opt) diff --git a/lib/sisu/v5/src_kdissert_share.rb b/lib/sisu/v5/src_kdissert_share.rb new file mode 100644 index 00000000..a71aca99 --- /dev/null +++ b/lib/sisu/v5/src_kdissert_share.rb @@ -0,0 +1,90 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: share sisu source markup file, copy it to output directory! + +=end +module SiSU_KdiSource + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + class Source + require 'fileutils' + include FileUtils + def initialize(opt) + @opt=opt + @env=SiSU_Env::InfoEnv.new(@opt.fns) + @output_path="#{@env.path.output}/#{@opt.fnb}" + end + def read + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share Kdissert Source Document!',@opt.fnb).green_hi_blue unless @opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Copy kdissert file to output directory","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on + FileUtils::mkdir_p(@env.path.output) unless FileTest.directory?(@env.path.output) + FileUtils::mkdir_p(@output_path) unless FileTest.directory?(@output_path) + if FileTest.directory?(@output_path) + if @opt.fns =~/\.kdi\._sst$/ \ + and FileTest.file?(@opt.fnb) + FileUtils::cp(@opt.fnb,@output_path) + end + else + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Output directory does not exist","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on + exit + end + end + end +end +__END__ diff --git a/lib/sisu/v5/src_share.rb b/lib/sisu/v5/src_share.rb new file mode 100644 index 00000000..1aba0d95 --- /dev/null +++ b/lib/sisu/v5/src_share.rb @@ -0,0 +1,102 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: share sisu source markup file, copy it to output directory! + +=end +module SiSU_Markup + require_relative 'src_shared' # src_shared.rb + include SiSU_Source + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + class Source < SiSU_Source::SiSUpodSource + def initialize(opt,build=nil,place=nil) + super(opt,build,place) + @opt=opt + end + def read + unless @opt.act[:quiet][:set]==:on + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share document markup text source',@opt.fns).cyan_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share document markup text source',@opt.fns).cyan_title_hi + end + if FileTest.directory?(@path_pod[:fnb]) + FileUtils::mkdir_p(@file.output_path.src.dir) unless FileTest.directory?(@file.output_path.src.dir) + v=(@opt.act[:maintenance][:set]==:on) \ + ? 'v' : '' + system(%{ + rsync -a#{v} #{@path_pod[:fnb]} #{@file.output_path.sisupod.dir} + chbk=`pwd` + cd #{@file.output_path.sisupod.dir} + for I in `find -type d` ; do chmod 755 $I ; done + for I in `find -type f` ; do chmod 644 $I ; done + cd ${chbk} + }) + else + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new('',"#{@opt.fno} not available").blue_tab + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/src_shared.rb b/lib/sisu/v5/src_shared.rb new file mode 100644 index 00000000..65c4288e --- /dev/null +++ b/lib/sisu/v5/src_shared.rb @@ -0,0 +1,312 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: create sisupod filetype and copy it to output directory! + +=end +module SiSU_Source + include SiSU_Env + class SiSUpodSource + require_relative 'sysenv' # sysenv.rb + require_relative 'particulars' # particulars.rb + def initialize(opt,build=nil,place=nil) + @opt=opt + @date=SiSU_Env::InfoDate.new.dt + @env=SiSU_Env::InfoEnv.new(opt.fns) + @ver=SiSU_Env::InfoVersion.instance.get_version + @v=(@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? 'v' : '' + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + @file=@particulars.file + @local_path="#{@file.output_path.sisupod.dir}" + processing_sisupod=@env.processing_path.processing_sisupod(opt) + processing_sisupod.make + path_pod=processing_sisupod.paths[:sisupod] + path_pod_fnb=processing_sisupod.paths[:fnb] + FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod) + @path_pod={ + fnb: path_pod_fnb, + pod: path_pod, + doc: path_pod + '/' + Gt[:doc] + '/' + opt.lng, + po: path_pod + '/' + Gt[:po] + '/' + opt.lng, + pot: path_pod + '/' + Gt[:pot], + conf: path_pod + '/' + Gt[:conf], + image: path_pod + '/' + Gt[:image], + audio: path_pod + '/' + Gt[:audio], + video: path_pod + '/' + Gt[:video], + } + end + def read + unless @opt.act[:quiet][:set]==:on + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble SiSU source',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_hi_blue + : '' + end + unless @opt.fns.empty? + directories + pod_source_build #this needs to be built in case of multi-lingual for all of them, before single pass tar + end + end + def directories + SiSU_Env::InfoEnv.new.sisupod_v4(@opt) + end + def images_extract(f,images) # consider using param info + rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m + if f !~/^%+\s/ \ + and f =~rgx_image + images << f.scan(rgx_image).uniq + end + images.flatten + end + def pod_source_build + @pwd=Dir.pwd + @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/ + @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ + @rgx_doc_import=/^<<\s*(\S+?\.ss[ti])/ + file_array=IO.readlines(@opt.fno,'') + images,doc_import=[],[] + doc_import_dir=@opt.sub_location + file_array.each do |f| #% work area + if f !~/^%+\s/ + f=f.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image) + if f !~/^%+\s/ \ + and f =~@rgx_image + images=images_extract(f,images) + end + if @opt.fno =~/\.ssm$/ + doc_import << f.scan(@rgx_doc_import) if f =~@rgx_doc_import + end + end + end + if doc_import.length > 0 + doc_import=doc_import.uniq.flatten + doc_import.each do |fn| + file_array=IO.readlines(fn,'') + file_array.each do |f| #% work area + if f !~/^%+\s/ \ + and f =~@rgx_image + images=images_extract(f,images) + end + end + end + end + gi=SiSU_Env::GetInit.new + unless FileTest.file?("#{@path_pod[:conf]}/#{gi.makefile_name}") + if gi.makefile \ + && FileTest.file?(gi.makefile) + FileUtils::mkdir_p(@path_pod[:conf]) unless FileTest.directory?(@path_pod[:conf]) + FileUtils::cp(gi.makefile,"#{@path_pod[:conf]}/#{gi.makefile_name}") + end + #get images from makefile, consider placing in param + end + if images \ + and images.length > 1 + images=images.flatten.uniq + images.delete_if {|x| x =~/https?:\/\// } + #images=images.sort + FileUtils::mkdir_p(@path_pod[:image]) + #unattractive hard coding ... ! + image_path='_sisu/image' + images_pwd="#{@opt.base_path}/#{image_path}" + ##sequence copies base images, defaults used in all html outputs + #image_source_base='/usr/share/sisu/image' + #dir_pwd=Dir.pwd + #Dir.chdir(image_source_base) + #base_images=Dir.glob('*') + #base_images.each do |i| + # FileUtils::cp_r(i,"#{images_path_pod}/#{i}") + #end + #Dir.chdir(dir_pwd) + if FileTest.directory?(images_pwd) + images=images.uniq + images.each do |i| + if FileTest.file?("#{images_pwd}/#{i}") + FileUtils::cp("#{images_pwd}/#{i}","#{@path_pod[:image]}/#{i}") + else STDERR.puts %{\t*WARN* did not find image - "#{images_pwd}/#{i}" [#{__FILE__}:#{__LINE__}]} + end + end + else STDERR.puts %{\t*WARN* did not find - #{images_pwd} #{@path_pod[:image]} [#{__FILE__}:#{__LINE__}]} + end + end + if doc_import.length > 0 \ + and @opt.fno =~/\.ssm$/ + doc_import.each do |f| + if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}") + FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f}","#{@path_pod[:doc]}/#{f}") + else STDERR.puts %{\t*WARN* did not find image - "#{@opt.base_path}#{doc_import_dir}/#{f}" [#{__FILE__}:#{__LINE__}]} + end + end + end + x=@env.document_language_versions_found #check multiple document language versions (param not used) + if x[:f] \ + and x[:f].length > 0 #store multiple document language versions, sisupod + x[:f].each do |f| + FileUtils::mkdir_p(@path_pod[:doc]) unless FileTest.directory?(@path_pod[:doc]) + if f[:f] =~/\~(\S{2,3})\.ss[tm]$/ + lng_f=$1 + if @opt.lng == lng_f + if @opt.fno =~/\.ssm$/ + if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") + FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + else + if FileTest.file?("#{@opt.base_path}/#{f[:f]}") + cpy= :no + cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ + or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ + :yes + elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ + and @opt.f_pth[:lng_is] == 'en' + :yes + else :no + end + if cpy == :yes + FileUtils::cp("#{@opt.base_path}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + end + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + end + end + else + if @opt.fno =~/\.ssm$/ + if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") + FileUtils::cp_r("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + else + if FileTest.file?("#{@opt.base_path}/#{f[:f]}") + cpy= :no + cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ + or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ + :yes + elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ + and @opt.f_pth[:lng_is] == 'en' + :yes + else :no + end + if cpy == :yes + FileUtils::cp("#{@opt.base_path}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + end + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + end + end + end + end #NB not all possibilies met, revisit, also in case of composite file may wish to add README + end + end +end +__END__ +question?: should you permit the packing of multiple documents in single .xz ? + + open @opt.fns, parse file + extract from file content: + images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image + + remove previously existing contents of _/sisu/sisupod & + make directory structure: + +v3 --> + _sisu + sisupod + doc + manifest.txt + en/content.sst [file content] + fr/content.sst + _sisu + conf + image (ln -s ../../image) + audio (ln -s ../../audio) + video (ln -s ../../video) + image [all images for specific document gathered here] + audio + video + +v2 --> + _sisu + sisupod + content.sst [file content] + filename.sst [link to content.sst] + _sisu/ + image/ [all images for specific document gathered here] + +sisu + _sisu + sisurc.yml + convert/ + standard_terms/ + image + processing + ao/ + tex/ + texinfo/ + tune/ + sisupod + +special case + +composite file (master), e.g. +SiSU.ssm diff --git a/lib/sisu/v5/src_sisupod_make.rb b/lib/sisu/v5/src_sisupod_make.rb new file mode 100644 index 00000000..d244ece4 --- /dev/null +++ b/lib/sisu/v5/src_sisupod_make.rb @@ -0,0 +1,167 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: create sisupod filetype and copy it to output directory! + +=end +module SiSU_Doc + require_relative 'src_shared' # scr_shared.rb + include SiSU_Source + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + class Source < SiSU_Source::SiSUpodSource + require_relative 'response' # response.rb + def initialize(opt,build=nil,place=nil) + super(opt,build,place) + @zipfile=@opt.fno.gsub(/(?:\~\S{2,3})?(\.ss[tm])$/,'\1') + unless @opt.act[:quiet][:set]==:on + pthinfo="#{@file.output_path.sisupod.dir}/#{@zipfile}.txz" + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble source for sisu document',"#{@opt.fns} -> file://#{pthinfo}").cyan_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble source for sisu document',pthinfo).cyan_title_hi + end + end + def sisupod_tar_xz + begin + FileUtils::mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir) + tree=((@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + && SiSU_Env::SystemCall.new.program_found?('tree')) \ + ? 'tree sisupod' + : '' + if FileTest.directory?(@path_pod[:fnb]) + Dir.chdir(@path_pod[:fnb]) + system(%{ + #{tree} + tar -cJf #{@zipfile}.txz sisupod + #echo "#{@file.place_file.sisupod.dir}" + }) + FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir) + Dir.chdir(@env.path.pwd) + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab + end + else + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab + end + end + rescue + ensure + end + end + end +end +__END__ +question?: should you permit the packing of multiple documents in single .xz ? + + open @opt.fns, parse file + extract from file content: + images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image + + remove previously existing contents of _/sisu/sisupod & + make directory structure: + +v3 --> + _sisu + sisupod + doc + manifest.txt + en/content.sst [file content] + fr/content.sst + _sisu + conf + image (ln -s ../../image) + audio (ln -s ../../audio) + video (ln -s ../../video) + image [all images for specific document gathered here] + audio + video + +v2 --> + _sisu + sisupod + content.sst [file content] + filename.sst [link to content.sst] + _sisu/ + image/ [all images for specific document gathered here] + +sisu + _sisu + sisurc.yml + convert/ + standard_terms/ + image + processing + ao/ + tex/ + texinfo/ + tune/ + sisupod + +special case + +composite file (master), e.g. +SiSU.ssm diff --git a/lib/sisu/v5/sst_to_s_xml_sax.rb b/lib/sisu/v5/sst_to_s_xml_sax.rb index 09fecc9e..5f18496a 100644 --- a/lib/sisu/v5/sst_to_s_xml_sax.rb +++ b/lib/sisu/v5/sst_to_s_xml_sax.rb @@ -69,7 +69,7 @@ module SiSU_SimpleXML_ModelSax require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'ao_doc_str' # ao_doc_str.rb - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'shared_sem' # shared_sem.rb require_relative 'xml_format' # xml_format.rb @@ -138,7 +138,7 @@ module SiSU_SimpleXML_ModelSax end end class Scroll - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb require_relative 'css' # css.rb include SiSU_TextUtils @@xml={ body: [], open: [], close: [], head: [] } diff --git a/lib/sisu/v5/txt_plain.rb b/lib/sisu/v5/txt_plain.rb new file mode 100644 index 00000000..e6a8f46f --- /dev/null +++ b/lib/sisu/v5/txt_plain.rb @@ -0,0 +1,576 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: plaintext text generation, stripped plaintext output (unix, + linefeed) + +=end +module SiSU_Plaintext + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'txt_plaint_format' # plaintext_format.rb + include SiSU_Plaintext_Format + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + include SiSU_Param + include SiSU_Viz + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" + end + end + def read + begin + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + unless @opt.act[:quiet][:set]==:on + tool=(@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? "#{env.program.text_editor} #{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Plaintext',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Plaintext',tool).green_title_hi + if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow + end + end + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Txt_Plain::Source::Scroll.new(md,ao_array,wrap_width).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within plaintext, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ + fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added + fix.each do |x| + unless x.empty?; @n << x + end + end + else @n << n + end + end + notes=@n.flatten + notes.each do |e| + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) + : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) + wrap=util.line_wrap + wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m + wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB +\\1[\\2]: \\3 + GSUB + ) + else + wrap.gsub(/^(.+)\Z/m, <<-GSUB +\\1 + GSUB + ) + end + @@endnotes[:para] << "-#{wrap}" + @@endnotes[:end] << '' << wrap + end + @@endnotes + end + def plaintext_metadata + array=SiSU_Metadata::Summary.new(@md).plaintext.metadata + array.each do |meta| + tag,inf=meta.scan(/^.+?:\s|.+/) + if tag and inf + util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) + txt=util.line_wrap + @plaintext[:metadata] <<< @wrap_width + @plaintext[:body] << case lv + when 1; wrapped.upcase << break_line << decorate.heading_underscore.l1*times + p_num << break_line*2 + when 2; wrapped.upcase << break_line << decorate.heading_underscore.l2*times + p_num << break_line*2 + when 3; wrapped.upcase << break_line << decorate.heading_underscore.l3*times + p_num << break_line*2 + when 4; wrapped.upcase << break_line << decorate.heading_underscore.l4*times + p_num << break_line*2 + when 5; wrapped.upcase << break_line << decorate.heading_underscore.l5*times + p_num << break_line*2 + when 6; wrapped.upcase << break_line << decorate.heading_underscore.l6*times + p_num << break_line*2 + end + else + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP + end + if @@endnotes[:para] \ + and not @@endnotes_ + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} + elsif @@endnotes[:para] \ + and @@endnotes_ + end + @@endnotes[:para]=[] + end + def markup(data) # Used for major markup instructions + SiSU_Env::InfoEnv.new(@md.fns) + @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @plaintext_contents_close[x]='' } + plaintext_tail #($1,$2) + plaintext_metadata + table_message='[table omitted, see other document formats]' + data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix + gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + "#{decorate.bold.open}\\1#{decorate.bold.close}"). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + "#{decorate.italics.open}\\1#{decorate.italics.close}"). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, + "#{decorate.insert.open}\\1#{decorate.insert.close}"). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, + "#{decorate.cite.open}\\1#{decorate.cite.close}"). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, + "#{decorate.strike.open}\\1#{decorate.strike.close}"). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + "#{decorate.monospace.open}\\1#{decorate.monospace.close}") + unless dob.is==:code + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). + gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). + gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). + gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). + gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). + gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). + gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') + end + dob.obj=if dob.of==:block # watch + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) + end + if dob.is==:code + dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< + gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/(.+?)<\/a>/m,'\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links + gsub(/ |#{Mx[:nbsp]}/,' '). # decide on + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + p_num='' + if @env.plaintext_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Fixnum) + p_num=SiSU_Plaintext_Format::ParagraphNumber.new(dob.ocn).display + end + end + if dob.is==:heading \ + or dob.is==:para + plaintext_structure(dob,p_num) + elsif dob.is==:group \ + or dob.is==:block \ + or dob.is==:verse \ + or dob.is==:code \ + or dob.is==:table + @plaintext[:body] << dob.obj + p_num << break_line + elsif dob.is==:break + sp=' ' + ln='-' + @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] \ + or dob.obj==Mx[:br_page_line] + "#{break_line}#{ln*40}#{break_line*2}" + elsif dob.obj ==Mx[:br_obj] + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix + end + dob='' if (dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') + end + end + end + @plaintext + end + def publish(plaintext) + divider='=' + content=[] + content << plaintext[:open] + content << plaintext[:head] + content << plaintext[:body] + content << @@endnotes[:end] if @@endnotes_ + content << "#{break_line}#{divider*@wrap_width}#{break_line}" + content << plaintext[:metadata] + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? + content << plaintext[:tail] + Output.new(content,@md).plaintext + @@endnotes={ para: [], end: [] } + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line + end + end + end + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_plaintext.close + end + end + end +end +__END__ + bold_o: '*', bold_c: '*', + #bold_o: '!', bold_c: '!', + #emphasis_o: '*', emphasis_c: '*', + italics_o: '/', italics_c: '/', + underscore_o: '_', underscore_c: '_', + cite_o: '"', cite_c: '"', + insert_o: '+', insert_c: '+', + strike_o: '-', strike_c: '-', + superscript_o: '^', superscript_c: '^', + subscript_o: '[', subscript_c: ']', + hilite_o: '*', hilite_c: '*', + monospace_o: '', monospace_c: '', + po_bold_o: '!{', po_bold_c: '}!', + po_italics_o: '/{', po_italics_c: '}/', + po_underscore_o: '_{', po_underscore_c: '}_', + po_cite_o: '"{', po_cite_c: '}"', + po_insert_o: '+{', po_insert_c: '}+', + po_strike_o: '-{', po_strike_c: '}-', + po_superscript_o: '^{', po_superscript_c: '}^', + po_subscript_o: ',{', po_subscript_c: '},', + po_hilite_o: '*{', po_hilite_c: '}*', + po_monospace_o: '#{', po_monospace_c: '}#', diff --git a/lib/sisu/v5/txt_shared.rb b/lib/sisu/v5/txt_shared.rb new file mode 100644 index 00000000..31a976d2 --- /dev/null +++ b/lib/sisu/v5/txt_shared.rb @@ -0,0 +1,242 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: modules shared by flatfile output generators + +=end +module SiSU_TextUtils + class Wrap + def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil) + @para,@n_char_max,@n_indent=para,n_char_max,n_indent + @n_char_max_extend = n_char_max + @n_hang=n_hang ? n_hang : @n_indent + end + def break_line + "\n" + end + def line_wrap + space=' ' + spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang + line=0 + out=[] + out[line]='' + @para=@para.gsub(/
    /,' \\ '). + gsub(/#{Mx[:br_nl]}/,"\n\n") + words=@para.scan(/\n\n|\s+\\\s+|
    |\S+/m) + while words != '' + word=words.shift + if not word + out[line] unless out[line].empty? #check + break + elsif word =~/
    / + word=nil + out[line]=out[line].gsub(/
    /,'') + line=line + elsif word =~/\n\n/ + word="\n" + @n_char_max_extend = @n_char_max + line += 1 + elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ + and out[line] =~/\S+/ + @n_char_max_extend = @n_char_max + out[line].squeeze!(' ') + line += 1 + end + if word + out[line]=if out[line] \ + and out[line] !~/\S+$/m + "#{out[line]}#{word}" + elsif out[line] \ + and out[line] =~/\S+/ + "#{out[line]} #{word}" + else "#{word.strip}" + end + end + @oldword=word if word =~/\S+/ + end + spaces_hang + out.join(spaces_indent) + end + def line_wrap_indent1 + @n_indent,@n_hang=2,2 + line_wrap + end + def line_wrap_endnote + @n_indent,@n_hang=4,2 + line_wrap + end + def array_wrap + if @para.is_a?(Array) + @arr=[] + @para.each do |line| + @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap + end + end + @arr + end + def no_wrap + @para + end + def no_wrap_no_breaks + @para.gsub(/\n/m,' ').gsub(/\s\s+/,' ') + end + end + class HeaderScan + def initialize(md,para) + @md,@p=md,para + end + def extract(tag,tag_content,type,attrib) + if dc_tag \ + and dc_content + [dc_tag,dc_content,{dc_tag=>dc_content}] + else nil + end + end + def header(tag,tag_content,type='',attrib='') #this will break stuff and must be tested thoroughly 20060825 + @tag,@tag_content,@type,@attrib=tag,tag_content,type,attrib + def label #element + @tag + end + def type + @type + end + def text + @tag_content + end + def info #element text + @tag_content + end + def attribute + @attrib + end + def element + @tag + end + def attrib + @attrib + end + def el + @tag + end + self + end + def start_is_match + case @p + when /^#{Mx[:meta_o]}(title)#{Mx[:meta_c]}\s*(.+?)$/; header($1,@md.title.full,'meta','dc') #dc 1 + when /^#{Mx[:meta_o]}(creator|author)#{Mx[:meta_c]}\s*(.+?)$/; header('creator',$2,'meta','dc') #dc 2 + when /^#{Mx[:meta_o]}(subject)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 3 + when /^#{Mx[:meta_o]}(description)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 4 + when /^#{Mx[:meta_o]}(publisher)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 5 + when /^#{Mx[:meta_o]}(contributor)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 6 + when /^#{Mx[:meta_o]}(date)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 7 + when /^#{Mx[:meta_o]}(date\.created)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.issued)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.available)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.valid)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.modified)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(type)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 8 + when /^#{Mx[:meta_o]}(format)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 9 + when /^#{Mx[:meta_o]}(identifier)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 10 + when /^#{Mx[:meta_o]}(source)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 11 + when /^#{Mx[:meta_o]}(language)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 12 + when /^#{Mx[:meta_o]}(relation)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 13 + when /^#{Mx[:meta_o]}(coverage)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 14 + when /^#{Mx[:meta_o]}(rights)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 15 + when /^#{Mx[:meta_o]}(keywords)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(copyright)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(translator|translated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('translator',$2) + when /^#{Mx[:meta_o]}(illustrator|illustrated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('illustrator',$2) + when /^#{Mx[:meta_o]}(prepared_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(digitized_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(comments?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(abstract)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(tags?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(catalogue)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_loc)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_loc',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_dewey)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_dewey',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_pg)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_pg',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_isbn)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_isbn',$2,'meta','extra') + when /^#{Mx[:meta_o]}(toc|structure)#{Mx[:meta_c]}\s*(.+?)$/; header('structure',$2,'process','instruct') + when /^#{Mx[:meta_o]}(level|page|markup)#{Mx[:meta_c]}\s*(.+?)$/; header('markup',$2,'process','instruct') + when /^#{Mx[:meta_o]}(bold)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(italics|itali[sz]e)#{Mx[:meta_c]}\s*(.+?)$/; header('italicize',$2,'process','instruct') + when /^#{Mx[:meta_o]}(vocabulary|wordlist)#{Mx[:meta_c]}\s*(.+?)$/; header('vocabulary',$2,'process','instruct') + when /^#{Mx[:meta_o]}(css|stylesheet)#{Mx[:meta_c]}\s*(.+?)$/; header('css',$2,'process','instruct') + when /^#{Mx[:meta_o]}(links)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(prefix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') #add a & b + when /^#{Mx[:meta_o]}(suffix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(information)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(contact)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(rcs|cvs)#{Mx[:meta_c]}\s*(.+?)$/; header('version',$2,'process','instruct') + else nil + end + end + def dublin + if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ + start_is_match + else nil + end + end + def meta + if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ + start_is_match + else nil + end + end + end +end +__END__ diff --git a/lib/sisu/v5/wikispeak.rb b/lib/sisu/v5/wikispeak.rb index 65e87c13..b87fef61 100644 --- a/lib/sisu/v5/wikispeak.rb +++ b/lib/sisu/v5/wikispeak.rb @@ -67,7 +67,7 @@ module SiSU_Wikispeak include SiSU_Viz require_relative 'plaintext_format' # plaintext_format.rb include Format - require_relative 'shared_txt' + require_relative 'txt_shared' @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 @@tablefoot='' class Source @@ -149,7 +149,7 @@ module SiSU_Wikispeak end end class Scroll . + + 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: epub generation, processing + +=end +module SiSU_XHTML_EPUB2 + require 'pstore' + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'xhtml_table' # xhtml_table.rb + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb + include SiSU_XHTML_EPUB2_Format + require_relative 'xhtml_epub2_segments' # xhtml_epub2_segments.rb + include SiSU_XHTML_EPUB2_Seg + require_relative 'xhtml_epub2_tune' # xhtml_epub2_tune.rb + include SiSU_XHTML_EPUB2_Tune + require_relative 'xhtml_epub2_concordance' # xhtml_epub2_concordance.rb + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + songsheet + end + def songsheet + begin + @md=@particulars.md + @fnb=@md.fnb + @env=@particulars.env + unless @opt.act[:quiet][:set]==:on + tool=(@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? "#{@env.program.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'EPUB',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'EPUB',tool).green_title_hi + if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").flow + end + end + @env.processing_path.epub_bld #(@md) + @env.processing_path.epub_cp_images(@md) + data=nil + SiSU_Env::FileOp.new(@md).mkdir.output.epub + @tuned_file_array=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(@particulars).tuned_file_instructions + data=@tuned_file_array + toc=SiSU_XHTML_EPUB2::Source::Toc.new(@md,data).songsheet + data=@tuned_file_array + SiSU_XHTML_EPUB2::Source::ScrollHeadAndSegToc.new(@md,toc).in_common #watch + SiSU_XHTML_EPUB2::Source::Seg.new(@md,data).songsheet + SiSU_XHTML_EPUB2::Source::Output.new(@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + unless (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"] + texfiles.each do |f| + if FileTest.file?(f) + File.unlink(f) + end + end + end + SiSU_Env::Clear.new(@opt.cmd,@opt.fns).param_instantiate + @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc,@@seg_ad={},{},{},{},{},{} + @@seg_total,@@tracker,@@loop_count,@@tablehead,@@number_of_cols=0,0,0,0,0 + @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@segtocband,@@tablefoot=Array.new(7){[]} + @@filename_seg,@@seg_url,@@fn,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','','','' + @@is4=@@is3=@@is2=@@is1=@@heading1=@@heading2=@@heading3=@@heading4=0 + end + end + private + class XHTML_Environment + def initialize(particulars) + @particulars=particulars + @md,@env=particulars.md,particulars.env + @vz=SiSU_Viz::Defaults.new + @env,@css=particulars.env,SiSU_Style::CSS.new + end + def directories + SiSU_Env::FileOp.new(@md).mkdir.output.epub + end + def tuned_file_instructions + @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) + directories + ao_array=@particulars.ao_array # ao file drawn here + @tuned_file_array=SiSU_XHTML_EPUB2_Tune::Tune.new(ao_array,@md).songsheet + @tuned_file_array + end + end + class Endnotes + include SiSU_XHTML_EPUB2_Format + def initialize(md,data) + @md,@data=md,data + end + def scroll + @scr_endnotes=[] + @data.each do |dob| + pg=dob.dup + unless pg.is ==:code + if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ / + endnote_array=[] + if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m) + end + if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m) + end + if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m) + end + endnote_array.flatten.each do |note| + txt_obj={ txt: note } + format_scroll=SiSU_XHTML_EPUB2_Format::FormatScroll.new(@md,txt_obj) + @scr_endnotes << format_scroll.endnote_body + end + end + end + end + @scr_endnotes + end + end + class Toc + @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } + @@seg_url='' + @@firstseg=nil + def initialize(md=nil,data='') + @md,@data=md,data + @vz=SiSU_Viz::Defaults.new + @epub=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md) + @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md + @make=SiSU_Env::ProcessingSettings.new(@md) + end + def songsheet #extracts toc for scroll & seg + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Toc').txt_grey + end + toc=nil + @@firstseg=nil + @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } + md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] + @nav_no=0 + @s_a_no,@s_b_no,@s_c_no,@lv5_no,@lv6_no=0,0,0,0,0 + @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap + @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close + @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author + @@toc[:ncx] << @epub.toc_ncx.navmap_open + @@toc[:opf] << @epub.metadata_opf.package_open + @@toc[:opf] << @epub.metadata_opf.metadata + @@toc[:opf] << @epub.metadata_opf.manifest_open + @@toc[:seg] << %{
    \n
    } + @@toc[:scr] << %{
    \n
    } + if defined? @md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + md_opf_a_content << @epub.metadata_opf.manifest_cover_image_information(@md) + md_opf_a_spine << @epub.metadata_opf.spine_cover_image + md_opf_a_guide << @epub.metadata_opf.guide_cover_image + end + md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc + if @make.build.toc? + md_opf_a_spine << @epub.metadata_opf.spine_sisu_toc + md_opf_a_guide << @epub.metadata_opf.guide_sisu_toc + end + @ncxo=[nil,false,false,false,false,false,false] + @dob_toc2,@dob_toc3=nil,nil + @ncx_cls=[] + @level_a_first_occurrence=true + @data.each do |dob| + if dob.is==:heading \ + || dob.is==:heading_insert + dob_toc=dob.dup + toc=case dob_toc.ln + when 1 + @s_a_no +=1 + lv_name='section_a' + @s_a_no.to_s + @nav_no+=1 + @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + if @level_a_first_occurrence \ + && @make.build.toc? + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc + @level_a_first_occurrence=false + end + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_1 + when 2 + @s_b_no +=1 + lv_name='section_b' + @s_b_no.to_s + @nav_no+=1 + @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_2 + when 3 + @s_c_no +=1 + lv_name='section_c' + @s_c_no.to_s + @nav_no+=1 + @nav_no3=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_3 + when 4 + @ncx_cls=[] + lv_name=dob_toc.name + @nav_no+=1 + @dob_name=dob.name + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @ncxo[4],@ncxo[5],@ncxo[6]=true,false,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_4 + when 5 + @ncx_cls=[] + hashtag='#o' + dob_toc.ocn.to_s + lv_name=@dob_name + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @ncxo[5],@ncxo[6]=true,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_5 + when 6 + @ncx_cls=[] + hashtag='#o' + dob_toc.ocn.to_s + lv_name=@dob_name + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @ncxo[6]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_6 + else nil + end + toc.each do |k,d| + d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + end if toc + if @@firstseg.nil? \ + and dob.ln==4 \ + and dob.name =~/\S+/ + @@firstseg=dob.name + end + if toc + begin + @@toc[:seg] << toc[:seg] + @@toc[:scr] << toc[:seg] + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + end + end + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false + md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) + @@toc[:seg] << "
    \n
    " + @@toc[:scr] << "
    \n
    " + @@toc[:ncx] << @epub.toc_ncx.navmap_close + @@toc[:ncx] << @epub.toc_ncx.close + @@toc[:opf] << md_opf_a_content << @epub.metadata_opf.manifest_close + @@toc[:opf] << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close + @@toc[:opf] << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close + @@toc[:opf] << @epub.metadata_opf.package_close + @@toc[:opf]=@@toc[:opf].flatten + SiSU_XHTML_EPUB2::Source::Output.new(@md,@@toc[:opf]).epub_metadata_opf + SiSU_XHTML_EPUB2::Source::Output.new(@md,@@toc[:ncx]).epub_toc_ncx + @md.firstseg=@@firstseg + @@toc + end + protected + def level_1 + dob=@data + linkname,link=dob.obj.strip,dob.ocn + title=if dob.obj !~/Document Information/ + linkname + else + link='metadata' + %{
    #{linkname}} + end + toc={} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:seg]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ #check + format_toc.lev0 + else format_toc.lev1 + end + title=if dob.ocn ==0 + if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + %{#{linkname}} + else linkname + end + else + @@toc[:scr] << '
    ' + link=(dob.ln) \ + ? dob.ln + : '' + %{#{linkname}} + end + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + format_toc.lev0 + else format_toc.lev1 + end + toc + end + def level_2 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + end + txt_obj={ txt: linkname } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev2 + if p_num + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev2 + end + toc + end + def level_3 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + end + txt_obj={ txt: linkname } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev3 + if p_num + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev3 + end + toc + end + def level_4 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) if ocn + if dob.ln==4 + seg_link=%{ + #{dob.obj} + } + @@seg_url=dob.name + elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/ + seg_link=dob.obj.gsub(/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/, + %{} + + %{\\1 \\2 }) + end + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) if ocn + txt_obj={ txt: seg_link } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev4 + title=%{#{p_num.goto}#{linkname}} if p_num + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev4 + toc + end + def level_5 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + toc={} + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + lnk_n_txt=%{ + #{linkname} + } + txt_obj={ txt: lnk_n_txt } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:seg]=format_toc.lev5 + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev5 + end + toc + end + def level_6 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + toc={} + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + lnk_n_txt=%{ + #{linkname} +} + txt_obj={ txt: lnk_n_txt } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:seg]=format_toc.lev6 + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev6 + end + toc + end + end + class ScrollHeadAndSegToc < Toc + def initialize(md='',toc='',links_guide_toc='') + @md,@toc,@links_guide_toc=md,toc,links_guide_toc + @vz=SiSU_Viz::Defaults.new + end + def in_common + toc_shared=[] + segtoc=[] + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Scroll & Segtoc').txt_grey + end + format_head_toc=SiSU_XHTML_EPUB2_Format::HeadToc.new(@md) + dochead=format_head_toc.head + dochead=dochead.gsub(/toc\.(html)/,'doc.\1') #kludge + toc_shared << dochead #<< ads.div.major + segtoc << format_head_toc.head #<< ads.div.major + if defined? @md.rights.all \ + and @md.rights.all + rights=format_head_toc.rights.all + rights=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(rights).clean + end + if defined? @md.notes.prefix_b \ + and @md.notes.prefix_b + prefix_b=format_head_toc.prefix_b + prefix_b=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(prefix_b).clean + end + tmp_head=nil + doc_title_endnote=@md.title.full.gsub(/(\*+)/,'\1') + tmp_head=doc_title_endnote + "\n" + txt_obj={ txt: tmp_head } + format_txt_obj=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,txt_obj) + toc_shared << format_txt_obj.center_bold + segtoc << format_txt_obj.center_bold + if defined? @md.creator.author \ + and @md.creator.author + creator_endnote=@md.creator.author.gsub(/(\*+)/,%{#{$ep[:hsp]}\\1}) + tmp_head=creator_endnote + "\n" + txt_obj={ txt: tmp_head } + format_txt_obj=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,txt_obj) + toc_shared << format_txt_obj.center_bold + segtoc << format_txt_obj.center_bold + end + tmp_head=nil + if defined? @md.prefix_a \ + and @md.prefix_a + tmp_head ||= %{#{@md.prefix_a}\n} + toc_shared << tmp_head.dup + segtoc << tmp_head.dup + end + tmp_head=nil + toc_shared << @links_guide_toc + if defined? @md.rights.all \ + and @md.rights.all + toc_shared << rights + end + if defined? @md.prefix_b \ + and @md.prefix_b + toc_shared << prefix_b + end + #Table of Contents added/appended here + toc_shared << @toc[:scr] + segtoc << @links_guide_toc + segtoc << @toc[:seg] + if defined? @md.rights.all \ + and @md.rights.all + segtoc << rights + end + if defined? @md.prefix_b \ + and @md.prefix_b + segtoc << prefix_b + end + #Segtoc tail added here + segtoc << format_head_toc.xhtml_close + segtoc=segtoc.flatten.compact #watch + SiSU_XHTML_EPUB2::Source::Output.new(@md).make_cover_image + SiSU_XHTML_EPUB2::Source::Output.new(@md,segtoc).make_segtoc + segtoc=[] + @toc[:scr],@toc[:seg]=[],[] + toc_shared + end + end + class Table < SiSU_XHTML_Table::TableXHTML + end + class Seg < SiSU_XHTML_EPUB2_Seg::Seg + end + class Output + def initialize(md,output='') + @md,@output=md,output + @epub_doc="#{@md.fnb}.epub" + @epub_header=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md) + @make=SiSU_Env::ProcessingSettings.new(@md) + @make_file=SiSU_Env::CreateFile.new(@md.fns) + end + def songsheet + mimetype + metainf_container + css + images if @md.ec[:image] + #concordance #uncomment to enable inclusion of concordance file + output_zip + end + def mimetype + out=@make_file.epub.mimetype + out<<@epub_header.mimetype + out.close + end + def metainf_container #container.xml file in META-INF directory + out=@make_file.epub.metainf_cont + out<<@epub_header.metainf_container + out.close + end + def css + out=@make_file.epub.xhtml_css + out << SiSU_XHTML_EPUB2_Format::CSS.new.css_epub_xhtml + out.close + end + def epub_toc_ncx + begin + out=@make_file.epub.toc_ncx + @output.each do |para| + unless para =~/\A\s*\Z/ + out.puts para + end + end + out.close + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def epub_metadata_opf + begin + out=@make_file.epub.metadata + @output.each do |para| + unless para =~/\A\s*\Z/ + out.puts para + end + end + out.close + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def images + img_pth=@md.env.path.image_source_include + img_src_pth=unless @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ + @md.file.output_path.epub.rel_image + else + pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] + pt + '/image' + end + @md.ec[:image].each do |x| + if FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ + && FileTest.file?("#{img_src_pth}/#{x}") + FileUtils::cp("#{img_src_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") + elsif FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ + && FileTest.file?("#{img_pth}/#{x}") + FileUtils::cp("#{img_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") + else STDERR.puts %{\t*WARN* did not find image - "#{x}" in #{img_src_pth} or #{img_pth} [#{__FILE__}:#{__LINE__}]} + end + end + end + def concordance + SiSU_XHTML_EPUB2_Concordance::Source.new(@md.opt).read + end + def output_zip + FileUtils::mkdir_p(@md.file.output_path.epub.dir) unless FileTest.directory?(@md.file.output_path.epub.dir) + if FileTest.directory?(@md.env.processing_path.epub) + pwd=Dir.pwd + Dir.chdir(@md.env.processing_path.epub) + system(" + zip -qXr9D #{@epub_doc} * + ") + FileUtils::mv(@epub_doc, @md.file.place_file.epub.dir) + Dir.chdir(pwd) + unless @md.opt.act[:maintenance][:set]==:on + FileUtils::rm_r(@md.env.processing_path.epub) + end + end + end + def make_cover_image + begin + if @md.make.cover_image? \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + filename_xhtml=@make_file.epub.xhtml_cover_image + cover_image=< + + + + Cover + + + + + +
    +
    + + + +
    +
    + + +WOK + filename_xhtml.puts cover_image,"\n" + filename_xhtml.close + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def make_segtoc + begin + if @make.build.toc? + filename_xhtml=@make_file.epub.xhtml_index + @output.each do |para| + para=para.strip + unless para =~/\A\s*\Z/ + filename_xhtml.puts para,"\n" + end + end + filename_xhtml.close + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_concordance.rb b/lib/sisu/v5/xhtml_epub2_concordance.rb new file mode 100644 index 00000000..5668521b --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_concordance.rb @@ -0,0 +1,324 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: epub concordance file (html concordance, wordmap, linked index + of words in document) + +=end +module SiSU_XHTML_EPUB2_Concordance + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb + include SiSU_XHTML_EPUB2_Format + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env,@md=@particulars.env,@particulars.md + wordmax=@env.concord_max + unless @md.wc_words.nil? + if @md.wc_words < wordmax + SiSU_XHTML_EPUB2_Concordance::Source::Words.new(@particulars).songsheet + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on + end + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on + SiSU_XHTML_EPUB2_Concordance::Source::Words.new(@particulars).songsheet + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class DocTitle + include SiSU_Viz + #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) + require_relative 'xhtml_epub2' # xhtml_epub2.rb + def initialize(particulars) + @particulars,@md=particulars,particulars.md + @data=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(particulars).tuned_file_instructions + @vz=SiSU_Viz::Defaults.new + @fnb=@md.fnb + @lex_button=%{SiSU home} + @doc_details =<
    } + - %{#{para_table}}). - gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{} + - %{#{para_table}}). - gsub(/#{Mx[:tc_c]}/, '
    } + - %{#{para_table}}). - gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{} + - %{#{para_table}}). - gsub(/#{Mx[:tc_c]}/, '
    #{$ep[:hsp]}

    #{@md.title.full}

    #{@md.creator.author}

    +WOK + end + def create + @css=SiSU_Env::CSS_Stylesheet.new(@particulars.md) + format_head_toc=SiSU_XHTML_EPUB2_Format::HeadToc.new(@md) + dochead=format_head_toc.head + < + #{@doc_details} +

    Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
    [For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

    +

    (The word listing/index is Case sensitive: Capitalized words appear before lower case)

    +

    + word (number of occurences)
    linked references to word within document
    + [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] +

    +

    + (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [#{$ep[:hsp]}http://[web host]/#{@fnb}/concordance.html#your_word#{$ep[:hsp]}] +

    +WOK + end + end + class Word + @@word_previous='' + def initialize(word,freq) + @word,@freq=word,freq + end + def html + w=if @word.capitalize==@@word_previous + %{\n

    #{@word}

    (#{@freq})

    \n\t

    } + else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html + %{\n

    #{@word}

    (#{@freq})

    \n\t

    } + end + @@word_previous=@word.capitalize + w + end + end + class Words + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb + include SiSU_XHTML_EPUB2_Format + require_relative 'sysenv' # sysenv.rb + include SiSU_Screen + def initialize(particulars) + @particulars=particulars + begin + @vz=SiSU_Viz::Defaults.new + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array + @path="#{@env.processing_path.epub}" + @freq=Hash.new(0) + @rxp_lv1=/^#{Mx[:lv_o]}1:/ #fix Mx[:lv_o] + @rxp_lv2=/^#{Mx[:lv_o]}2:/ #fix Mx[:lv_o] + @rxp_lv3=/^#{Mx[:lv_o]}3:/ #fix Mx[:lv_o] + @rxp_seg=/^#{Mx[:lv_o]}4:(\S+?)#{Mx[:lv_c]}/ + @rxp_title=Regexp.new("^#{Mx[:meta_o]}title#{Mx[:meta_c]}\s*(.+?)\s*$") + @rxp_t1=Regexp.new('^T1') + @rxp_t2=Regexp.new('^T2') + @rxp_t3=Regexp.new('^T3') + @rxp_excluded1=/(?:https?|file|ftp):\/\/\S+/ + @rxp_excluded0=/^(?:#{Mx[:fa_bold_o]}|#{Mx[:fa_italics_o]})?(?:to\d+|\d+| |#{Mx[:br_endnotes]}|EOF|#{Mx[:br_eof]}|thumb_\S+|snap_\S+|_+|-+|[(]?(?:ii+|iv|vi+|ix|xi+|xiv|xv|xvi+|xix|xx)[).]?|\S+?_\S+|[\d_]+\w\S+|[\w\d]{1,2}|\d{1,3}\w?|[0-9a-f]{16,64}|\d{2,3}x\d{2,3}|\S{0,2}sha\d|\S{0,3}\d{4}w\d\d|\b\w\d+|\d_all\b|e\.?g\.?)(?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})?$/mi #this regex causes and cures a stack dump in ruby 1.9 !!! + @rgx_splitlist=%r{[—.,;:-]+|#{Mx[:nbsp]}+}mi + @rgx_scanlist=%r{#{Mx[:fa_italics_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_italics_c]}|#{Mx[:fa_bold_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_bold_c]}|#{Mx[:url_o]}https?://\S+?#{Mx[:url_c]}|file://\S+|<\S+?>|\w+|[a-zA-Z]+}mi + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def songsheet + begin + #fix to use + p __LINE__.to_s + ':' + __FILE__ + p "#{@path}/content/#{@md.fn[:epub_concord]}" + p "#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" + @file_concordance=File.open("#{@path}/content/#{@md.fn[:epub_concord]}",'w') + map_para + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + @file_concordance.close + end + end + protected + def location_scroll(wordlocation,show) + @wordlocation=wordlocation + %{#{@wordlocation}; } + end + def location_seg(wordlocation,show) + @wordlocation,@show=wordlocation,show + @word_location_seg=wordlocation.gsub(/(.+?)\#(\d+)/,"\\1#{Sfx[:epub_xhtml]}#o\\2") unless wordlocation.nil? + case @wordlocation + when @rxp_t1 + %{[H]#{@show}, } + when @rxp_t2 + %{[H]#{@show}, } + when @rxp_t3 + %{[H]#{@show}, } + else %{#{@show}, } + end + end + def map_para + @seg,toy=nil,nil + @word_map={} + @ao_array.each do |line| + if defined? line.ocn + if (line.is ==:heading \ + || line.is ==:heading_insert) \ + && line.ln==4 + @seg=line.name + end + if line.ocn.to_s =~/\d+/ then toy=line.ocn.to_s + end + if toy =~/\d+/ \ + and toy !~/^0$/ + line.obj=line.obj.split(@rgx_splitlist).join(' ') #%take in word or other match + for word in line.obj.scan(@rgx_scanlist) #%take in word or other match + word=word.gsub(/#{Mx[:lnk_o]}|#{Mx[:lnk_c]}|#{Mx[:url_o]}|#{Mx[:url_c]}/,''). + gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,''). + gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). + gsub(/#{Mx[:gl_o]}#[a-z]+#{Mx[:gl_c]}/,''). + gsub(/#{Mx[:gl_o]}#[0-9]+#{Mx[:gl_c]}/,''). + gsub(/^\S$/,'') + word=nil if word.empty? + word=nil if word =~@rxp_excluded0 #watch + word=nil if word =~@rxp_excluded1 #watch + word=nil if word =~/^\S$/ + if word + word=word.gsub(/#{Mx[:br_nl]}|#{Mx[:br_line]}/,' '). + gsub(/#{Mx[:fa_o]}[a-z]{1,7}#{Mx[:fa_o_c]}|#{Mx[:fa_c_o]}[a-z]{1,7}#{Mx[:fa_c]}/,''). + gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}:[0-9a-f]{32}|[0-9a-f]{64}:[0-9a-f]{64})#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}|[0-9a-f]{64})#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:en_a_o]}(?:\d|[*+])*|#{Mx[:en_b_o]}(?:\d|[*+])*|#{Mx[:en_a_c]}|#{Mx[:en_b_c]}/mi,''). + gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,'').gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). + gsub(/<\/?\S+?>/,''). + gsub(/^\@+/,''). + strip. + gsub(/#{Mx[:tc_p]}.+/,''). + gsub(/[\.,;:"]$/,''). + gsub(/["]/,''). + gsub(/^\s*[\(]/,''). + gsub(/[\(]\s*$/,''). + gsub(/^(?:See|e\.?g\.?).+/,''). + gsub(/^\s*[.,;:]\s*/,''). + strip. + gsub(/^\(?[a-zA-Z]\)$/,''). + gsub(/^\d+(st|nd|rd|th)$/,''). + gsub(/^(\d+\.?)+$/, ''). + gsub(/#{Mx[:mk_o]}|#{Mx[:mk_c]}/,''). + gsub(/:name#\S+/,''). + gsub(/^\S$/,'') + word=nil if word =~/^\S$/ + word=nil if word =~/^\s*$/ #watch + if word + unless word =~/[A-Z][A-Z]/ \ + or word =~/\w+\s\w+/ + word=word.capitalize + end + @freq[word] +=1 + @word_map[word] ||= [] + if line !~@rxp_lv1 \ + and line !~@rxp_lv2 \ + and line !~@rxp_lv3 + @word_map[word] << location_seg("#{@seg}\##{toy}",toy) + else + @word_map[word] << case line + when @rxp_lv1; location_seg('T1',toy) + when @rxp_lv2; location_seg('T2',toy) + when @rxp_lv3; location_seg('T3',toy) + end + end + end + end + end + end + end + end + seg='' + @file_concordance << SiSU_XHTML_EPUB2_Concordance::Source::DocTitle.new(@particulars).create + alph=%W[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] + @file_concordance << '

    ' + alph.each {|x| @file_concordance << %{#{x},#{$ep[:hsp]}}} + @file_concordance << '

    ' + letter=alph.shift + @file_concordance << %{\n

    A

    } + for word in @freq.keys.sort! {|a,b| a.downcase<=>b.downcase} + f=/^(\S)/.match(word)[1] + if letter < f.upcase + while letter < f.upcase + if alph.length > 0 + letter=alph.shift + @file_concordance << %{\n

    #{letter}

    } + else break + end + end + end + keyword=SiSU_XHTML_EPUB2_Concordance::Source::Word.new(word,@freq[word]).html + if keyword !~ @rxp_excluded0 + if @word_map[word][0] =~ /\d+/ + @file_concordance << %{#{keyword}#{seg}#{@word_map[word].uniq.compact.join}} + end + @file_concordance << '

    ' + end + # special cases endnotes and header levels 1 - 3 + end + credits=@vz.credits_sisu_epub + @file_concordance << %{>#{credits}\n} # footer + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_format.rb b/lib/sisu/v5/xhtml_epub2_format.rb new file mode 100644 index 00000000..e53c3bfe --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_format.rb @@ -0,0 +1,2236 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: epub formating, css template + +=end +module SiSU_XHTML_EPUB2_Format + include SiSU_Viz + class ParagraphNumber + def initialize(md,ocn) + @md,@ocn=md,ocn.to_s + @ocn ||='' + end + def ocn_display + make=SiSU_Env::ProcessingSettings.new(@md) + if make.build.ocn? + ocn_class='ocn' + if @ocn==nil \ + or @ocn.to_i==0 \ + or @ocn.empty? + %{} + else + @ocn.gsub(/^(\d+|)$/, + %{}) + end + else + %{} + end + end + def name + (@ocn==nil || @ocn.empty?) ? '' : %{} + end + def id #w3c? "tidy" complains about numbers as identifiers ! annoying + (@ocn==nil || @ocn.empty?) ? '' : %{id="o#{@ocn}"} + end + def goto + (@ocn==nil || @ocn.empty?) ? '' : %{} + end + end + class CSS + def css_epub_xhtml + <<-WOK +/* SiSU epub css default stylesheet */ + body { + color: black; + background: #ffffff; + background-color: #ffffff; + } +/* + table { + margin-left: 5%; + display: block; + } + tr { + display: block; + } + th,td { + display: inline; + vertical-align: top; + } +*/ + a:link { + color: #003399; + text-decoration: none; + } + a:visited { + color: #003399; + text-decoration: none; + } + a:hover { + color: #000000; + background-color: #f9f9aa; + } +/* + a:hover { + border-bottom: 2px solid #777777; + background-color: #fff3b6; + } +*/ + a:hover img { + background-color: #ffffff; + } + a:active { + color: #003399; + text-decoration: underline; + } + a.lnkocn:link { + color: #777777; + text-decoration: none; + } + div { + margin-left: 0; + margin-right: 0; + } + div.p { + margin-left: 5%; + margin-right: 1%; + } + + .norm, .bold, .verse, .group, .block, .alt { + line-height: 133%; + margin-left: 0em; + margin-right: 2em; + margin-top: 12px; + margin-bottom: 0px; + padding-left: 0em; + text-indent: 0mm; + } + p, h0, h1, h2, h3, h4, h5, h6 { + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-size: 100%; + font-weight: normal; + line-height: 133%; + text-align: justify; + margin-left: 0em; + margin-right: 2em; + text-indent: 0mm; + margin-top: 0.8em; + margin-bottom: 0.8em; + } + p.norm { } + p.i1 {padding-left: 1em;} + p.i2 {padding-left: 2em;} + p.i3 {padding-left: 3em;} + p.i4 {padding-left: 4em;} + p.i5 {padding-left: 5em;} + p.i6 {padding-left: 6em;} + p.i7 {padding-left: 7em;} + p.i8 {padding-left: 8em;} + p.i9 {padding-left: 9em;} + + p.h0i0 { + padding-left: 0em; + text-indent: 0em; + } + p.h0i1 { + padding-left: 1em; + text-indent: -1em; + } + p.h0i2 { + padding-left: 2em; + text-indent: -2em; + } + p.h0i3 { + padding-left: 3em; + text-indent: -3em; + } + p.h0i4 { + padding-left: 4em; + text-indent: -4em; + } + p.h0i5 { + padding-left: 5em; + text-indent: -5em; + } + p.h0i6 { + padding-left: 6em; + text-indent: -6em; + } + p.h0i7 { + padding-left: 7em; + text-indent: -7em; + } + p.h0i8 { + padding-left: 8em; + text-indent: -8em; + } + p.h0i9 { + padding-left: 9em; + text-indent: -9em; + } + + p.h1i0 { + padding-left: 0em; + text-indent: 1em; + } + p.h1i1 { + padding-left: 1em; + text-indent: 0em; + } + p.h1i2 { + padding-left: 2em; + text-indent: -1em; + } + p.h1i3 { + padding-left: 3em; + text-indent: -2em; + } + p.h1i4 { + padding-left: 4em; + text-indent: -3em; + } + p.h1i5 { + padding-left: 5em; + text-indent: -4em; + } + p.h1i6 { + padding-left: 6em; + text-indent: -5em; + } + p.h1i7 { + padding-left: 7em; + text-indent: -6em; + } + p.h1i8 { + padding-left: 8em; + text-indent: -7em; + } + p.h1i9 { + padding-left: 9em; + text-indent: -8em; + } + + p.h2i0 { + padding-left: 0em; + text-indent: 2em; + } + p.h2i1 { + padding-left: 1em; + text-indent: 1em; + } + p.h2i2 { + padding-left: 2em; + text-indent: 0em; + } + p.h2i3 { + padding-left: 3em; + text-indent: -1em; + } + p.h2i4 { + padding-left: 4em; + text-indent: -2em; + } + p.h2i5 { + padding-left: 5em; + text-indent: -3em; + } + p.h2i6 { + padding-left: 6em; + text-indent: -4em; + } + p.h2i7 { + padding-left: 7em; + text-indent: -5em; + } + p.h2i8 { + padding-left: 8em; + text-indent: -6em; + } + p.h2i9 { + padding-left: 9em; + text-indent: -7em; + } + + p.h3i0 { + padding-left: 0em; + text-indent: 3em; + } + p.h3i1 { + padding-left: 1em; + text-indent: 2em; + } + p.h3i2 { + padding-left: 2em; + text-indent: 1em; + } + p.h3i3 { + padding-left: 3em; + text-indent: 0em; + } + p.h3i4 { + padding-left: 4em; + text-indent: -1em; + } + p.h3i5 { + padding-left: 5em; + text-indent: -2em; + } + p.h3i6 { + padding-left: 6em; + text-indent: -3em; + } + p.h3i7 { + padding-left: 7em; + text-indent: -4em; + } + p.h3i8 { + padding-left: 8em; + text-indent: -5em; + } + p.h3i9 { + padding-left: 9em; + text-indent: -6em; + } + + p.h4i0 { + padding-left: 0em; + text-indent: 4em; + } + p.h4i1 { + padding-left: 1em; + text-indent: 3em; + } + p.h4i2 { + padding-left: 2em; + text-indent: 2em; + } + p.h4i3 { + padding-left: 3em; + text-indent: 1em; + } + p.h4i4 { + padding-left: 4em; + text-indent: 0em; + } + p.h4i5 { + padding-left: 5em; + text-indent: -1em; + } + p.h4i6 { + padding-left: 6em; + text-indent: -2em; + } + p.h4i7 { + padding-left: 7em; + text-indent: -3em; + } + p.h4i8 { + padding-left: 8em; + text-indent: -4em; + } + p.h4i9 { + padding-left: 9em; + text-indent: -5em; + } + + p.h5i0 { + padding-left: 0em; + text-indent: 5em; + } + p.h5i1 { + padding-left: 1em; + text-indent: 4em; + } + p.h5i2 { + padding-left: 2em; + text-indent: 3em; + } + p.h5i3 { + padding-left: 3em; + text-indent: 2em; + } + p.h5i4 { + padding-left: 4em; + text-indent: 1em; + } + p.h5i5 { + padding-left: 5em; + text-indent: 0em; + } + p.h5i6 { + padding-left: 6em; + text-indent: -1em; + } + p.h5i7 { + padding-left: 7em; + text-indent: -2em; + } + p.h5i8 { + padding-left: 8em; + text-indent: -3em; + } + p.h5i9 { + padding-left: 9em; + text-indent: -4em; + } + + p.h6i0 { + padding-left: 0em; + text-indent: 6em; + } + p.h6i1 { + padding-left: 1em; + text-indent: 5em; + } + p.h6i2 { + padding-left: 2em; + text-indent: 4em; + } + p.h6i3 { + padding-left: 3em; + text-indent: 3em; + } + p.h6i4 { + padding-left: 4em; + text-indent: 2em; + } + p.h6i5 { + padding-left: 5em; + text-indent: 1em; + } + p.h6i6 { + padding-left: 6em; + text-indent: 0em; + } + p.h6i7 { + padding-left: 7em; + text-indent: -1em; + } + p.h6i8 { + padding-left: 8em; + text-indent: -2em; + } + p.h6i9 { + padding-left: 9em; + text-indent: -3em; + } + + p.h7i0 { + padding-left: 0em; + text-indent: 7em; + } + p.h7i1 { + padding-left: 1em; + text-indent: 6em; + } + p.h7i2 { + padding-left: 2em; + text-indent: 5em; + } + p.h7i3 { + padding-left: 3em; + text-indent: 4em; + } + p.h7i4 { + padding-left: 4em; + text-indent: 3em; + } + p.h7i5 { + padding-left: 5em; + text-indent: 2em; + } + p.h7i6 { + padding-left: 6em; + text-indent: 1em; + } + p.h7i7 { + padding-left: 7em; + text-indent: 0em; + } + p.h7i8 { + padding-left: 8em; + text-indent: -1em; + } + p.h7i9 { + padding-left: 9em; + text-indent: -2em; + } + + p.h8i0 { + padding-left: 0em; + text-indent: 8em; + } + p.h8i1 { + padding-left: 1em; + text-indent: 7em; + } + p.h8i2 { + padding-left: 2em; + text-indent: 6em; + } + p.h8i3 { + padding-left: 3em; + text-indent: 5em; + } + p.h8i4 { + padding-left: 4em; + text-indent: 4em; + } + p.h8i5 { + padding-left: 5em; + text-indent: 3em; + } + p.h8i6 { + padding-left: 6em; + text-indent: 2em; + } + p.h8i7 { + padding-left: 7em; + text-indent: 1em; + } + p.h8i8 { + padding-left: 8em; + text-indent: 0em; + } + p.h8i9 { + padding-left: 9em; + text-indent: -1em; + } + + p.h9i0 { + padding-left: 0em; + text-indent: 9em; + } + p.h9i1 { + padding-left: 1em; + text-indent: 8em; + } + p.h9i2 { + padding-left: 2em; + text-indent: 7em; + } + p.h9i3 { + padding-left: 3em; + text-indent: 6em; + } + p.h9i4 { + padding-left: 4em; + text-indent: 5em; + } + p.h9i5 { + padding-left: 5em; + text-indent: 4em; + } + p.h9i6 { + padding-left: 6em; + text-indent: 3em; + } + p.h9i7 { + padding-left: 7em; + text-indent: 2em; + } + p.h9i8 { + padding-left: 8em; + text-indent: 1em; + } + p.h9i9 { + padding-left: 9em; + text-indent: 0em; + } + + p.it0 { + margin-left: 0em; + margin-top: 6px; + margin-bottom: 0px; + line-height: 100%; + } + p.it1 { + margin-left: 1em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it2 { + margin-left: 2em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it3 { + margin-left: 3em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it4 { + margin-left: 4em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it5 { + margin-left: 5em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it6 { + margin-left: 6em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it7 { + margin-left: 7em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it8 { + margin-left: 8em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it9 { + margin-left: 9em; + margin-bottom: 0px; + margin-top: 0px; + line-height: 100%; + } + + p.group { } + + p.block { } + + p.alt { } + + p.verse { + margin-bottom: 6px; + } + + p.code { + font-family: inconsolata, andale mono, courier new, courier, monospace; + font-size: 90%; + text-align: left; + background-color: #eeeeee; + } + + p.caption { + text-align: left; + font-size: 80%; + display: inline; + } + + p.endnote { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-right: 2em; + } + p.endnote_indent { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-left: 2em; + margin-right: 2em; + } + + p.center { + text-align: center; + } + p.align_right { + text-align: right; + } + p.bold { + font-weight: bold; + } + p.bold_left { + font-weight: bold; + text-align: left; + } + p.centerbold { + text-align: center; + font-weight: bold; + } + p.em { + font-weight: bold; + font-style: normal; + background: #fff3b6; + } + + p.small { + font-size: 80%; + margin-top: 0px; + margin-bottom: 0px; + margin-right: 6px; + text-align: left; + } + + .tiny, .tiny_left, .tiny_right, .tiny_center { + font-size: 10px; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 6px; + text-align: left; + } + p.tiny { } + p.tiny_left { + margin-left: 0px; + margin-right: 0px; + text-align: left; + } + p.tiny_right { + margin-right: 1em; + text-align: right; + } + p.tiny_center { + margin-left: 0px; + margin-right: 0px; + text-align: center; + } + + p.concordance_word { + line-height: 150%; + font-weight: bold; + display: inline; + margin-top: 4px; + margin-bottom: 1px; + } + p.concordance_count { + font-size: 80%; + color: #777777; + display: inline; + margin-left: 0em; + } + p.concordance_object { + font-size: 80%; + line-height: 120%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + p.book_index_lev1 { + line-height: 100%; + margin-top: 4px; + margin-bottom: 1px; + } + p.book_index_lev2 { + line-height: 100%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + + p.quickref { + font-size: 10px; + font-style: italic; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 5px; + text-align: left; + } + p.bigref { + font-size: 11px; + font-weight: bold; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 5px; + text-align: center; + } + + p.letter { + font-weight: bold; + font-size: 80%; + margin-left: 0em; + margin-top: 2px; + margin-bottom: 2px; + margin-right: 6px; + text-align: left; + color: white; + background: #880000; + } + + tt { + font-family: inconsolata, andale mono, courier new, courier, monospace; + background-color: #eeeeee; + } + + label.ocn { + width: 2%; + float: right; + top: 0; + font-size: 10px; + margin-top: 0px; + margin-bottom: 5px; + color: #777777; + margin-right: 5px; + text-align: right; + background-color: #ffffff; + } + + table { } + tr { } + th,td { + vertical-align: top; + text-align: left; + } + th { + font-weight: bold; + } + + p.left, th.left, td.left { + text-align: left; + } + p.small_left, th.small_left, td.small_left { + text-align: left; + font-size: 80%; + } + p.right, th.right, td.right { + text-align: right; + } + + #horizontal_links { + background: #eeeeee; + margin-left: 5%; + margin-right: 5%; + } + #horizontal { + margin: 0; + padding: 0 0 0 10px; + border-top: 1px solid #000077; + border-bottom: 1px solid #000077; + } + #horizontal li { + margin: 0 0 0 0; + padding: 0 16px 0 0; + display: inline; + list-style-type: none; + text-align: left; + background: none; + } + #horizontal a { + line-height: 12px; + margin: 0 0 0 0; + text-decoration: none; + color: #000077; + } + #horizontal a.active, #horizontal a:hover { + border-bottom: 2px solid #777777; + padding-bottom: 2px; + color: #000077; + } + #horizontal a:hover { + color: #000077; + } + + #document_versions { + position: absolute; + top: 10mm; + right: 2%; + width: 12%; + float: right; + } + + #vertical_links { + position: absolute; + top: 10mm; + right: 0px; + width: 20%; + background: #dddddd; + float: right; + } + #vertical { + padding: 0 12px 0px 0px; + margin-left: 2%; + margin-right: 2%; + } + #vertical li { + display: block; + list-style-type: none; + } + #vertical a { + line-height: 12px; + text-decoration: none; + color: #000077; + } + #vertical a.active, #vertical a:hover { + border-bottom: 2px solid #777777; + padding-bottom: 2px; + color: #000077; + } + + ul, li { + list-style-type: none; + list-style: none; + padding-left: 20px; + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-weight: normal; + line-height: 150%; + text-align: justify; + text-indent: 0mm; + margin-left: 1em; + margin-right: 2em; + margin-top: 3px; + margin-bottom: 3px; + } + + li { + background: url(../image/bullet_09.png) no-repeat 0px 6px; + } + + ul { + } + li.bullet { margin-left: 0em; } + li.i1 { margin-left: 1em; } + li.i2 { margin-left: 2em; } + li.i3 { margin-left: 3em; } + li.i4 { margin-left: 4em; } + li.i5 { margin-left: 5em; } + li.i6 { margin-left: 6em; } + li.i7 { margin-left: 7em; } + li.i8 { margin-left: 8em; } + li.i9 { margin-left: 9em; } + + li.doc, li.ref, li.refcenter { + margin-top: 0px; + margin-bottom: 0px; + margin-right: 0px; + font-size: 8px; + font-style: normal; + text-align: left; + } + li.doc { + background: url(../image/bullet_09.png) no-repeat 0px 6px; + padding-left: 16px; + margin-left: 10px; + margin-right: 0px; + } + li.ref { + background: none; + padding-left: 0; + margin-left: 0; + color: #777777; + } + li.refcenter { + background: url(../image/bullet_09.png) no-repeat 0px 6px; + padding-left: 20px; + margin-left: 10%; + font-size: 9px; + color: #777777; + text-align: center; + } + li.refbold { + list-style-type: none; + padding-left: 16px; + margin-left: 0; + margin-right: 10mm; + font-weight: bold; + } + + h0, h1, h2, h3, h4, h5, h6 { + font-weight: bold; + line-height: 120%; + text-align: left; + margin-top: 20px; + margin-bottom: 10px; + } + h4.norm, h5.norm, h6.norm { + margin-top: 10px; + margin-bottom: 0px; + } + h1.center, h2.center, h3.center, h4.center, h5.center, h6.center { + text-align: center; + } + h1 { font-size: 120%; } + h2 { font-size: 115%; } + h3 { font-size: 110%; } + h4 { font-size: 105%; } + h5 { font-size: 100%; } + h6 { font-size: 100%; } + h0 { font-size: 80%; } + + h1.i {margin-left: 2em;} + h2.i {margin-left: 3em;} + h3.i {margin-left: 4em;} + h4.i {margin-left: 5em;} + h5.i {margin-left: 6em;} + h6.i {margin-left: 7em;} + h7.i {margin-left: 8em;} + h8.i {margin-left: 9em;} + h9.i {margin-left: 10em;} + + .toc { + font-weight: normal; + margin-top: 6px; + margin-bottom: 6px; + } + h1.toc { + margin-left: 1em; + font-size: 115%; + line-height: 150%; + } + h2.toc { + margin-left: 2em; + font-size: 110%; + line-height: 140%; + } + h3.toc { + margin-left: 3em; + font-size: 105%; + line-height: 120%; + } + h4.toc { + margin-left: 4em; + font-size: 100%; + line-height: 120%; + } + h5.toc { + margin-left: 5em; + font-size: 95%; + line-height: 110%; + } + h6.toc { + margin-left: 6em; + font-size: 90%; + line-height: 110%; + } + + .microtoc { + margin-top: 2px; + margin-bottom: 2px; + } + + h1.microtoc { + margin-left: 0mm; + font-size: 115%; + } + h2.microtoc { + margin-left: 5mm; + font-size: 110%; + } + h3.microtoc { + margin-left: 10mm; + font-size: 105%; + } + h4.microtoc { + margin-left: 15mm; + font-weight: normal; + font-size: 100%; + } + h5.microtoc { + margin-left: 20mm; + font-weight: normal; + font-size: 95%; + } + h6.microtoc { + margin-left: 25mm; + font-weight: normal; + font-size: 90%; + } + + .subtoc { + margin-right: 34%; + font-weight: normal; + } + h5.subtoc { + margin-left: 2em; + font-size: 80%; + margin-top: 2px; + margin-bottom: 2px; + } + h6.subtoc { + margin-left: 3em; + font-size: 75%; + margin-top: 0px; + margin-bottom: 0px; + } + + div.substance { + width: 100%; + background-color: #ffffff; + } + div.ocn { + width: 5%; + float: right; + top: 0; + background-color: #ffffff; + } + div.endnote { + width: 100%; + background-color: #fffffff; + } + div.toc { + position: absolute; + float: left; + margin: 0; + padding: 0; + padding-top: 0.5em; + border: 0; + width: 5%; + background-color: #eeeeee; + margin-right:1em; + } + div.summary { + margin: 0; + padding: 0; + border-left: 2em solid #eeeeee; + padding-left: 0em; + background-color: #eeeeee; + } + div.content, div.main_column { + margin: 0; + padding: 0; + border-left: 0% solid #ffffff; + padding-left: 5%; + } + div.content:after { + content:' '; + clear:both; + display:block; + height:0; + overflow:hidden + } + div.footer { + clear:left; + padding: 0.5em; + font-size: 80%; + margin: 0; + } + div.toc ul { + list-style: none; + padding: 0; + margin: 0; + } + div.toc li ul a, li ul span.currentlink + { + font-weight: normal; + font-size: 90%; + padding-left: 2em; + background-color: #eeeeee; + } + div.toc a, span.currentlink{ + display:block; + text-decoration: none; + padding-left: 0.5em; + color: #0000aa; + } + hr { + width: 90%; + } + + span.currentlink { + text-decoration: none; + background-color: #aaaaf9; + } + + div.toc a:visited { + color: #0000aa; + } + div.toc a:hover { + color: #000000; + background-color: #f9f9aa; + } + + h1.c, h2.c, h3.c, h4.c, h5.c, h6.c, p.c { + text-align: center + } + h1.red, h2.red, h3.red, h4.red, h5.red, h6.red { + text-align: center; + color: #ff0000; + margin-left: 5mm; + text-indent: 5mm; + margin-top: 30px; + margin-bottom: 20px; + margin-right: 15mm; + } + h1.ruby, h2.ruby, h3.ruby, h4.ruby, h5.ruby, h6.ruby { + text-align: center; + color: #990000; + margin-left: 5mm; + text-indent: 5mm; + margin-top: 30px; + margin-bottom: 20px; + margin-right: 15mm; + } + WOK + end + end + module SanitizeXML + def self.xml(x) + if x.is_a?(String) + x=x.gsub(/ /,' ') if Ep[:alt]==:on + x.gsub(/&/,'&'). + gsub(//,">"). + gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). + #gsub(//,'>'). + gsub(/\\\\/,'
    '). + gsub(/<br(?: \/)?>/,'
    ') + else x + end + end + end + class HeadInformation + include SiSU_Viz + attr_reader :md,:rdf,:vz + def initialize(md) + @md=md + # DublinCore 1 - title + @vz=SiSU_Viz::Defaults.new + @css=SiSU_Env::CSS_Stylesheet.new(md) + @seg_name_xhtml=(SiSU_XHTML_EPUB2::Source::Seg.new.seg_name_xhtml || []) + @seg_name_xhtml_tracker=(SiSU_XHTML_EPUB2::Source::Seg.new.seg_name_xhtml_tracker || []) + @tocband_scroll,@tocband_segtoc=nil,nil + @index,@metalink='index','#metadata' + end + def doc_type_xhtml + <<-WOK + + + WOK + end +=begin +~/epub + |-- META-INF + | `-- container.xml # simple, make sure full-path of rootfile points to metadata.opf + |-- content + | |-- 1.xhtml + | |-- 2.xhtml + | |-- 3.xhtml + | |-- ... .xhtml + | |-- concordance.xhtml + | |-- css + | | `-- xhtml.css + | |-- endnotes.xhtml + | |-- image + | | |-- arrow_next_red.png + | | |-- arrow_prev_red.png + | | |-- arrow_up_red.png + | | `-- bullet_09.png + | |-- index.xhtml + | |-- meta.xhtml + | |-- metadata.xhtml + | `-- toc.xhtml + |-- metadata.opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) + |-- mimetype # application/epub+zip + `-- toc.ncx #(i) head (ii) doc title (iii) navmap, list of navigation points (like chapters) +=end + def doc_type + doc_type_xhtml + end + def mimetype + <<-WOK +application/epub+zip + WOK + end + def metainf_container #container.xml file in META-INF directory + #simple, make sure full-path of rootfile points to metadata.opf + #epub_metadata.opf content.opf + <<-WOK + + + + + + + WOK + end + def sections(dob,fn_base) + name=fn_base + Sfx[:epub_xhtml] + dir_epub_cont=@md.env.processing_path.epub + '/' + Ep[:d_oebps] + segfilename=dir_epub_cont + '/' + name + output_epub_cont_seg=File.new(segfilename,'w') + output_epub_cont_seg << %{#{doc_type} + + + #{dob.obj} - + #{@md.html_title} + + + #{@css.xhtml_epub} + + #{@vz.color_body} +
    +
    + #{dob.ocn} +

    + #{dob.obj} +

    +
    +
    + + } +output_epub_cont_seg.close + end + def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map + def structure + open + head_open + head + head_close + doc_title + doc_author + navmap_open + #navmap ... + navmap_close + close + end + def open + <<-WOK + + + WOK + end + def close + <<-WOK + + WOK + end + def head_open + <<-WOK + + WOK + end + def head + depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4] + title=SanitizeXML.xml(@md.title.full) + author=SanitizeXML.xml(@md.author) + <<-WOK + + #{title} by #{author} + + + + + + + WOK + end + def head_close + <<-WOK + + WOK + end + def doc_title + txt=SanitizeXML.xml(@md.title.full) + <<-WOK + + #{txt} + + WOK + end + def doc_author + txt=SanitizeXML.xml(@md.author) + <<-WOK + + #{txt} + + WOK + end + def navmap_open + <<-WOK + + WOK + end + def navmap_sisu_toc(no) + id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ + ? '' + : "-#{no}" + <<-WOK + + + Table of Contents + + + + WOK + end + def navpoint(dob,no,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ + ? '' + : "-#{no}" + <<-WOK + + + #{dob.obj} + + + WOK + end + def navpoint_close + <<-WOK + + WOK + end + def navmap_close + <<-WOK + + WOK + end + self + end + def metadata_opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) + def structure + package_open + metadata_open + metadata_close + manifest_open + manifest_close + spine_open + spine_close + guide_open + guide_close + package_close + end + def package_open + <<-WOK + + + WOK + end + def package_close + <<-WOK + + WOK + end + def metadata #metadata dc + cover_image=if defined? @md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + %{\n <#{$ep[:o]}meta name="cover" content="cover_image" />} + else '' + end + author=if defined? @md.creator.author \ + and @md.creator.author =~/\S+/ + m='' + @md.creator.author_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.author.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + editor=if defined? @md.creator.editor \ + and @md.creator.editor =~/\S+/ + m='' + @md.creator.editor_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.editor.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + translator=if defined? @md.creator.translator \ + and @md.creator.translator =~/\S+/ + m='' + @md.creator.translator_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.translator.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + illustrator=if defined? @md.creator.illustrator \ + and @md.creator.illustrator =~/\S+/ + m='' + @md.creator.illustrator_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.illustrator.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + date_published=if defined? @md.date.published \ + and @md.date.published =~/\S+/ + x=@md.date.published.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + subject=if defined? @md.classify.subject \ + and @md.classify.subject =~/\S+/ + x=@md.classify.subject.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + language=if defined? @md.opt.lng \ + and @md.opt.lng =~/\S+/ + language=@md.opt.lng.gsub(/
    /,'
    ') + %{\n #{language}} + else '' + end + rights=if defined? @md.rights.all \ + and @md.rights.all =~/\S+/ + rights=SanitizeXML.xml(@md.rights.all) + rights=rights.gsub(//,' ') + %{\n #{rights}} + else '' + end + f=SiSU_Env::FileOp.new(@md) + <<-WOK + <#{$ep[:o]}metadata + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:opf="http://www.idpf.org/2007/opf" + xmlns:dcterms="http://purl.org/dc/terms/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0"> + #{@md.title.full} + #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} + #{f.output_path.epub.url.gsub(/http:\/\//,'')}/#{f.base_filename.epub} + urn:uuid:#{@md.dgst[1]} + + + WOK + end + def manifest_open + <<-WOK + + + + + + + WOK + end + def manifest_content_sisu_toc + <<-WOK + + WOK + end + def manifest_cover_image_information(md) + if defined? md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and md.make.cover_image[:cover] =~/\S+/ + <<-WOK + + WOK + else '' + end + end + def manifest_content(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + <<-WOK + + WOK + end + def manifest_images(imgs) + imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png'] + images=[" \n"] + imgs.each do |i| + image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2] + type=type.sub(/jpg/,'jpeg') + images<<<<-WOK + + WOK + end + images=images.join('') + images + end + def manifest_close + <<-WOK + + WOK + end + def spine_open + #spine: reading order of XHTML files from manifest, idref attribute refers back to id in manifest (exclude images, CSS etc.). + <<-WOK + + WOK + end + def spine_cover_image + <<-WOK + + WOK + end + def spine_sisu_toc + <<-WOK + + WOK + end + def spine(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + <<-WOK + + WOK + end + def spine_close + <<-WOK + + WOK + end + def guide_open + #guide: presentation order of XHTML files by reader). + <<-WOK + + WOK + end + def guide_cover_image + <<-WOK + + WOK + end + def guide_sisu_toc + <<-WOK + + WOK + end + def guide(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + name=name ? name : dob.name + guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) + <<-WOK + + WOK + end + def guide_close + <<-WOK + + WOK + end + self + end + def table_close + %{
    +#{@vz.table_close}} + end + def xhtml_close + %{#{@vz.credits_sisu_epub} + +} + end + end + class HeadToc < HeadInformation + def initialize(md) + super(md) + @md=md + @tocband_segtoc=make_seg + end + def manifest_link(text) + %{ #{text}} + end + def concordance_link(text) + if @md.concord_make + %{ + #{text} + } + else '' + end + end + def head + %{#{doc_type} + + + #{@css.xhtml_epub} + + #{@vz.color_body}} + end + def concordance + if @md.concord_make + %{#{@vz.margin_css} +

    + + Concordance + +

    +#{@vz.table_close}} + else + %{#{@vz.margin_css} +#{@vz.table_close}} + end + end + def links_guide_open(type='horizontal') + (type=='vertical') \ + ? links_guide_vertical_open + : links_guide_horizontal_open + end + def prefix_a + end + def rights + def all + rights=SanitizeXML.xml(@md.rights.all) + %{

    Rights: #{rights}

    } + end + self + end + def prefix_b + %{

    Prefix: #{@md.prefix_b}} + end + def make_seg + concord=concordance_link(@vz.nav_txt_concordance) + %{ + +
    + #{@vz.nav_txt_toc_link} + + + #{concord} +#{@vz.table_close}} + end + def manifest #check structure + manifest=manifest_link(@vz.nav_txt_manifest) + %{#{@vz.margin_txt_3} + #{@vz.paragraph_font_small} + #{manifest} + +#{@vz.table_close}} + end + def concordance #check structure + concord=concordance_link(@vz.nav_txt_concordance) + %{#{@vz.margin_txt_3} + #{@vz.paragraph_font_small} + #{concord} + +#{@vz.table_close}} + end + def metadata + %{#{@vz.margin_css} +

    + + MetaData + +

    +#{@vz.table_close}} + end + end + class HeadSeg < HeadInformation + def initialize(md) + super(md) + end + def head + %{#{doc_type} + + + #{@seg_name_xhtml[@seg_name_xhtml_tracker]} - + #{@md.html_title} + + + #{@css.xhtml_epub} + + #{@vz.color_body}} + end + def endnote_mark +%{ +
    +} + end + end + class HeadScroll < HeadToc + def initialize(md) + super(md) + end + def toc_owner_details + %{#{@vz.margin_txt_3} +#{@vz.paragraph_font_small} + + Owner Details + + #{$ep[:hsp]*3} + + + +#{@vz.table_close}} + end + end + class FormatTextObject + @vz=SiSU_Viz::Defaults.new + attr_accessor :md,:t_o,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url + def initialize(md,t_o) + @md,@t_o=md,t_o + if t_o.is_a?(Hash) + @txt =t_o[:txt] || nil + @ocn =t_o[:ocn] || nil + @ocn_display =t_o[:ocn_display] || nil + @headname =t_o[:headname] || nil + @trailer =t_o[:trailer] || nil + @endnote_part_a =t_o[:endnote_part_a] || nil + @endnote_part_b =t_o[:endnote_part_b] || nil + @lnk_url =t_o[:lnk_url] || nil + @lnk_txt =t_o[:lnk_txt] || nil + @format =t_o[:format] || nil + @target =t_o[:target] || nil #occasionally passed but not used + if @format and not @format.empty? + if @format=~/^\d:(\S+)/ #need more reliable marker #if @format =~ /#{Rx[:lv]}/ + headname=$1 #format[/\d~(\S+)/m,1] + @headname=(headname =~/^[a-zA-Z]/) \ + ? %{} + : %{} + @headname=(headname =~/^[a-zA-Z]/) \ + ? %{} + : %{} + end + end + elsif t_o.class.inspect =~/Object/ + @dob=t_o if defined? t_o.is + @named=nametags_seg(@dob) + @txt=((defined? t_o.obj) ? t_o.obj : nil) + @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil) + @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil) + else + if @md.opt.act[:maintenance][:set]==:on + p __FILE__ << ':' << __LINE__.to_s + p t_o.class + p caller + end + end + if @txt and not @txt.empty? + @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'') + end + @p_num=ParagraphNumber.new(@md,@ocn) + @vz=SiSU_Viz::Defaults.new + end + def nametags_seg(dob) #FIX + tags='' + if defined? dob.tags \ + and dob.tags.length > 0 # insert tags "hypertargets" + dob.tags.each do |t| + tags=tags << %{} + end + end + tags + end + def endnote_body + %{ +

    + #{@txt} +

    +} + end + def endnote_body_indent + %{ +

    + #{@txt} +

    +} + end + def no_paranum + %{ +
    + +

    + #{@txt} +

    +
    +} + end + def para_form_css(tag,attrib,txt) # regular paragraphs shaped here + ul=ulc='' + ul,ulc="
      \n ","\n
    " if @tag =~/li/ + %{ +
    + #{@p_num.ocn_display} + #{ul}<#{tag} class="#{attrib}" #{@p_num.id}> + #{@named}#{txt} + #{ulc} +
    +} + end + def para + para_form_css('p','norm',@txt) + end + def group + para_form_css('p','group',@txt) + end + def block + para_form_css('p','block',@txt) + end + def alt + para_form_css('p','alt',@txt) + end + def verse + para_form_css('p','verse',@txt) + end + def code + para_form_css('p','code',@txt) + end + def center + para_form_css('p','center',@txt) + end + def bold + para_form_css('p','bold',@txt) + end + def bullet + para_form_css('li','bullet',@txt) + end + def table + @txt=if @t_o.obj !~/^
    '). + gsub(/#{Mx[:br_obj]}/,'

    ') + para_form_css('p','norm',@txt) + end + def format(tag,attrib) + para_form_css(tag,attrib,@txt) + end + def title_heading(tag,attrib) + %{ +
    +<#{tag} class="#{attrib}"> + #{@named}#{@txt} + +
    +} + end + def title_heading1 + DISABLE[:epub][:per_section_title] \ + ? '' + : title_heading('h1','tiny') + end + def title_heading2 + DISABLE[:epub][:per_section_title] \ + ? '' + : title_heading('h2','tiny') + end + def title_heading3 + DISABLE[:epub][:per_section_title] \ + ? '' + : title_heading('h3','tiny') + end + def title_heading4 + '' + end + def seg_heading_sub(tag,attrib,txt) + txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + %{ +
    + #{@p_num.ocn_display} + <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} + #{@named}#{@txt} + +
    +} + end + def seg_heading4 + %{ +
    + #{@p_num.ocn_display} +

    + #{@txt} +

    +
    +} + end + def seg_heading5 + seg_heading_sub('p','bold',@txt) + end + def seg_heading6 + seg_heading_sub('p','bold',@txt) + end + def dl #check :trailer + "
    #{@txt} #{@trailer}
    " + end + def table_css_end + '
    +

    + ' + end + def gsub_body #unused + @txt=case @txt + when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\((i+|iv|v|vi+|ix|x|xi+)\)/ + @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'(\1)'). + gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((i+|iv|v|vi+|ix|x|xi+)\)/,'\1(\2)') + when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\(?(\d|[a-z])+\)/ + @txt.gsub(/^\((\d+|[a-z])+\)/,'(\1)'). + gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((\d+|[a-z])+\)/,'\1(\2)') + when /^\s*\d{1,3}\.\s/ + @txt.gsub(/^\s*(\d+\.)/,'\1') + when /^\s*[A-Z]\.\s/ + @txt.gsub(/^\s*([A-Z]\.)/,'\1') + else @txt + end + end + def bold_para + %{#{@vz.margin_txt_0} +

    + #{@txt} +

    +#{@vz.margin_num_css} + #{$ep[:hsp]*3} +#{@vz.table_close}} + end + def bold_heading #unused + @txt=@txt.gsub(/[1-9]~\S+/,''). + gsub(/[1-9]~/,'') + %{

    + #{@txt} +

    +#{@vz.margin_num_css} + #{$ep[:hsp]*3} +#{@vz.table_close}} + end + def toc_head_copy_at + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + def center + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + def bold + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + def center_bold + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + end + class FormatScroll < FormatTextObject + def initialize(md,txt) + super(md,txt) + @vz=SiSU_Viz::Defaults.new + end + end + class FormatSeg < FormatTextObject + def initialize(md,txt) + super(md,txt) + end + def endnote_seg_body(fn='') #FIX #url construction keep within single line... BUG WATCH 200408 + fn='doc' if fn.to_s.empty? #you may wish to reconsider, sends to 'doc' where no segment info + %{ +

    + #{@endnote_part_a}#{fn}#{Sfx[:epub_xhtml]}#{@endnote_part_b} +

    +} + end + def clean(txt) + txt=txt.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/,''). + gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'') + end + def subtoc_lev(tag,attrib) + @txt=clean(@txt) + txt=if @txt \ + and @txt =~/<\/?i>|/mi + @txt.gsub(/<\/?i>|/mi,'') #removes name markers from subtoc, go directly to substantive text + else @txt + end + note='' + if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end + note=$1 + note=note.gsub(/[\n\s]+/m,' ') + txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove + end + %{<#{tag} class="#{attrib}"> + #{txt} #{note} + } + end + def subtoc_lev5 + subtoc_lev('h5','subtoc') if @txt + end + def subtoc_lev6 + subtoc_lev('h6','subtoc') if @txt + end + def heading_sub(tag,attrib,txt) + txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + %{ +
    + #{@p_num.ocn_display} + <#{tag} class="#{attrib}" #{@p_num.id}> #{@headname} + #{@txt} + +
    +} + end + def heading4 + %{ +
    + #{@p_num.ocn_display} +

    + #{@t_o[:format]} + #{@txt} +

    +
    +} + end + def heading5 + heading_sub('p','bold',@txt) + end + def heading6 + heading_sub('p','bold',@txt) + end + def navigation_heading4 + %{ +
    +

    + #{@txt} +

    +#{@vz.table_close}} + end + def navigation_heading5 + %{

    + #{@txt} +

    } + end + def navigation_heading6 + %{

    + #{@txt} +

    } + end + def navigation_center + %{

    #{@txt}

    } + end + end + class FormatToc < FormatTextObject + def initialize(md,txt) + super(md,txt) + end + def links_guide + %{
  • + + #{@lnk_txt} + +
  • +} + end + def lev(tag,attrib) + if @txt + %{<#{tag} class="#{attrib}"> + #{@txt} + +} + else '' + end + end + def lev1 + lev('h1','toc') + end + def lev2 + lev('h2','toc') + end + def lev3 + lev('h3','toc') + end + def lev4 + lev('h4','toc') + end + def lev5 + lev('h5','toc') + end + def lev6 + lev('h6','toc') + end + def lev0 #docinfo + lev('h0','toc') + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_segments.rb b/lib/sisu/v5/xhtml_epub2_segments.rb new file mode 100644 index 00000000..d16e98e8 --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_segments.rb @@ -0,0 +1,543 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: epub segment generation, processing + +=end +module SiSU_XHTML_EPUB2_Seg + require_relative 'xhtml_shared' # xhtml_shared.rb + require_relative 'xhtml_epub2' # xhtml_epub2.rb + require_relative 'shared_metadata' # shared_metadata.rb + class Output + def initialize(md,outputfile,seg,type='') + @md,@output_epub_cont_seg,@seg,@type=md,outputfile,seg,type + end + def output #CONSIDER + if @seg[:title] =~/\S/ + filename_seg=[] + filename_seg << @seg[:title] << @seg[:nav] + if @type=='endnotes' + @seg[:headings]=[] #watch + txt_obj={ txt: 'Endnotes', ocn_display: ''} + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_endnotes] << @seg[:headings] << %{\n
    \n} << @seg[:endnote_all] << '
    ' + elsif @type=='idx' + @seg[:headings]=[] + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << @seg[:idx] << '
    ' + elsif @type=='metadata' + metadata=SiSU_Metadata::Summary.new(@md).xhtml_display.metadata + @seg[:headings]=[] + txt_obj={ txt: 'Metadata', ocn_display: ''} + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << metadata << '
    ' + elsif @type=='sisu_manifest' + env=SiSU_Env::InfoEnv.new(@md.fns) + path_and_name,url_and_name="#{env.path.output}/#{@md.fnb}/sisu_manifest.html","#{env.url.root}/#{@md.fnb}/sisu_manifest.html" + manifest=if FileTest.file?("#{path_and_name}")==true + <A list of available output types may be available at the following url:

    +

    #{url_and_name}

    +WOK + else '' + end + @seg[:headings]=[] + txt_obj={ txt: 'Manifest', ocn_display: ''} + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << manifest << '
    ' + else + filename_seg << @seg[:headings] << @seg[:main] << "\n\n" + end + filename_seg << @seg[:tail] << @seg[:nav] << @seg[:close] + filename_seg=filename_seg.flatten.compact #watch + filename_seg.each do |str| + unless str =~/\A\s*\Z/ + @output_epub_cont_seg << str.strip + end + end + @output_epub_cont_seg.close + end + end + end + class Seg + @@seg,@@seg_subtoc,@@seg_endnotes,@@seg_ad={},{},{},{} + @@seg_name,@@seg_name_xhtml=[],[] + @@seg_url=@@fn=@@get_hash_to=@@get_hash_fn='' + @@loop_count=@@seg_total=@@tracker=0 + @@is4=@@is3=@@is2=@@is1=0 + @@heading1=@@heading2=@@heading3=@@heading4=0 + @@seg[:headings],@@seg[:main],@@seg[:idx],@@seg[:tail],@@seg_subtoc_array,@@seg_endnotes_array,@@seg[:endnote_all]=Array.new(7){[]} + @@seg[:heading_endnotes]='' + @@tablehead,@@number_of_cols=0,0 + @@fns_previous='' + attr_reader :seg_name_xhtml,:seg_name_xhtml_tracker + def initialize(md='',data='') + @md,@data=md,data + @vz=SiSU_Viz::Defaults.new + @seg_name_xhtml=@@seg_name_xhtml || nil + @seg_name_xhtml_tracker=@@tracker || nil + @make=SiSU_Env::ProcessingSettings.new(@md) if @md + end + def songsheet + begin + data=get_subtoc_endnotes(@data) + data=articles(data) + SiSU_XHTML_EPUB2_Seg::Seg.new.cleanup # (((( added )))) + #### (((( END )))) #### + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + @@seg_name=[] + end + end + protected + def articles(data) + tracking,newfile=0,0 + @@is4=@@is3=@@is2=@@is1=0 + printed_endnote_seg='n' + idx_xhtml=nil + if @md.book_idx + idx_xhtml=SiSU_Particulars::CombinedSingleton.instance.get_idx_xhtml(@md).xhtml_idx + idx_xhtml.each {|x| @@seg[:idx] << x } + @@seg[:heading_idx]='' + end + data.each do |dob| + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 + @@seg_name << dob.name + dob.name + end + end + @@seg_name_xhtml=@@seg_name + @@seg_total=@@seg_name.length + testforartnum=@@seg_name_xhtml + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],@@seg_name.length) + end + SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + data.each do |dob| + #if defined? dob.obj \ + #and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/ + # ##Consider: remove, reinstate earlier? + # #while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/ + # # m=$1 + # # if map_nametags[m][:segname] + # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#{map_nametags[m][:segname]}#{Sfx[:html]}#\\1"}) + # # else + # # p "NOT FOUND name_tags: #{m}" + # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#\\1"}) # not satisfactory + # # end + # #end + #end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 + if dob.ocn==0 + @@heading4=dob.obj + else @@heading4=dob.obj + end + @@is4=newfile=1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==3 + @@heading3=dob.obj + @@is4,@@is3=0,1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==2 + @@heading2=dob.obj + @@is4,@@is3,@@is2=0,0,1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==1 + @@heading1=dob.obj + @@is4,@@is3,@@is2,@@is1=0,0,0,1 + end + if (@@is1 && !@@is2 && !@@is3 && !@@is4) + if not (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==1 + $_ #; check + end + end + if @@is4==1 + dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}" + if newfile==1 \ + or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/ + newfile=0 + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 + if tracking != 0 + SiSU_XHTML_EPUB2_Seg::Seg.new(@md).tail + segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking-1]}#{Sfx[:epub_xhtml]}" + output_epub_cont_seg=File.new(segfilename,'w') if @@seg_name_xhtml[tracking-1] + if dob.is==:heading \ + or @@seg_name_xhtml[tracking-1] !~/endnotes|book_index|metadata/ + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg).output + elsif dob.is==:heading_insert + if @@seg_name_xhtml[tracking-1]=='endnotes' + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'endnotes').output + elsif @@seg_name_xhtml[tracking-1]=='book_index' + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'idx').output + @@seg[:idx]=[] + elsif @@seg_name_xhtml[tracking-1]=='metadata' # navigation bug FIX + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output + else puts "#{__FILE__}::#{__LINE__}" + end + else puts "#{__FILE__}::#{__LINE__}" + end + SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise + heading_art(dob) + head(dob) + if @@seg_name_xhtml[tracking] =='metadata' + segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking]}#{Sfx[:epub_xhtml]}" + output_epub_cont_seg=File.new(segfilename,'w') + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output + SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise #BUG navigation bug with items following metadata, and occurring before manifest, this becomes a bug ... work area for book index, FIX + end + #@output_epub_cont_seg.close #%(((( EOF )))) --> + end + if tracking==0 + heading_art(dob) + head(dob) + end + end + tracking=tracking+1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 \ + and dob.name + @@get_hash_to=dob.name + @@get_hash_fn=dob.name + end + if dob.obj.is_a?(String) + markup(dob) + elsif dob.obj.is_a?(Array) + dob.obj.each do |pg| + markup(pg) + end + end + if testforartnum[tracking-1] =~/endnote/ + if printed_endnote_seg=='n' + printed_endnote_seg='y' + end + end + end + end + data + end + def heading_art(dob) + @@seg[:title]=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md).head + end + def head(dob) + clean=/|<:.*?>$/ + @p_num ||= '' + if @@is1==1 + if defined? @md.creator.author \ + and @md.creator.author + @author=%{#{@md.creator.author}\n} + end + ocn=(@@heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: @@heading1, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading1.gsub(clean,'') + @@heading1=@@heading1.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + end + if @@is2==1 + heading2=@@heading2 + ocn=(heading2[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading2.gsub(clean,'') + @@heading2=@@heading2.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + end + if @@is3==1 + heading3=@@heading3 + ocn=(heading3[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading3.gsub(clean,'') + @@heading3=@@heading3.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + end + if @@is4==1 + heading4=@@heading4 + ocn=(heading4[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading4.gsub(clean,'') + end + @@tracker=@@tracker+1 + end + def markup(dob) + @debug=[] + if dob.is ==:heading \ + || dob.is ==:heading_insert \ + || dob.is ==:para + #extend as necessary FIX + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) + end + sto=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,dob) + dob_xhtml=if dob.is==:heading \ + || dob.is==:heading_insert \ + || dob.is==:para + dob_xhtml=if dob.is==:heading \ + or dob.is==:heading_insert + if dob.ln==4 + sto.seg_heading4 # work on see SplitTextObject + elsif dob.ln==5 + sto.seg_heading5 + elsif dob.ln==6 + sto.seg_heading6 + end + elsif dob.is==:para + if dob.indent \ + and dob.hang \ + and dob.indent =~/[0-9]/ \ + and dob.hang =~/[0-9]/ + if dob.bullet_ + (dob.indent =~/[1-9]/) \ + ? sto.format('li',"i#{dob.indent}") + : sto.format('li','bullet') + elsif dob.indent == dob.hang + sto.format('p',"i#{dob.indent}") + elsif dob.indent != dob.hang + sto.format('p',"h#{dob.hang}i#{dob.indent}") + else sto.para + end + else sto.para + end + end + elsif dob.is ==:block \ + || dob.is ==:group \ + || dob.is ==:alt + sto.para #fix this should be block type specific #FIX + elsif dob.is==:verse + sto.verse + elsif dob.is==:code + sto.code + elsif dob.is==:table + sto.table + elsif dob.is==:break + sto.break + end + if @md.flag_separate_endnotes # may need to revisit, check + dob.obj=dob.obj.gsub(/"\s+href="#note_ref(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}#note_ref\\1">}) #endnote- twice #removed file type + end + if (dob.is ==:heading \ + || dob.is==:heading_insert \ + || dob.is==:para) \ + && (not dob.ocn or dob.ocn.to_s.empty?) + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) + end + if (dob.is==:heading \ + || dob.is==:heading_insert \ + || dob.is==:para) \ + and dob.note_ #dob.obj =~/ \n} + @@seg[:main] << dob_xhtml + if @make.build.segsubtoc? + @@seg[:main] << @@seg_subtoc[@@get_hash_fn] #% insertion of sub-toc + end + else + @@seg[:main] << dob_xhtml + end + end + def tail + format_head_seg=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md) + if @md.flag_auto_endnotes \ + and @@seg_endnotes[@@get_hash_fn] + @@seg[:tail] << %{\n
    \n
    \n} + if @@seg_endnotes[@@get_hash_fn].flatten.length > 0 + @@seg[:tail] << format_head_seg.endnote_mark + @@seg[:tail] << @@seg_endnotes[@@get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES| + end + @@seg[:tail] << '
    ' + @@seg[:tail] << '
    ' #this div closes div class content + end + @@seg[:close]=[] + @@seg[:close] << format_head_seg.xhtml_close + end + def reinitialise + @@seg[:headings],@@seg[:main],@@seg[:tail],@@seg[:credits]=Array.new(4){[]} + end + def cleanup + reinitialise + @@seg_total,@@tracker=0,0 + @@seg_endnotes,@@seg_subtoc={},{} + @@seg_endnotes_array,@@seg_subtoc_array=[],[] + @@seg[:endnote_all]=[] + end + def get_subtoc_endnotes(data) #get endnotes & sub-table of contents subtoc + data.each do |dob| + dob.obj=dob.obj.gsub(/
    (.+?)<\/a>/mi,'\1') + if @md.flag_auto_endnotes + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln.to_s =~/^[1234]/ \ + and not @@fn.to_s.empty? + @@seg_endnotes[@@fn]=[] + @@seg_endnotes[@@fn] << @@seg_endnotes_array + @@seg_endnotes_array=[] if dob.ln==4 + @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/ + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs + @@seg_subtoc[@@fn]=@@seg_subtoc_array + @@seg_subtoc_array=[] + if dob.name \ + and dob.obj + @@fn=dob.name + else + @@fn=(dob.name =~/\S+/) \ + ? dob.name + : '' + end + end + end + if dob.is==:heading \ + and dob.ln.to_s =~/^[56]/ + case dob.ln + when 5 + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) + subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc + when 6 + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) + subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc + end + @@seg_subtoc_array << subtoc + end + if @md.flag_auto_endnotes + ast,pls='*','+' + if dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(?:\d|#{ast}|#{pls})+ / \ + and dob.is !=:code # endnote- + endnote_array=[] + if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m + endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m) + end + if dob.obj=~/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m + endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m) + end + if dob.obj=~/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m + endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m) + end + endnote_array=endnote_array.flatten #.compact #check compacting + endnote_array.each do |note| + note_match=note.dup + note_match_seg=note.dup + e_n=note_match_seg[/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1] + try=e_n.split(/
    /) + try.each do |e| + txt_obj={ txt: e } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/ + format_seg.endnote_body_indent + else format_seg.endnote_body + end + @@seg_endnotes_array << note_match + end + try.join('
    ') + #% creation of separate end segment/page of all endnotes referenced back to reference segment + m=/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?href=")(#note_ref(?:\d|_a|_b)+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi + endnote_part_a=note_match_seg[m,1] + endnote_part_b=note_match_seg[m,2] + txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + note_match_all_seg=format_seg.endnote_seg_body(@@fn) #BUG WATCH 200408 + @@seg[:endnote_all] << note_match_all_seg + end + dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + end + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_tune.rb b/lib/sisu/v5/xhtml_epub2_tune.rb new file mode 100644 index 00000000..b46f49f0 --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_tune.rb @@ -0,0 +1,333 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: epub generation, epub pre-processing + +=end +require_relative 'param' +module SiSU_XHTML_EPUB2_Tune + require_relative 'sysenv' # sysenv.rb + include SiSU_Env; include SiSU_Screen + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb #watch + @@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 + @file=SiSU_Env::FileOp.new(@md) + @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX + end + def hard_output + @filename_tune=@file.write_file_processing.html_tune + data=[] + @data.each {|x| x.obj.strip; data << x if not x.obj.empty?} #1.9 array? + data.each do |dob| + @filename_tune.puts dob, "\n" #check + end + end + def marshal + File.open(@file.marshal.html_tune,'w') {|f| Marshal.dump(@data.to_a,f)} + end + end + class CleanXHTML + def initialize(html='') + @html=html + end + def clean + html=@html + str=if html.is_a?(String) + html + else html.obj + end + str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/
    /u,'
    '). + gsub(/#{Mx[:nbsp]}/u,$ep[:hsp]) + end + end + class Tune + def initialize(data,md) + @data,@md=data,md + @vz=SiSU_Viz::Defaults.new + @env=SiSU_Env::InfoEnv.new(@md.fns) + @sys=SiSU_Env::SystemCall.new + @env=SiSU_Env::InfoEnv.new(@md.fns) + @brace_url=SiSU_Viz::Defaults.new.url_decoration + end + def songsheet + begin + @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Tune').txt_grey + end + data=SiSU_XHTML_EPUB2_Tune::Tune.new(@data,@md).amp_angle_brackets + data=SiSU_XHTML_EPUB2_Tune::Tune.new(data,@md).endnotes_html + data=SiSU_XHTML_EPUB2_Tune::Tune.new(data,@md).url_markup + data=SiSU_XHTML_EPUB2_Tune::Tune.new(data,@md).markup + if @md.opt.act[:maintenance][:set]==:on #Hard Output Tune Optional on/off here + data=SiSU_XHTML_EPUB2_Tune::Output.new(data,@md).hard_output + SiSU_XHTML_EPUB2_Tune::Output.new(data,@md).marshal + end + SiSU_XHTML_EPUB2_Tune::Tune.new(@data,@md).output + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + def markup + @tuned_file=[] + @data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table + dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,"●#{$ep[:hsp]*2}"). + gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). + gsub(/#{Mx[:nbsp]}/,$ep[:hsp]). + gsub(/<(p|br)>/,'<\1 />') + dob.obj=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(dob.obj).clean + @tuned_file << dob + end + end + def urls(data) + @words=[] + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + data.each do |word| + @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + http_=true + if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + http_=false + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures + end + case m + when /\.png|\.jpg|\.gif|c=|\s\d+x\d+/ + w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\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=@md.file.output_path.epub.rel_image #image_path=@env.url.images_epub + ins=if u \ + and u.strip !~/^image$/ + %{
    #{caption}} + else %{#{caption}} + end + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) + else + link=m[/(.+)/m] + png=m.scan(/\S+/)[0].strip + link=link.strip + u=u.sub(/^#*/,'') #make neater + if map_nametags[u] \ + and map_nametags[u][:segname] + u=unless http_ + u=if u=~/^\d+$/ + u.gsub(/^(\d+)$/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#o\\1") if u !~/\// + else + u.gsub(/(\S+)/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#\\1") if u !~/\// + end + else u + end + elsif u =~/^:/ + u=u.gsub(/^:/,"#{@env.url.root}/") + elsif u =~/^\.\.\// + u=u.gsub(/^\.\.\//,"#{@env.url.root}/") + elsif u =~/https?:\/\// + else p "NOT FOUND name_tags: #{u}" + end + ins=%{#{link}} + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). + gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) + end + word + else word + end + word + end + @words=@words.join(' ') + end + def url_markup + data=@data + @tuned_file=[] + data.each do |dob| + unless dob.is==:code + if dob.obj =~/<::\s+/ #watch + dob.obj=dob.obj.gsub(/<::\s+(\S+?)\s+!>/, + %{\\1}) + end + if dob.obj =~/<:image\s+/ + dob.obj=dob.obj.gsub(/<:image\s+(http\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, + %{}). + gsub(/<:image\s+(http\S+)\s+(\S+)\s+>/, + %{}). + gsub(/<:image\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, + %{}). + gsub(/<:image\s+(\S+)\s+>/, + %{}) + end + if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + @word_mode=dob.obj.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)[()\[\]]*[,.;:!?'"]{0,2}|(?:#{Mx[:gl_o]}\S+?#{Mx[:gl_c]})+|[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+/mu) + words=urls(@word_mode) + dob.obj=dob.obj.gsub(/.+/m,words) + end + dob.obj=dob.obj.gsub(/\\copyright/i,%{©}) + dob.obj=if (dob.obj !~/\<:ad\s+\.\.\//) + dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, + %{\n
    \\3
    \n}) + else + dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, + %{\n
    \\3
    \n}) + end + dob.obj=dob.obj.gsub(/!pick/,%{stellar}). + gsub(/!new/,%{#{$ep[:hsp]}new}). + gsub(/<:h(.{1,7}?)>/,'\1'). + gsub(/<:to(\d{1,7}?)>/,%{to#{$ep[:hsp]}\{#{$ep[:hsp]}\\1#{$ep[:hsp]}\} }). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + if dob.obj =~/..\/\S+/ \ + and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ + dob.obj=dob.obj.gsub(/(\.\.\/\S+)/,'\1') + end + dob.obj=dob.obj.gsub(//m,'>') + end + @tuned_file << dob + end + end + def amp_angle_brackets + data,data_new=@data,[] + data.each do |dob| + dob.obj=dob.obj. + gsub(/&/u,'&'). + gsub(//u,'>') + data_new << dob + end + data_new + end + def endnotes_html + data=@data + @tuned_file=[] + a,s='_a','_s' + ast,pls='*','+' + data.each do |dob| + unless dob.is ==:code + dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + gsub(/(#{Mx[:en_b_o]})[*](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + gsub(/(#{Mx[:en_b_o]})[+](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug + if dob.obj =~/#{Mx[:en_a_o]}([*+]+)\s+.+?#{Mx[:en_a_c]}/ + m=$1.length.to_i + dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]})[*]+\s+(.+?)(#{Mx[:en_a_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) + gsub(/(#{Mx[:en_a_o]})([+]+)\s+(.+?)(#{Mx[:en_a_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) + end + end + @tuned_file << dob + end + end + def output + data=@data + @tuned_file=[] + data.each do |dob| + dob.obj=dob.obj.strip.chomp + @tuned_file << dob + end + @tuned_file << "\n" if (@md.fns =~/\.sst0/) #remove + @tuned_file + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_shared.rb b/lib/sisu/v5/xhtml_shared.rb new file mode 100644 index 00000000..27ddba4b --- /dev/null +++ b/lib/sisu/v5/xhtml_shared.rb @@ -0,0 +1,68 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: shared html parts + +=end +module SiSU_XHTML_Shared + require_relative 'defaults' # defaults.rb + require_relative 'xhtml_table' # xhtml_table.rb + class TableXHTML < SiSU_XHTML_Table::TableXHTML + end +end +__END__ diff --git a/lib/sisu/v5/xml_dom.rb b/lib/sisu/v5/xml_dom.rb index 6a2d7505..6f0391f1 100644 --- a/lib/sisu/v5/xml_dom.rb +++ b/lib/sisu/v5/xml_dom.rb @@ -67,7 +67,7 @@ module SiSU_XML_DOM require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'ao' # ao.rb - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format @@ -135,9 +135,9 @@ module SiSU_XML_DOM end end class Scroll - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb include SiSU_TextUtils - require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml + require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml @@xml={ body: [], open: [], close: [], head: [], sc: [] } def initialize(particulars) @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array diff --git a/lib/sisu/v5/xml_fictionbook.rb b/lib/sisu/v5/xml_fictionbook.rb deleted file mode 100644 index 446e12e2..00000000 --- a/lib/sisu/v5/xml_fictionbook.rb +++ /dev/null @@ -1,305 +0,0 @@ -# encoding: utf-8 -=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) 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: - - - * Git - - - - * Ralph Amissah - - - - ** Description: extract and print an XML rendition of document structure to screen - -=end -module SiSU_XML_Fictionbook - require_relative 'dal' # dal.rb - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'shared_txt' # shared_txt.rb - include SiSU_TextUtils - require_relative 'shared_xml' # shared_xml.rb - include SiSU_XML_Munge - include SiSU_Param - class Source - def initialize(opt) - @opt=opt - @sp=' ' - end - def read - begin - @md=SiSU_Param::Parameters.new(@opt).get - @dal_array=SiSU_DAL::Source.new(@opt).get - SiSU_XML_Fictionbook::Source::Scroll.new(@dal_array,@md).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class Scroll #{@md.date.available} Initial version

    " - else '' - end - date_modified=if defined? @md.date.modified; "\n

    #{@md.date.modified} Last Modified

    " - else '' - end - head=< - - - - *** - - *** - *** - *** - - #{@md.title.full} - - - yyyy - - - - - - - - #{version[:project]} #{version[:version]} and #{rb_ver} - #{version[:date]} - - 1.0 - #{date_available}#{date_modified} - - - - -WOK - put(head) - end - def extract_endnotes - @endnotes=[] - @data.each do |para| - @endnotes << para.scan(/~\{(.+?)\}~/m) - end - @endnotes=@endnotes.flatten - end - def endnotes - @endnotes.each do |endnote| - endnote=endnote.strip - endnote=@trans.markup_fictionbook(endnote) - endnote="

    #{endnote}

    " - util=SiSU_TextUtils::Wrap.new(endnote,80,10) - endnote=util.line_wrap - put(endnote) - end - end - def tail - tail=< -
    -WOK - put(tail) - end - def markup(para,type='') - para=para.strip - para=@trans.markup_fictionbook(para) - para=if type.empty?; "

    #{para}

    " - else "<#{type}>

    #{para}

    " - end - util=SiSU_TextUtils::Wrap.new(para,80,10) - util.line_wrap - end - def put(line) - @file_fictionbook.puts line - puts line if @md.opt.act[:verbose_plus][:set]==:on - end - def structure_build_tag_close(lev,h) - @sp=' ' - case h[0] - when 1 - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 2 - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 3 - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 4 - put("#{@sp*4}") if (lev <= 4) - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 5 - put("#{@sp*5}") if (lev <= 5) - put("#{@sp*4}") if (lev <= 4) - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 6 - put("#{@sp*6}") if (lev <= 6) - put("#{@sp*5}") if (lev <= 5) - put("#{@sp*4}") if (lev <= 4) - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - end - end - def structure_build(ds) - @h=[0,false,false,false] - put("<#{@s[0]}>") - ds.each_with_index do |x,i| - @ef=false - case x[:lev] - when /^1/ - structure_build_tag_close(1,@h) - y="#{@sp*1}<#{@s[1]}>\n#{x[:para]}" - @h=[1,true,false,false] - when /^2/ - structure_build_tag_close(2,@h) - y="#{@sp*2}<#{@s[2]}>\n#{x[:para]}" - @h=[2,true,true,false] - when /^0:0/ #endnotes and metadata - structure_build_tag_close(2,@h) - y="#{@sp*2}<#{@s[2]}>\n#{x[:para]}" - @h=[2,true,true,false] - @ef=true if x[:hdr] =~/u0/ - when /^3/ - structure_build_tag_close(3,@h) - y="#{@sp*3}<#{@s[3]}>\n#{x[:para]}" - @h=[3,true,true,true] - when /^4/ - structure_build_tag_close(4,@h) - y="#{@sp*4}<#{@s[4]}>\n#{x[:para]}" - @h[0]=4 - when /^m2/ #metadata - structure_build_tag_close(4,@h) - y="#{@sp*4}<#{@s[4]}>\n#{x[:para]}" - @h[0]=4 - when /^5/ - structure_build_tag_close(5,@h) - y="#{@sp*5}<#{@s[5]}>\n#{x[:para]}" - @h[0]=5 - when /^6/ - structure_build_tag_close(6,@h) - y="#{@sp*6}<#{@s[6]}>\n#{x[:para]}" - @h[0]=6 - else - y=if @md.opt.act[:verbose_plus][:set]==:on; "#{x[:para]}" - else nil - end - end - put(y) if y - endnotes if @ef - end - structure_build_tag_close(0,@h) - end - def structure - data=@data - @ds=[] - c=0 - data.each do |para| - rgx_headers=/#{Mx[:id_o]}~(\d+);((?:\w|[0-6]:)\d+);(\w\d+)#{Mx[:id_c]}/ #fix - if para =~rgx_headers - x=(rgx_headers).match(para) - if x[3] =~/^[hum]\d+/ - @ds[c]={} - @ds[c][:ocn]=x[1] - @ds[c][:lev]=x[2] - @ds[c][:hdr]=x[3] - @ds[c][:para]=markup(para,'title') - else - @ds[c]={} - @ds[c][:para]=markup(para) if @md.opt.act[:verbose_plus][:set]==:on - end - c+=1 - end - end - structure_build(@ds) - @ds - end - end - end -end -__END__ diff --git a/lib/sisu/v5/xml_odf_odt.rb b/lib/sisu/v5/xml_odf_odt.rb new file mode 100644 index 00000000..e7389110 --- /dev/null +++ b/lib/sisu/v5/xml_odf_odt.rb @@ -0,0 +1,820 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: opendocument text generation + +=end +module SiSU_XML_ODF_ODT + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + include SiSU_Viz + require_relative 'xml_odf_odt_format' # xml_odf_odt_format.rb + include SiSU_XML_ODF_ODT_Format + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + class Source + require 'zlib' + require 'find' + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + @@endnotes_para=[] + end + def read + begin + @md,@env,@ao_array=@particulars.md,@particulars.env,@particulars.ao_array + unless @opt.act[:quiet][:set]==:on + tool=(@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? "#{@env.program.odf_viewer} file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Opendocument (ODF:ODT)',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Opendocument (ODF:ODT)',tool).green_title_hi + if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}").flow + end + end + SiSU_XML_ODF_ODT::Source::Scroll.new(@particulars).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within odf, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}/ + fix=n.split(/#{Mx[:br_line]}/) #watch #added + fix.each do |x| + if x =~/\S+/ then @n << x + end + end + else @n << n + end + end + end + def odf_book_idx + if @md.book_idx + idx_arr,idx_raw=[],SiSU_Particulars::CombinedSingleton.instance.get_idx_raw(@md.opt).raw_idx + idx_raw.each do |x| + x=if x.is_a?(String) + SiSU_XML_ODF_ODT_Format::FormatBookIndex.new(x).book_idx_bookmark + else nil + end + idx_arr << x.strip if x.is_a?(String) + end + @@odf[:book_idx]=idx_arr.join + end + end + def odf_metadata + @@odf[:metadata]=SiSU_Metadata::Summary.new(@md).odf.metadata + end + def odf_tail + manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" + @@odf[:tail] << %{Available document outputs:
    <#{manifest}>
    } + @@odf[:tail] << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} + @@odf[:tail] << "\n" + end + def set_bookmark_tag(dob) + SiSU_XML_ODF_ODT_Format::Tags.new.set_bookmark_tag(dob) + end + def heading(dob,p_num) + dob=footnote(dob) + m=/#{$1}/ + breakpage='' + if @md.fns \ + and @md.fns != '' \ + and @md.fns !=@@fns + @@docstart=true + @@fns=@md.fns + end + unless @@docstart + breakpage=if (@md.pagenew || @md.pagebreak) \ + and (@md.pagenew =~m or @md.pagebreak =~m) + ' ' + elsif @md.pageline \ + and @md.pageline =~m #fix + else '' + end + end + @@docstart=false + dob.tmp=dob.obj + dob.obj=%{#{breakpage}#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + dob + end + def toc(dob,p_num) + hardspace=(dob.lv =~/[A-C]/i) \ + ? '' + : '' + toc_heading=dob.ocn \ + ? %{#{dob.tmp}} + : dob.tmp + dob.obj=%{#{toc_heading}#{hardspace}} + dob + end + def image_src(i) + if @md.fns =~/\.ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_include}/#{i}") #review + @env.path.image_source_include + elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ + pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] + img_src=pt + '/image' + if FileTest.file?("#{img_src}/#{i}") + img_src + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"ERROR - image:",%{"#{i}" missing},"search locations: #{@env.path.image_source_include_local},#{@env.path.image_source_include_remote} and #{@env.path.image_source_include}").error2 unless @md.opt.act[:quiet][:set]==:on + nil + end + elsif @md.fns =~/\.ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_include_local}/#{i}") #review + @env.path.image_source_include_local + elsif @md.fns =~/\.ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_sisu_includes}/#{i}") + @env.path.image_source_sisu_includes + elsif @md.fns =~/\.-ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_include_remote}/#{i}") + @env.path.image_source_include_remote + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"ERROR - image:",%{"#{i}" missing},"search locations: #{@env.path.image_source_include_local},#{@env.path.image_source_include_remote} and #{@env.path.image_source_include}").error2 unless @md.opt.act[:quiet][:set]==:on + nil + end + end + def image_odf(img) + # copy image to od image directory (unless exists) + # divide pixel dimension by 37.79485 and retain 3 decimal places + m=img[1] + i=/^(\S+?\.(?:png|jpg|gif))/.match(m).captures.join if m =~/^(\S+?\.(?:png|jpg|gif))/ + c=/^\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"/.match(m).captures.join if m =~/^\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"/ + w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\d+x\d+/ + w=(w.to_i/37.79485).to_s + h=(h.to_i/37.79485).to_s + h=/([0-9]+\.\d{0,3})/.match(h).captures.join + w=/([0-9]+\.\d{0,3})/.match(w).captures.join + image_source=image_src(i) + if image_source + if FileTest.file?("#{image_source}/#{i}") + FileUtils::cp("#{image_source}/#{i}","#{@env.processing_path.odt}/Pictures/#{i}") + else STDERR.puts %{\t*WARN* did not find image - "#{image_source}/#{i}" [#{__FILE__}:#{__LINE__}]} + end + end + img=if i.to_s =~/jpg|png|gif/ \ + and h.to_s =~/\d/ \ + and w.to_s =~/\d/ + @@img_count +=1 + %{#{c}} #anchor-type: as-char or paragraph or char or ... + else %{[image omitted]} + end + end + def image(dob) + m=if dob.obj =~/#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + dob.obj.scan(/(#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) + elsif dob.obj =~/#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}image/ + dob.obj.scan(/(#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}(image))/) + else nil + end + if m then m.each do |i| + cont,url=i[1],i[2] + cont=cont.gsub(/([)(\]\[])/,"\\\\\\1"). + gsub(/([+?])/,"\\\\\\1") # incorrect handling of + + url=url.gsub(/([+?])/,"\\\\\\1") + dob.obj=dob.obj.sub(/#{Mx[:lnk_o]}[ ]*#{cont}[ ]*#{Mx[:lnk_c]}image/m,image_odf(i)). + sub(/#{Mx[:lnk_o]}[ ]*#{cont}[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}#{url}#{Mx[:url_c]}/m,image_odf(i)). + sub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def text_link_odf(txt,url,trail) + txt=txt.gsub(/(\\\+)/,'+') #this is convoluted, and risky :-( + url=url.gsub(/(\\\+)/,'+') #this is convoluted, and risky :-( + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map + t=case url + when /^https?:/ + %{#{txt.strip}#{trail}} + when /^:/ # site same document collection html link + url=url.gsub(/^:/,"#{@env.url.root}/") + %{#{txt.strip}#{trail}} + when /^\.\.\// # site same document collection html link + url=url.gsub(/^\.\.\//,"#{@env.url.root}/") + %{#{txt.strip}#{trail}} + else # document internal link + if map_nametags[url] \ + and map_nametags[url][:segname] + else p "NOT FOUND name_tags: #{url}" + end + t=map_nametags[url] \ + && map_nametags[url][:segname] \ + ? %{#{txt.strip}#{trail}} + : %{#{txt.strip}#{trail}} + end + t + end + def text_link_odf_bookmark(txt,url,trail) + SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map + %{#{txt.strip}#{trail}} + end + def text_link(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt=txt.gsub(/([)(\]\[])/,"\\\\\\1"). + gsub(/([+?*])/,"\\\\\\1") # problems with + + url=url.gsub(/([+?])/,"\\\\\\1") # problems with + + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:url_o]}#{url}#{Mx[:url_c]}/m,text_link_odf(txt,url,trail)). #make sure trailing ']' are not caught in url + gsub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def text_link_relative(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt=txt.gsub(/([)(\]\[])/,"\\\\\\1"). + gsub(/([+?*])/,"\\\\\\1") # problems with + + url=url.gsub(/([+?])/,"\\\\\\1") # problems with + + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m,text_link_odf_bookmark(txt,url,trail)). #make sure trailing ']' are not caught in url + gsub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def text_link_relative_(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt=txt.gsub(/([)(\]\[])/,"\\\\\\1") + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m,text_link_odf(txt,url,trail)). #make sure trailing ']' are not caught in url + gsub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def normal(dob,p_num) #P1 - P3 + dob=footnote(dob) + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + dob.obj= if dob.is==:para \ + and dob.indent.to_s =~/[0-9]/ \ + and dob.indent == dob.hang + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + elsif dob.is==:para \ + and dob.hang.to_s =~/[0-9]/ \ + and dob.indent != dob.hang + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + else %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + end + dob + end + def fontface(dob) + end + def footnote_urls(str) + str=str.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) + str=text_link(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + str=text_link_relative(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + str + end + def footnote(t_o) + str=if defined? t_o.obj then t_o.obj + elsif t_o.is_a?(String) then t_o + end + if str + @astx||=10000 + @astxs||=20000 + if str =~/#{Mx[:en_a_o]}\d+\s+/ + str=str.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/,'\1 \2') + end + if str =~/#{Mx[:en_a_o]}([*]+)\s+/ + a=$1.gsub(/([*])/,"\\\\\\1") + str=str.gsub(/#{Mx[:en_a_o]}([*]+)\s+(.+?)#{Mx[:en_a_c]}/,%{\\1 \\2}) + @astxs+=1 + end + if str=~/#{Mx[:en_a_o]}[*+]+\s/ + asterisk=str.scan(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/) + asterisk.each do |x| + a=x[0].gsub(/([*+])/,"\\\\\\1") + str=group_clean(str) + str=footnote_urls(str) + str=str.gsub(/#{Mx[:en_a_o]}(#{a})\s+(.+?)#{Mx[:en_a_c]}/,%{\\1 \\2}) + @astx+=1 + end + end + if str=~/#{Mx[:en_b_o]}[*+]\d+\s/ + asterisk=str.scan(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/) + asterisk.each do |x| + a=x[0].gsub(/([*+])/,"\\\\\\1") + str=group_clean(str) + str=footnote_urls(str) + str=str.gsub(/#{Mx[:en_b_o]}(#{a})\s+(.+?)#{Mx[:en_b_c]}/,%{\\1 \\2}) + @astx+=1 + end + end + end + if defined? t_o.obj then t_o.obj=str + elsif t_o.is_a?(String) then t_o=str + end + t_o + end + def group_clean(str) + str=str.gsub(/&nbsp;| |#{Mx[:nbsp]}/,' '). + gsub(//,'>'). + gsub(/<(text:span text:style-name="Span_\S+?"|\/text:span)>/,'<\1>'). #works, not ideal + gsub(/#{Mx[:br_line]}/,'
    '). + gsub(/<br(?:\s+\/)?>/,'
    ') + end + def poem(dob,p_num) #P4 #same as group + parray=[] + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=footnote(parablock) + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + dob + end + def group(dob,p_num) #P4 #same as verse + parray=[] + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=parablock.gsub(/<text:a xl:type="simple" xl:href="(.+?)">/m,''). + gsub(/<(\/text:a)>/,'<\1>'). + gsub(/<(text:note text:id=.+?)>/,'<\1>'). + gsub(/<(text:p text:style-name="Footnote")>/,'<\1>'). + gsub(/<(\/?text:(?:note-citation|note-body|note|p))>/,'<\1>') + parablock=footnote(parablock) + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + dob + end + def block(dob,p_num) #P4 #same as verse + parray=[] + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=parablock.gsub(/<text:a xl:type="simple" xl:href="(.+?)">/m,''). + gsub(/<(\/text:a)>/,'<\1>'). + gsub(/<(text:note text:id=.+?)>/,'<\1>'). + gsub(/<(text:p text:style-name="Footnote")>/,'<\1>'). + gsub(/<(\/?text:(?:note-citation|note-body|note|p))>/,'<\1>') + parablock=footnote(parablock) + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + dob + end + def code(dob,p_num) #P5 + if dob.is==:code + dob.obj=dob.obj.gsub(/\s\s/,'  ') + parray=[] + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=parablock.gsub(/^\s*$/,'
    '). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1') #http ftp matches escaped, no decoration + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + end + dob + end + def table(dob,p_num) # + if dob.is ==:table + dob=footnote(dob) #check + table=SiSU_XML_ODF_ODT_Format::Table.new(@md,dob,p_num) + dob=table.table + end + dob + end + def obj_break(dob) + if dob.is ==:break + br=SiSU_XML_ODF_ODT_Format::FormatObjBreak.new(@md,dob) + if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] + dob=br.br_page + elsif dob.obj==Mx[:br_page_line] + dob=br.br_page_line + elsif dob.obj==Mx[:br_obj] + dob=br.obj_sep + end + end + dob + end + def odf_structure(md,dob) + @md,@dob=md,dob + dob=if dob.is !=:code + dob=image(dob) if dob.obj =~/#{Mx[:lnk_o]}[ ]*\S+?\.(?:png|jpg|gif)\s.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + dob=text_link(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + dob=text_link_relative(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + dob + else dob + end + p_num={ display: '', set_ref: '' } + if dob.is !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + if @env.odt_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Fixnum) + p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(dob.ocn).set_bookmark_and_display + end + end + end + if dob.is==:heading + @@odf[:body] << heading(dob,p_num).obj << break_line*2 + if SiSU_Env::ProcessingSettings.new(md).build.toc? + if dob.lv =~/[A-C1]/i + @@odf[:toc] << toc(dob,p_num).obj + end + end + elsif dob.is ==:verse + @@odf[:body] << poem(dob,p_num).obj << break_line*2 + elsif dob.is==:group + @@odf[:body] << group(dob,p_num).obj << break_line*2 + elsif dob.is==:block + @@odf[:body] << block(dob,p_num).obj << break_line*2 + elsif dob.is==:code + @@odf[:body] << code(dob,p_num).obj << break_line*2 + elsif dob.is==:table #elsif dob.obj =~ /<\-_&!@%~#\]\[*=$| \n+`#{Mx[:tc_p]}]/u + dir=SiSU_Env::InfoEnv.new(@md.fns) + dir.path.odt_bld + @data_mod,@endnotes,@level,@cont,@copen,@odf_contents_close=Array.new(6){[]} + @rcdc=false + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @odf_contents_close[x]='' } + odf_tail #($1,$2) + bullet=image_src('bullet_09.png') + if bullet + if FileTest.file?("#{bullet}/bullet_09.png") + FileUtils::cp("#{bullet}/bullet_09.png","#{@env.processing_path.odt}/Pictures/.") + else STDERR.puts %{\t*WARN* did not find image - "#{bullet}/bullet_09.png" [#{__FILE__}:#{__LINE__}]} + end + end + odf_book_idx + odf_metadata + data.each do |dob| + #p dob.obj if dob.obj =~safe_characters and @md.opt.cmd =~/V/ #KEEP + dob.obj='' if dob.obj =~/#{Mx[:lv_o]}\d+:.*?#{Mx[:lv_c]}.+?#{Mx[:pa_non_object_dummy_heading]}/ #fix Mx[:lv_o] + para_array=[] + dob.obj=dob.obj.gsub(//,'>') + word=dob.obj.scan(/\S+|\n/) + if word + word.each do |w| # _ - / # | : ! ^ ~ + unless dob =~/^(?:#{Rx[:meta]}|%+ )/m + w=w.gsub(/&#(?:126|152);/,'~'). #126 usual + gsub(/ /,' ') + if w !~/(?:&\S{2,7}?;)+/ + w=w.gsub(/&/,'&') + end + if w !~/&\S{1,7}?;(?:&\S{1,7}?;)+/ #imperfect + w=w.gsub(/(&\S{1,7};)+&/,'\1&') + end + end + para_array << w + end + dob.obj=para_array.join(' ') + dob.obj=dob.obj.strip + end + if dob.is==:code #{Mx[:gr_o]}code#{Mx[:gr_c]}/ #fix #code-block: angle brackets special characters #fix + dob.obj=dob.obj.gsub(/(^|[^}])_(?:<|<)/m,'\1<').gsub(/(^|[^}])_(?:>|>)/m,'\1>'). + gsub(/(^|[^}])_(?:<|<)/m,'\1<').gsub(/(^|[^}])_(?:>|>)/m,'\1>') + end + if dob.of==:block + dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') + end + dob.obj=dob.obj.gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/,''). #check + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}[~-]##{Mx[:mk_c]}/,'') + if dob.is==:para \ + and dob.bullet_ + dob.obj=' ' + + dob.obj + end + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/,'
    '). + gsub(/©/,'©'). #too arbitrary + gsub(/.+?<-#>/,''). # remove dummy headings (used by html) #check + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + '\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + '\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + '\1'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + '\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + '\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + '\1'). + gsub(/­/u,'-'). + gsub(/ /u, ' '). # space identify + gsub(/ /u, ' '). # space identify + gsub(/·/u,'*'). + gsub(/[­–—]/u,'-'). #— – chk + gsub(/ < /i,'<'). + gsub(/\\copy(?:right)?\b/,'©'). + gsub(/\\trademark\b|\\tm\b/,'®'). + gsub(/\44/,'$'). #$ watch + gsub(/(.+?)<\/a>/,'\1'). + gsub(/#{Mx[:mk_o]}name#\S+?#{Mx[:mk_c]}/,'') # remove name links + wordlist=dob.obj.scan(/\S+/) + dob.obj=tidywords(wordlist).join(' ').strip + @rcdc=true if @rcdc==false \ + and (dob.obj =~/~metadata/ or dob =~/#{Mx[:lv_o]}1:meta#{Mx[:lv_x]}\s*Document Information/) #fix Mx[:lv_o] + if dob.is !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ #check + if defined? dob.ocn and dob.ocn =~/\d+/ + @p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(dob.ocn) + end + if dob.is ==:heading \ + || dob.is ==:para \ + || dob.is ==:group \ + || dob.is ==:verse \ + || dob.is ==:code \ + || dob.is ==:table \ + || dob.is ==:break + odf_structure(@md,dob) + end + if dob.obj ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/#{Mx[:tc_o]}.+?#{Mx[:tc_c]}/,' '). + gsub(/<:\S+>/,' ') + end + end + end + end + def pre + table=if @md.flag_tables + x=< + + + + + + + + + + + + + + + + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + else '' + end + x=< + + + +#{table} + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + @@odf[:head] << x + end + def publish + content=[] + br_pg=' ' + content << + @@odf[:head] << + @@odf[:toc] << + br_pg << + @@odf[:body] << + @@odf[:book_idx] << + br_pg << + @@odf[:metadata] << + @@odf[:tail] + SiSU_XML_ODF_ODT::Source::Output.new(content,@md,@env).odf + @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } + end + end + class Output . + + 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: opendocument formatting, default opendocument template + +=end +module SiSU_XML_ODF_ODT_Format + require_relative 'param' # param.rb + include SiSU_Param + include SiSU_Viz + class ParagraphNumber + def initialize(paranum) + @paranum=/(\d+)/m.match(paranum.to_s)[1] + end + def set_ref_and_display + set_ref=@paranum.gsub(/(\d+)/,' ') + disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) + { display: disp, set_ref: set_ref } + end + def set_bookmark_and_display + set_ref=@paranum.gsub(/(\d+)/,' ') + disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) + { display: disp, set_ref: set_ref } + end + def name + @paranum.gsub(/(\d+)/,'') + end + def goto + @paranum.gsub(/(\d+)/,'') + end + end + class FormatBookIndex + def initialize(idx_str) + @idx_str=idx_str + end + def book_idx_bookmark + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + rgx_bookmark=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m + while @idx_str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m + link,url=$1,$2 + link,url=link.strip,url.strip + @idx_str=@idx_str.gsub(/&/m,"&") + ocn_lnk=if map_nametags[url] \ + and map_nametags[url][:ocn] + map_nametags[url][:ocn] + else nil + end + ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk) + if ocn_lnk and not ocn_lnk.empty? + @idx_str=@idx_str.sub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + '\1'). + sub(rgx_bookmark, + %{#{link.strip}}) + else + puts %{name tag: "#{url}" not found} + @idx_str.sub!(rgx_bookmark,"#{link}") + end + end + @idx_str=@idx_str.gsub(/#{Xx[:protect]}/m,''). + sub(/,\s*$/m,''). + gsub(/\n/,'') + @idx_str='' + @idx_str + '' + end + end + class Tags + def set_bookmark_tag(dob) + tags='' + if dob.tags.length > 0 + dob.tags.each do |tag| + tags +=%{ } + end + end + tags + end + end + class FormatTextObject + def initialize(md,t_o) + @md,@t_o=md,t_o + if t_o.is_a?(Hash) + @txt =t_o[:txt] || nil + else + p t_o.class + p caller + end + rgx=/#{Mx[:en_a_o]}\d+\s+(.+?)#{Mx[:en_a_c]}/ + @txt=@txt.gsub(rgx,'\1') if @txt =~rgx + @vz=SiSU_Viz::Defaults.new + end + def scr_endnote_body + "#{@txt} " + end + def heading_body1 + end + def heading_body2 + end + def heading_body3 + end + def heading_body4 + end + def heading_body5 + end + def heading_body6 + end + end + class Table + @@tablehead,@@table_counter=0,0 #reinitialise on new file + @@tablefoot=[] #watch + @@fns='' + def initialize(md,dob,p_num) + @md,@dob,@p_num=md,dob,p_num + @txt=dob.obj + @vz=SiSU_Viz::Defaults.new + if @md.fns != @@fns + @@table_counter=0 + @@fns=@md.fns + end + end + def break_line + (@md.opt.act[:maintenance][:set]==:on) \ + ? "\n" : '' + end + def table_head_open(count) + type=(@dob.head_) \ + ? 1 + : 2 + alpha=case @dob.cols + when 1; 'A' + when 2; 'B' + when 3; 'C' + when 4; 'D' + when 5; 'E' + when 6; 'F' + when 7; 'G' + when 8; 'H' + when 9; 'I' + when 10; 'J' + when 11; 'K' + when 12; 'L' + when 13; 'M' + when 14; 'N' + else 'D' + end + tag=SiSU_XML_ODF_ODT_Format::Tags.new.set_bookmark_tag(@dob) + %{#{@p_num[:set_ref]}#{tag}#{break_line}} + + %{#{break_line}} + end + def table_close(tablefoot='') + '' \ + + %{#{@p_num[:display]}} + end + def table_tag_cell(str,i) + txt_name_cell=if i==0 \ + and @dob.head_ + 'Table_Heading' + else 'P_table_cell' + end + str=str.gsub(/^~$/,'') # tilde / empty cell + %{#{break_line}} + + %{#{break_line}} + + %{#{str}} + + %{#{break_line}} + + %{#{break_line}} + end + def table_tag_row(str,i) + %{#{break_line}} + + %{#{str}} + + %{#{break_line}} + end + def table_tag_row_dump(str,i) + txt_name_row=if i==0 \ + and @dob.head_ + 'Table_Heading' + else 'P_table_cell' + end + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} + + %{#{str}} + + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} + end + def table_row(row,i) + row='' if row =~/^/,1] + @@tablefoot << m if m + row=row.gsub(//,'') + @cells=[] + row.split(/\s*#{Mx[:tc_p]}/).each do |cell| + @cells << table_tag_cell(cell,i) + end + row=@cells.join + row=table_tag_row(row,i) + row + end + def table + @@table_counter+=1 + table_head_open(@@table_counter) + @table=[] + @dob.obj.split(/\s*#{Mx[:tc_c]}/).each_with_index do |r,i| + @table << table_row(r,i) + end + @dob.obj= table_head_open(@@table_counter) + @table.join + table_close + @dob + end + end + class ODT_Head_1_2 + def initialize(md) + @md=md + @generator="#{@md.sisu_version[:project]} #{@md.sisu_version[:version]} #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" + end + def manifest_rdf + x=< + + + + + + + + + + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def meta_inf_manifest_xml(md) + images=[' '] + if md.ec[:image].length > 0 + md.ec[:image].each do |i| + images<<< +WOK + end + end + images=images.join('') + x=< + + + + + #{images} + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def meta_xml + x=< + + + #{@generator} + #{@md.generated} + #{@md.generated} + en-US + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def settings_xml + x=< + + + + 0 + 0 + 0 + 0 + true + false + + + view2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + true + 100 + false + + + + + true + false + false + true + true + false + true + false + false + + false + false + false + true + true + 0 + false + false + false + false + true + false + false + false + false + true + true + false + false + true + false + true + false + high-resolution + 1 + 0 + true + + + false + true + + false + true + false + true + false + true + false + + true + true + false + true + true + true + false + false + + false + 0 + false + false + true + true + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def styles_xml + x=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def mimetype + x=<#{sep*60}
    } + @t_o + end + def obj_sep #center later + sep='--- ' + @t_o.obj=%{#{sep*20}} + @t_o + end + end + class XML + end +end +__END__ diff --git a/lib/sisu/v5/xml_sax.rb b/lib/sisu/v5/xml_sax.rb index a53abdd6..aa701822 100644 --- a/lib/sisu/v5/xml_sax.rb +++ b/lib/sisu/v5/xml_sax.rb @@ -66,7 +66,7 @@ module SiSU_XML_SAX include SiSU_Particulars require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format @@ -135,10 +135,10 @@ module SiSU_XML_SAX end end class Scroll - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb include SiSU_TextUtils require_relative 'css' # css.rb - require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml + require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml @@xml={ body: [], open: [], close: [], head: [] } def initialize(particulars) @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array diff --git a/lib/sisu/v5/xml_shared.rb b/lib/sisu/v5/xml_shared.rb new file mode 100644 index 00000000..caad8be0 --- /dev/null +++ b/lib/sisu/v5/xml_shared.rb @@ -0,0 +1,751 @@ +# encoding: utf-8 +=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, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) 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: + + + * Git + + + + * Ralph Amissah + + + + ** Description: common file for xml generation +=end +module SiSU_XML_Munge + class Trans + require_relative 'defaults' # defaults.rb + def initialize(md) + @md=md + @sys=SiSU_Env::SystemCall.new + @dir=SiSU_Env::InfoEnv.new(@md.fns) + @brace_url=SiSU_Viz::Defaults.new.url_decoration + if @md.sem_tag + @ab ||=semantic_tags.default + end + end + def semantic_tags + def default + { + pub: 'publication', + conv: 'convention', + vol: 'volume', + pg: 'page', + cty: 'city', + org: 'organization', + uni: 'university', + dept: 'department', + fac: 'faculty', + inst: 'institute', + co: 'company', + com: 'company', + conv: 'convention', + dt: 'date', + y: 'year', + m: 'month', + d: 'day', + ti: 'title', + au: 'author', + ed: 'editor', #editor? + v: 'version', #edition + n: 'name', + fn: 'firstname', + mn: 'middlename', + ln: 'lastname', + in: 'initials', + qt: 'quote', + ct: 'cite', + ref: 'reference', + ab: 'abreviation', + def: 'define', + desc: 'description', + trans: 'translate', + } + end + self + end + def char_enc #character encode + def utf8(dob='') + if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn + str=if defined? dob.obj then dob.obj + elsif dob.is_a?(String) then dob + end + if str + #¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûü + #¢£¥§©ª«®°±²³µ¶¹º»¼½¾×÷ + str=str.gsub(//um,'>'). # '>' # > + gsub(/¢/um,'¢'). # '¢' # ¢ + gsub(/£/um,'£'). # '£' # £ + gsub(/¥/um,'¥'). # '¥' # ¥ + gsub(/§/um,'§'). # '§' # § + gsub(/©/um,'©'). # '©' # © + gsub(/ª/um,'ª'). # 'ª' # ª + gsub(/«/um,'«'). # '«' # « + gsub(/®/um,'®'). # '®' # ® + gsub(/°/um,'°'). # '°' # ° + gsub(/±/um,'±'). # '±' # ± + gsub(/²/um,'²'). # '²' # ² + gsub(/³/um,'³'). # '³' # ³ + gsub(/µ/um,'µ'). # 'µ' # µ + gsub(/¶/um,'¶'). # '¶' # ¶ + gsub(/¹/um,'¹'). # '¹' # ¹ + gsub(/º/um,'º'). # 'º' # º + gsub(/»/um,'»'). # '»' # » + gsub(/¼/um,'¼'). # '¼' # ¼ + gsub(/½/um,'½'). # '½' # ½ + gsub(/¾/um,'¾'). # '¾' # ¾ + gsub(/×/um,'×'). # '×' # × + gsub(/÷/um,'÷'). # '÷' # ÷ + gsub(/¿/um,'¿'). # '¿' # ¿ + gsub(/À/um,'À'). # 'À' # À + gsub(/Á/um,'Á'). # 'Á' # Á + gsub(/Â/um,'Â'). # 'Â' #  + gsub(/Ã/um,'Ã'). # 'Ã' # à + gsub(/Ä/um,'Ä'). # 'Ä' # Ä + gsub(/Å/um,'Å'). # 'Å' # Å + gsub(/Æ/um,'Æ'). # 'Æ' # Æ + gsub(/Ç/um,'Ç'). # 'Ç' # Ç + gsub(/È/um,'È'). # 'È' # È + gsub(/É/um,'É'). # 'É' # É + gsub(/Ê/um,'Ê'). # 'Ê' # Ê + gsub(/Ë/um,'Ë'). # 'Ë' # Ë + gsub(/Ì/um,'Ì'). # 'Ì' # Ì + gsub(/Í/um,'Í'). # 'Í' # Í + gsub(/Î/um,'Î'). # 'Î' # Î + gsub(/Ï/um,'Ï'). # 'Ï' # Ï + gsub(/Ð/um,'Ð'). # 'Ð' # Ð + gsub(/Ñ/um,'Ñ'). # 'Ñ' # Ñ + gsub(/Ò/um,'Ò'). # 'Ò' # Ò + gsub(/Ó/um,'Ó'). # 'Ó' # Ó + gsub(/Ô/um,'Ô'). # 'Ô' # Ô + gsub(/Õ/um,'Õ'). # 'Õ' # Õ + gsub(/Ö/um,'Ö'). # 'Ö' # Ö + gsub(/Ø/um,'Ø'). # 'Ø' # Ø + gsub(/Ù/um,'Ù'). # 'Ù' # Ù + gsub(/Ú/um,'Ú'). # 'Ú' # Ú + gsub(/Û/um,'Û'). # 'Û' # Û + gsub(/Ü/um,'Ü'). # 'Ü' # Ü + gsub(/Ý/um,'Ý'). # 'Ý' # Ý + gsub(/Þ/um,'Þ'). # 'Þ' # Þ + gsub(/ß/um,'ß'). # 'ß' # ß + gsub(/à/um,'à'). # 'à' # à + gsub(/á/um,'á'). # 'á' # á + gsub(/â/um,'â'). # 'â' # â + gsub(/ã/um,'ã'). # 'ã' # ã + gsub(/ä/um,'ä'). # 'ä' # ä + gsub(/å/um,'å'). # 'å' # å + gsub(/æ/um,'æ'). # 'æ' # æ + gsub(/ç/um,'ç'). # 'ç' # ç + gsub(/è/um,'è'). # 'è' # è + gsub(/é/um,'é'). # '´' # é + gsub(/ê/um,'ê'). # 'ˆ' # ê + gsub(/ë/um,'ë'). # 'ë' # ë + gsub(/ì/um,'ì'). # 'ì' # ì + gsub(/í/um,'í'). # '´' # í + gsub(/î/um,'î'). # 'î' # î + gsub(/ï/um,'ï'). # 'ï' # ï + gsub(/ð/um,'ð'). # 'ð' # ð + gsub(/ñ/um,'ñ'). # 'ñ' # ñ + gsub(/ò/um,'ò'). # 'ò' # ò + gsub(/ó/um,'ó'). # 'ó' # ó + gsub(/ô/um,'ô'). # 'ô' # ô + gsub(/õ/um,'õ'). # 'õ' # õ + gsub(/ö/um,'ö'). # 'ö' # ö + gsub(/ø/um,'ø'). # 'ø' # ø + gsub(/ù/um,'ú'). # 'ù' # ú + gsub(/ú/um,'û'). # 'ú' # û + gsub(/û/um,'ü'). # 'û' # ü + gsub(/ü/um,'ý'). # 'ü' # ý + gsub(/þ/um,'þ'). # 'þ' # þ + gsub(/ÿ/um,'ÿ'). # 'ÿ' # ÿ + gsub(/‘/um,'‘'). # '‘' # ‘ + gsub(/’/um,'’'). # '’' # ’ + gsub(/“/um,'“'). # “ # “ + gsub(/”/um,'”'). # ” # ” + gsub(/–/um,'–'). # – # – + gsub(/—/um,'—'). # — # — + gsub(/∝/um,'∝'). # ∝ # ∝ + gsub(/∞/um,'∞'). # ∞ # ∞ + gsub(/™/um,'™'). # ™ # ™ + gsub(/✠/um,'✠'). # ✗ # ✠ + gsub(/ /um,' '). # space identify + gsub(/ /um,' ') # space identify + end + dob=if defined? dob.obj + dob.obj=str + dob + elsif dob.is_a?(String) + str + end + dob + end + end + def html(dob='') + if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn + dob.obj=dob.obj.gsub(/ /u,' '). # space identify + gsub(/ /u,' ') # space identify + else + dob.obj=dob.obj.gsub(/¢/u,'¢'). # ¢ + gsub(/£/u,'£'). # £ + gsub(/¥/u,'¥'). # ¥ + gsub(/§/u,'§'). # § + gsub(/©/u,'©'). # © + gsub(/ª/u,'ª'). # ª + gsub(/«/u,'«'). # « + gsub(/®/u,'®'). # ® + gsub(/°/u,'°'). # ° + gsub(/±/u,'±'). # ± + gsub(/²/u,'²'). # ² + gsub(/³/u,'³'). # ³ + gsub(/µ/u,'µ'). # µ + gsub(/¶/u,'¶'). # ¶ + gsub(/¹/u,'¹'). # ¹ + gsub(/º/u,'º'). # º + gsub(/»/u,'»'). # » + gsub(/¼/u,'¼'). # ¼ + gsub(/½/u,'½'). # ½ + gsub(/¾/u,'¾'). # ¾ + gsub(/×/u,'×'). # × + gsub(/÷/u,'÷'). # ÷ + gsub(/¿/u,'¿'). # ¿ + gsub(/À/u,'À'). # À + gsub(/Á/u,'Á'). # Á + gsub(/Â/u,'Â'). #  + gsub(/Ã/u,'Ã'). # à + gsub(/Ä/u,'Ä'). # Ä + gsub(/Å/u,'Å'). # Å + gsub(/Æ/u,'Æ'). # Æ + gsub(/Ç/u,'Ç'). # Ç + gsub(/È/u,'È'). # È + gsub(/É/u,'É'). # É + gsub(/Ê/u,'Ê'). # Ê + gsub(/Ë/u,'Ë'). # Ë + gsub(/Ì/u,'Ì'). # Ì + gsub(/Í/u,'Í'). # Í + gsub(/Î/u,'Î'). # Î + gsub(/Ï/u,'Ï'). # Ï + gsub(/Ð/u,'Ð'). # Ð + gsub(/Ñ/u,'Ñ'). # Ñ + gsub(/Ò/u,'Ò'). # Ò + gsub(/Ó/u,'Ó'). # Ó + gsub(/Ô/u,'Ô'). # Ô + gsub(/Õ/u,'Õ'). # Õ + gsub(/Ö/u,'Ö'). # Ö + gsub(/Ø/u,'Ø'). # Ø + gsub(/Ù/u,'Ù'). # Ù + gsub(/Ú/u,'Ú'). # Ú + gsub(/Û/u,'Û'). # Û + gsub(/Ü/u,'Ü'). # Ü + gsub(/Ý/u,'Ý'). # Ý + gsub(/Þ/u,'Þ'). # Þ + gsub(/ß/u,'ß'). # ß + gsub(/à/u,'à'). # à + gsub(/á/u,'á'). # á + gsub(/â/u,'â'). # â + gsub(/ã/u,'ã'). # ã + gsub(/ä/u,'ä'). # ä + gsub(/å/u,'å'). # å + gsub(/æ/u,'æ'). # æ + gsub(/ç/u,'ç'). # ç + gsub(/è/u,'è'). # è + gsub(/é/u,'´'). # é + gsub(/ê/u,'ˆ'). # ê + gsub(/ë/u,'ë'). # ë + gsub(/ì/u,'ì'). # ì + gsub(/í/u,'´'). # í + gsub(/î/u,'î'). # î + gsub(/ï/u,'ï'). # ï + gsub(/ð/u,'ð'). # ð + gsub(/ñ/u,'ñ'). # ñ + gsub(/ò/u,'ò'). # ò + gsub(/ó/u,'ó'). # ó + gsub(/ô/u,'ô'). # ô + gsub(/õ/u,'õ'). # õ + gsub(/ö/u,'ö'). # ö + gsub(/ø/u,'ø'). # ø + gsub(/ù/u,'ù'). # ú + gsub(/ú/u,'ú'). # û + gsub(/û/u,'û'). # ü + gsub(/ü/u,'ü'). # ý + gsub(/þ/u,'þ'). # þ + gsub(/ÿ/u,'ÿ'). # ÿ + gsub(/‘/u,'&#lsquo;'). # ‘ # ‘ + gsub(/’/u,'&#rsquo;'). # ’ # ’ + gsub(/“/u,'“'). # “ # “ + gsub(/”/u,'”'). # ” # ” + gsub(/–/u,'–'). # – # – + gsub(/—/u,'—'). # — # — + gsub(/∝/u,'∝'). # ∝ # ∝ + gsub(/∞/u,'∞'). # ∞ # ∞ + gsub(/™/u,'™'). # ™ # ™ + gsub(/✠/u,'✠'). # ✠ + #gsub(/✠/u '†'). # † # † incorrect replacement † + gsub(/ /u,' '). # space identify + gsub(/ /u,' ') # space identify + end + end + self + end + def tidywords(wordlist) + wordlist_new=[] + wordlist.each do |x| + #imperfect solution will not catch all possible cases + x=x.gsub(/&/,'&') unless x =~/&\S+;/ + x=x.gsub(/&([A-Z])/,'&\1') + wordlist_new << x + end + wordlist_new + end + def markup(dob='') + wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 + dob.obj=tidywords(wordlist).join(' ').strip + unless dob.is==:table + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/u,'
    '). + gsub(/#{Mx[:br_paragraph]}/u,'
    '). + gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') + end + dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/(^|#{Mx[:gl_c]}|\s+)<\s+/,'\1< ').gsub(/\s+>(\s+|$)/,' >\1'). + #gsub(/#{Mx[:fa_emphasis_o]}(.+?)#{Mx[:fa_emphasis_c]}/,'\1'). #reinstate + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/m,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/m,'\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). + gsub(/<:pb>\s*/,''). #Fix + gsub(/<+[-~]#>+/,'') + if dob.is !=:code + #embeds a red-bullet image --> + dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1') + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table + dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*/,''). + gsub(/#{Mx[:br_page_new]}\s*/,''). + gsub(/#{Mx[:br_page_line]}\s*/,''). + gsub(/#{Mx[:pa_non_object_no_heading]}|#{Mx[:pa_non_object_dummy_heading]}/,''). + gsub(/<[-~]#>/,''). + gsub(/href="#{Xx[:segment]}/m,'href="'). + gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/, + '\1'). + gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/, + '\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/, + '\1'). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{[\\1] \\4}). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{\\1}). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}image/, + %{[\\1] \\4}). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}image/, + %{\\1}). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + '\1'). #watch, compare html_tune + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1') #escaped urls not linked, deal with later + else + dob.obj=dob.obj.gsub(//m,'>') + end + if dob.of==:block + dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Dx[:url_o]}/,"#{Dx[:url_o_xml]}"). + gsub(/#{Dx[:url_c]}/,"#{Dx[:url_c_xml]}"). + gsub(/ |#{Mx[:nbsp]}/m,' ') + dob + end + def markup_light(dob='') + dob.obj=dob.obj.gsub(/\/\{(.+?)\}\//,'\1'). + gsub(/[*!]\{(.+?)\}[*!]/,'\1'). + gsub(/_\{(.+?)\}_/,'\1'). + gsub(/-\{(.+?)\}-/,'\1'). + gsub(//,'
    '). + gsub(/<:pb>\s*/,''). + gsub(/<[-~]#>/,''). + gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort + gsub(/&([^;]{1,5})/,'&\1'). #sort, rough estimate, revisit #WATCH found in node not sax + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/, + "#{@md.file.output_path.xml.rel_image}\/\\1"). + gsub(/ |#{Mx[:nbsp]}/,' ') + wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 + dob.obj=tidywords(wordlist).join(' ').strip + dob + end + def clean(str) + str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;') + end + def markup_fictionbook(str='',is='') + str=str.gsub(/#{Mx[:en_a_o]}([\d+*]+).+?#{Mx[:en_a_c]}/m,'
    [\1]'). + gsub(/&/,'&'). #sort + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + str=str.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless is==:table + str=str.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,''). + gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,'●  '). + gsub(/#{Mx[:nbsp]}/,' '). + gsub(/<(p|br)>/,'<\1 />') + clean(str) + end + def markup_docbook(dob='') # work on, initially a copy of fictionbook! + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m,'\1'). + gsub(/&/,'&'). #sort + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table + dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,'●  '). + gsub(/#{Mx[:nbsp]}/,' '). + gsub(/<(p|br)>/,'<\1 />') + dob.obj=clean(dob.obj) + dob + end + def markup_group(dob='') + dob.obj=dob.obj.gsub(//,'>'). + gsub(/<:?br(?:\s+\/)?>/,'
    '). + gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). + gsub(/<(\/link)>/,'<\1>'). + gsub(/<(\/?en)>/,'<\1>') + dob + end + def markup_block(dob='') + dob.obj=dob.obj.gsub(//,'>'). + gsub(/<:?br(?:\s+\/)?>/,'
    '). + gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). + gsub(/<(\/link)>/,'<\1>'). + gsub(/<(\/?en)>/,'<\1>') + dob + end + def xml_sem_block_paired(matched) # colon depth: many, recurs + matched=matched.gsub(/\b(au):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(vol):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(pub):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(ref):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(desc):\{(.+?)\}:\1\b/m,%{\\2}). + gsub(/\b(conv):\{(.+?)\}:\1\b/m,%{\\2}). + gsub(/\b(ct):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(cty):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(org):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(dt):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(n):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m,'\2') + end + def xml_semantic_tags(dob) + if @md.sem_tag + dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } + dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } + dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } + dob.obj=dob.obj.gsub(/:\{(.+?)\}:au\b/m, %{\\1}). + gsub(/:\{(.+?)\}:n\b/m, %{\\1}). + gsub(/:\{(.+?)\}:ti\b/m, %{\\1}). + gsub(/:\{(.+?)\}:ref\b/m, %{\\1}). + gsub(/:\{(.+?)\}:desc\b/m, %{\\1}). + gsub(/:\{(.+?)\}:cty\b/m, %{\\1}). + gsub(/:\{(.+?)\}:org\b/m, %{\\1}). + gsub(/:\{(.+?)\}:([a-z]+(?:[_:.][a-z]+)*)/m,'\1'). + gsub(/;\{([^}]+(?![;]))\};ti\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};qt\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ref\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ed\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};v\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};desc\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};def\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};trans\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};y\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ab\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};pg\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};fn?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};mn?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ln?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};in\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};uni\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};fac\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};inst\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};dept\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};org\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};com?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};cty\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};([a-z]+(?:[_:.][a-z]+)*)/m,'\1') + end + dob + end + end +end +module SiSU_XML_Tags #Format + require_relative 'param' # param.rb + include SiSU_Param + include SiSU_Viz + class RDF + def initialize(md='',seg_name=[],tracker=0) + @full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords='' + @md=md + @rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n} + if defined? @md.title.full \ + and @md.title.full # DublinCore 1 - title + @rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n} + @full_title=%{ \n} + end + if defined? @md.creator.author \ + and @md.creator.author=~/\S+/ # DublinCore 2 - creator/author (author) + @rdf_author=%{ dc.author="#{@md.creator.author}"\n} + content=meta_content_clean(@md.creator.author) + @author=%{ \n} + end + if defined? @md.publisher \ + and @md.publisher # DublinCore 5 - publisher (current copy published by) + @rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n} + content=meta_content_clean(@md.publisher) + @publisher=%{ \n} + end + if defined? @md.creator.contributor \ + and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor + @rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n} + content=meta_content_clean(@md.creator.contributor) + @contributor=%{ \n} + end + if defined? @md.date.published \ + and @md.date.published=~/\S+/ # DublinCore 7 - date year-mm-dd + @rdf_date=%{ dc.date="#{@md.date.published}"\n} + @date=%{ \n} # fix @md.date_scheme + end + if defined? @md.date.created \ + and @md.date.created=~/\S+/ # DublinCore 7 - date.created year-mm-dd + @rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n} + @date_created=%{ \n} + end + if defined? @md.date.issued \ + and @md.date.issued=~/\S+/ # DublinCore 7 - date.issued year-mm-dd + @rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n} + @date_issued=%{ \n} + end + if defined? @md.date.available \ + and @md.date.available=~/\S+/ # DublinCore 7 - date.available year-mm-dd + @rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n} + @date_available=%{ \n} + end + if defined? @md.date.valid \ + and @md.date.valid=~/\S+/ # DublinCore 7 - date.valid year-mm-dd + @rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n} + @date_valid=%{ \n} + end + if defined? @md.date.modified \ + and @md.date.modified=~/\S+/ # DublinCore 7 - date.modified year-mm-dd + @rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n} + @date_modified=%{ \n} + end + if defined? @md.rights.all \ + and @md.rights.all # DublinCore 15 - rights + @rdf_rights=%{ dc.rights="#{@md.rights.all}"\n} + content=meta_content_clean(@md.rights.all) + @rights=%{ \n} + end + if defined? @md.classify.subject \ + and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???) + @rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n} + content=meta_content_clean(@md.classify.subject) + @subject=%{ \n} + end + if defined? @md.notes.description \ + and @md.notes.description=~/\S+/ # DublinCore 4 - description + @rdf_description=%{ dc.description="#{@md.notes.description}"\n} + content=meta_content_clean(@md.notes.description) + @description=%{ \n} + end + if defined? @md.notes.coverage \ + and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage + @rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n} + content=meta_content_clean(@md.notes.coverage) + @coverage=%{ \n} + end + if defined? @md.notes.relation \ + and @md.notes.relation=~/\S+/ # DublinCore 13 - relation + @rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n} + content=meta_content_clean(@md.notes.relation) + @relation=%{ \n} + end + if defined? @md.notes.type \ + and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc) + @rdf_type=%{ dc.type="#{@md.notes.type}"\n} + content=meta_content_clean(@md.notes.type) + @type=%{ \n} + end + if defined? @md.notes.format \ + and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type) + @rdf_format=%{ dc.format="#{@md.notes.format}"\n} + content=meta_content_clean(@md.notes.format) + @format=%{ \n} + end + #if defined? @md.identifier.sisupod \ + #and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free) + # @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n} + # content=meta_content_clean(@md.identifier.sisupod) + # @identifier=%{ \n} + #end + if defined? @md.original.source \ + and @md.original.source=~/\S+/ # DublinCore 11 - source (document source) + @rdf_source=%{ dc.source="#{@md.original.source}"\n} + content=meta_content_clean(@md.original.source) + @source=%{ \n} + end + if defined? @md.title.language \ + and @md.title.language=~/\S+/ # DublinCore 12 - language (English) + @rdf_language=%{ dc.language="#{@md.title.language}"\n} + @language=%{ \n} + end + if defined? @md.original.language \ + and @md.original.language=~/\S+/ + @rdf_language_original=%{ dc.language="#{@md.original.language}"\n} + @language_original=%{ \n} + end + content=meta_content_clean(@md.keywords) + @keywords=%{ \n} if @md.keywords + @vz=SiSU_Viz::Defaults.new + end + def meta_content_clean(content='') + content=if not content.nil? + content=content.tr('"',"'") + content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content) + else content + end + end + def rdfseg #segHead + rdftoc + end + def comment_xml(extra='') + generator="Generated by: #{@md.sisu_version[:project]} #{@md.sisu_version[:version]} of #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" if @md.sisu_version[:version] + lastdone="Last Generated on: #{Time.now}" + rubyv="Ruby version: #{@md.ruby_version}" + sc=if @md.sc_info + "Source file: #{@md.sc_filename} version: #{@md.sc_number} of: #{@md.sc_date}" + else '' + end + if extra.empty? +< +WOK + else +< +WOK + end + end + def comment_xml_sax + desc='SiSU XML, SAX type representation' + comment_xml(desc) + end + def comment_xml_node + desc='SiSU XML, Node type representation' + comment_xml(desc) + end + def comment_xml_dom + desc='SiSU XML, DOM type representation' + comment_xml(desc) + end + def metatag_html #values strung together, because some empty, and resulting output (line breaks) is much better +<