From 90051a7ea55acb043434b1c2483b878d602246ba Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 2 Apr 2021 19:37:00 -0400 Subject: org mode (ruby code within) --- org/xml.org | 5583 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 5583 insertions(+) create mode 100644 org/xml.org (limited to 'org/xml.org') diff --git a/org/xml.org b/org/xml.org new file mode 100644 index 00000000..68452bfa --- /dev/null +++ b/org/xml.org @@ -0,0 +1,5583 @@ +-*- mode: org -*- +#+TITLE: sisu xml including odf +#+DESCRIPTION: documents - structuring, various output representations & search +#+FILETAGS: :sisu:xml: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2021 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: content hideblocks hidestars noindent entitiespretty +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+PROPERTY: header-args :exports code +#+PROPERTY: header-args+ :noweb yes +#+PROPERTY: header-args+ :eval no +#+PROPERTY: header-args+ :results no +#+PROPERTY: header-args+ :cache no +#+PROPERTY: header-args+ :padline no + +* xml native +** xml_sax.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_sax.rb" +# <> +module SiSU_XML_SAX + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + require_relative 'xml_format' # xml_format.rb + include SiSU_XML_Format + require_relative 'xml_persist' # xml_persist.rb + require_relative 'rexml' # rexml.rb + include SiSU_Rexml + require_relative 'shared_metadata' # shared_metadata.rb + @@alt_id_count=0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env, @md, @ao_arr= + @particulars.env,@particulars.md,@particulars.ao_array + unless @opt.act[:quiet][:set]==:on + tool=if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + @env.program.web_browser \ + + ' file://' \ + + @md.file.output_path.xml_sax.dir + '/' \ + + @md.file.base_filename.xml_sax + "\n\t" \ + + @env.program.xml_viewer \ + + ' file://' \ + + @md.file.output_path.xml_sax.dir + '/' \ + + @md.file.base_filename.xml_sax + elsif @opt.act[:verbose][:set]==:on + @env.program.web_browser \ + + ' file://' \ + + @md.file.output_path.xml_sax.dir + '/' \ + + @md.file.base_filename.xml_sax + else "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + end + (@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], + 'XML SAX', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'XML SAX', + 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.xml_sax.dir + '/' \ + + @md.file.base_filename.xml_sax + ).flow + end + end + SiSU_XML_SAX::Source::Songsheet.new(@particulars).song + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + #file closed in songsheet + SiSU_Env::CreateSite.new(@opt).cp_css + Dir.chdir(@opt.f_pth[:pth]) + end + end + private + class Songsheet + def initialize(particulars) + @env, @md, @ao_arr, @particulars= + particulars.env,particulars.md,particulars.ao_array,particulars + @file=SiSU_Env::FileOp.new(@md) + end + def song + begin + SiSU_XML_SAX::Source::Scroll.new(@particulars).songsheet + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_XML_SAX::Source::Tidy.new(@md,@file.place_file.xml_sax.dir).xml # test wellformedness, comment out when not in use + end + SiSU_Rexml::Rexml.new(@md,@file.place_file.xml_sax.dir).xml if @md.opt.act[:maintenance][:set]==:on # test rexml parsing, comment out when not in use #debug + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + end + class Scroll + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'css' # css.rb + require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml + def initialize(particulars) + @env, @md, @ao_arr= + particulars.env,particulars.md,particulars.ao_array + @trans=SiSU_XML_Munge::Trans.new(@md) + @sys=SiSU_Env::SystemCall.new + @per=SiSU_XML_Persist::Persist.new + end + def songsheet + begin + pre + @data=markup(@ao_arr) + post + publish + ensure + SiSU_XML_Persist::Persist.new.persist_init + end + end + protected + def embedded_endnotes(dob='') + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1\2 '). + gsub(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/, + '\1\2 '). + gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1\2 ') + end + def extract_endnotes(dob='') + notes=dob.obj.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/) + notes.flatten.each do |e| + s=e.to_s + util=SiSU_TextUtils::Wrap.new(s,70) + wrap=util.line_wrap + wrap=wrap.gsub(/^(\d+)\s+(.+?)\s*\Z/m, < +#{Ax[:tab]*2}\\1 +#{Ax[:tab]*2} +#{Ax[:tab]*3}\\2 +#{Ax[:tab]*2} +#{Ax[:tab]*1} +WOK +). + gsub(/^([*+]\d+)\s+(.+?)\s*\Z/m, < +#{Ax[:tab]*2}\\1 +#{Ax[:tab]*2} +#{Ax[:tab]*3}\\2 +#{Ax[:tab]*2} +#{Ax[:tab]*1} +WOK +). + gsub(/^([*+]+)\s+(.+?)\s*\Z/m, < +#{Ax[:tab]*2}\\1 +#{Ax[:tab]*2} +#{Ax[:tab]*3}\\2 +#{Ax[:tab]*2} +#{Ax[:tab]*1} +WOK +) + @endnotes << wrap + end + end + def xml_head + metadata=SiSU_Metadata::Summary.new(@md).xml_sax.metadata + @per.head << metadata + end + def xml_sc(md='') + sc=if @md.sc_info + < + filename: + + #{@md.sc_filename} +
+ version number: + + #{@md.sc_number} +
+ version date: + + #{@md.sc_date} +
+ +WOK + else '' + end + @per.sc=sc + end + def xml_structure(dob,type='norm') + if dob.is==:heading + lv=dob.ln + dob.ln + 2 + else lv=nil + end + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean + #if defined? dob.obj + #t_ograph="#{dob.obj}" + util=SiSU_TextUtils::Wrap.new(dob.obj,70) + wrapped=util.line_wrap + #end + @per.body << if defined? dob.ocn; %{#{Ax[:tab]*0}} + else "#{Ax[:tab]*0}" + end + @per.body << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn + @per.body << if lv; %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} + else %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} # main text, contents, body KEEP + end + @per.body << @endnotes if @endnotes + ##@per.body << "#{Ax[:tab]*1}#{dob[@regx,2]}" if dob[@regx,2] # old unwrapped main text, contents, body KEEP + @per.body << "#{Ax[:tab]*0}" + @endnotes=[] + end + def block_structure(dob='') + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean + dob=@trans.markup_block(dob) + dob.obj=dob.obj.strip + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" + @per.body << @endnotes if @endnotes + @endnotes=[] + end + def group_structure(dob='') + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean + dob=@trans.markup_group(dob) + dob.obj=dob.obj.strip + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" + @per.body << @endnotes if @endnotes + @endnotes=[] + end + def poem_structure(dob='') + dob=@trans.markup_group(dob) + #dob.obj.gsub(/\s\s/,'  ') + dob.obj=dob.obj.strip + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*0}} + end + def code_structure(dob='') + dob=@trans.markup_group(dob) + dob.obj=dob.obj.gsub(/\s\s/,'  ').strip + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*1}} + @per.body << "#{Ax[:tab]*0}" + end + def table_structure(dob) + table=SiSU_XHTML_Shared::TableXHTML.new(dob) + @per.body << %{#{Ax[:tab]*0}} + @per.body << %{#{Ax[:tab]*1}#{dob.ocn}} + @per.body << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*2}#{table.table.obj}} + @per.body << %{#{Ax[:tab]*1}} + #@per.body << %{#{tab*1}} + @per.body << "#{Ax[:tab]*0}" + #@per.body << %{#{Ax[:tab]*0}} + #@per.body << %{#{Ax[:tab]*1}#{table}\n#{Ax[:tab]*1}} # unless lv # main text, contents, body KEEP + #@per.body << "#{Ax[:tab]*0}" + #@endnotes=[] + end + def markup(data) + xml_sc(@md) + @endnotes,@level,@cont,@copen,@xml_contents_close=[],[],[],[],[] + @rcdc=false + xml_head + (0..7).each { |x| @cont[x]=@level[x]=false } + (4..7).each { |x| @xml_contents_close[x]='' } + data.each do |dob| + @trans.char_enc.utf8(dob) if @sys.locale =~/utf-?8/i #% utf8 + dob=@trans.markup(dob) + if @rcdc==false \ + and (dob.is ==:meta \ + and dob.obj =~/Document Information/) + @rcdc=true + end + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + if defined? dob.ocn #look to move to format section + ocn=((dob.ocn.to_s =~/\d+/) ? dob.ocn : nil) + @p_num=SiSU_XML_Format::ParagraphNumber.new(@md,ocn) + end + if not @rcdc + if defined? dob.ocn \ + and dob.ocn.to_s =~/\d+/ + x=SiSU_XML_Format::FormatSeg.new(@md,dob) + if dob.is==:heading + xml_structure(dob) + dob.obj=case dob.ln + when 1 then x.heading_body1 + when 2 then x.heading_body2 + when 3 then x.heading_body3 + when 4 then x.heading_body4 + when 5 then x.heading_body5 + when 6 then x.heading_body6 + when 7 then x.heading_body7 + end + else + if dob.is==:verse + poem_structure(dob) + elsif dob.is==:group + group_structure(dob) + elsif dob.is==:block + block_structure(dob) + elsif dob.is==:code + code_structure(dob) + elsif dob.is==:table # FIX, check css, will need to modify + table_structure(dob) + elsif dob.is ==:para \ + and dob.indent.to_s =~/[1-9]/ \ + and dob.bullet_==true + xml_structure(dob,"indent_bullet#{dob.indent}") + elsif dob.is ==:para \ + and dob.indent.to_s =~/[1-9]/ \ + and dob.indent == dob.hang + xml_structure(dob,"indent#{dob.indent}") + elsif dob.is ==:para \ + and dob.hang.to_s =~/[0-9]/ \ + and dob.indent != dob.hang + xml_structure(dob,"hang#{dob.hang.to_s}_indent#{dob.indent.to_s}") + else xml_structure(dob) + end + end + elsif dob.obj =~/(#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + elsif dob.obj =~/MetaData/ + txt_obj={ txt: '
MetaData' } + format_scroll=FormatScroll.new(@md,txt_obj) + dob.obj=format_scroll.bold_para + elsif dob.obj =~/(Owner Details)/ +# txt_obj={ txt: '
Owner Details' } +# format_scroll=FormatScroll.new(@md,txt_obj) +# @per.owner_details=format_scroll.bold_para + dob.obj='' + end + if dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/ # -endnote + dob.obj='' + end + if dob.obj =~/.*<:#>.*$/ #investigate removal + dob.obj=if dob.obj =~ /#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/ + txt_obj={ txt: dob } + format_text=FormatTextObject.new(@md,txt_obj) + format_text.scr_inden_ocn_e_no_paranum + end + end + else # + end + dob.obj=dob.obj.gsub(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') if dob.obj + end + end + 7.downto(4) do |x| + y=x - 1; v=x - 3 + @per.body << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true + end + 3.downto(1) do |x| + y=x - 1 + @per.body << "#{Ax[:tab]*y}" if @level[x]==true + end + #7.downto(1) { |x| y=x - 1; @per.body << "#{Ax[:tab]*y}" if @level[x]==true } + end + def pre + rdf=SiSU_XML_Tags::RDF.new(@md) + @per.head,@per.body=[],[] + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_sax').stylesheet + encoding=if @sys.locale =~/utf-?8/i then '' + else '' + end + @per.open =< +WOK + @per.head << '' + @per.body << '' + end + def post + @per.head << @per.sc + @per.head << '' + @per.body << '' + @per.close = '' + end + def publish + content=[] + content << @per.open << @per.head << @per.body #<< @per.metadata + #content << @per.owner_details if @md.stmp =~/\w\w/ + content << @per.tail << @per.close + content=content.flatten.compact + Output.new(content,@md).xml + @@xml={} + end + end + class Output + def initialize(data,md) + @data,@md=data,md + @file=SiSU_Env::FileOp.new(@md) + end + def xml + SiSU_Env::FileOp.new(@md).mkdir + filename_xml=@file.write_file.xml_sax + @data.each do |str| + str=str.gsub(/\A\s+\Z/m,'') + filename_xml.puts str unless str.empty? + end + filename_xml.close + end + end + class Tidy + def initialize(md,file) + @md,@file=md,file + @prog=SiSU_Env::InfoProgram.new + end + def xml + if @prog.tidy !=false #note values can be other than true + if (@md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + unless @md.opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + 'invert', + 'Using XML Tidy', + 'check document structure' + ).colorize + tell=SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + 'invert', + '', + '' + ) + tell.grey_open + end + tidyfile='/dev/null' #don't want one or screen output, check for alternative flags + tidy=SiSU_Env::SystemCall.new(@file,tidyfile) + tidy.well_formed? + tell.p_off unless @md.opt.act[:quiet][:set]==:on + end + end + end + end + end +end +__END__ +#+END_SRC + +** xml_dom.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_dom.rb" +# <> +module SiSU_XML_DOM + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'ao' # ao.rb + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + require_relative 'xml_format' # xml_format.rb + include SiSU_XML_Format + require_relative 'xml_persist' # xml_persist.rb + require_relative 'rexml' # rexml.rb + include SiSU_Rexml + require_relative 'shared_metadata' # shared_metadata.rb + @@alt_id_count=0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env, @md, @ao_arr= + @particulars.env,@particulars.md,@particulars.ao_array + unless @opt.act[:quiet][:set]==:on + tool=if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + @env.program.web_browser \ + + ' file://' \ + + @md.file.output_path.xml_dom.dir + '/' \ + + @md.file.base_filename.xml_dom + "\n\t" \ + + @env.program.xml_viewer \ + + ' file://' \ + + @md.file.output_path.xml_dom.dir + '/' \ + + @md.file.base_filename.xml_dom + elsif @opt.act[:verbose][:set]==:on + @env.program.web_browser \ + + ' file://' \ + + @md.file.output_path.xml_dom.dir + '/' \ + + @md.file.base_filename.xml_dom + else "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + end + (@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], + 'XML DOM', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'XML DOM', + 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.xml_dom.dir + '/' \ + + @md.file.base_filename.xml_dom + ).flow + end + end + SiSU_XML_DOM::Source::Songsheet.new(@particulars).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + SiSU_Env::CreateSite.new(@opt).cp_css + Dir.chdir(@opt.f_pth[:pth]) + end + end + private + class Songsheet + def initialize(particulars) + @env, @md, @ao_arr, @particulars= + particulars.env,particulars.md,particulars.ao_array,particulars + @file=SiSU_Env::FileOp.new(@md) + end + def songsheet + begin + SiSU_XML_DOM::Source::Scroll.new(@particulars).songsheet + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_XML_DOM::Source::Tidy.new(@md,@file.place_file.xml_dom.dir).xml # test wellformedness, comment out when not in use + end + SiSU_Rexml::Rexml.new(@md,@file.place_file.xml_dom.dir).xml if @md.opt.act[:maintenance][:set]==:on # test rexml parsing, comment out when not in use #debug + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + end + class Scroll + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml + def initialize(particulars) + @env, @md, @ao_arr= + particulars.env,particulars.md,particulars.ao_array + @trans=SiSU_XML_Munge::Trans.new(@md) + @sys=SiSU_Env::SystemCall.new + @per=SiSU_XML_Persist::Persist.new + end + def songsheet + begin + pre + @data=markup(@ao_arr) + post + publish + ensure + SiSU_XML_Persist::Persist.new.persist_init + end + end + protected + def xml_markup(dob='') + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1\2 '). + gsub(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/, + '\1\2 '). + gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1\2 ') + end + def xml_head + metadata=SiSU_Metadata::Summary.new(@md).xml_dom.metadata + @per.head << metadata + end + def xml_sc(md='') + sc=if @md.sc_info + < + filename: + + #{@md.sc_filename} +
+ version number: + + #{@md.sc_number} +
+ version date: + + #{@md.sc_date} +
+ +WOK + else '' + end + @per.sc=sc + end + def xml_element(dob,xml_el='',xml_content='',type='norm') + n=n1=n2=n3=0 + if dob.is==:heading + lv=dob.ln + n=dob.ln + n1=dob.ln + n2=dob.ln + 2 + n3=dob.ln + 3 + else lv=nil + end + tag=if defined? dob.name and dob.name=~/\S+/ + "\n#{Ax[:tab]*n3}#{dob.name}" + else '' + end + xml_el ||='' + @per.body <<< +#{Ax[:tab]*n2} +#{Ax[:tab]*n3}#{dob.ocn}#{tag} +#{Ax[:tab]*n3}#{dob.obj} +#{Ax[:tab]*n2} +#{Ax[:tab]*n1}#{xml_content} +WOK + if lv==4 + @copen[1]=true + @copen[2]=@copen[3]=@copen[4]=false + elsif lv==5 + @copen[2]=true + @copen[3]=@copen[4]=false + elsif lv==6 + @copen[3]=true + @copen[4]=false + elsif lv==7 + @copen[4]=true + end + end + def xml_structure(dob,type='norm') + n=n1=n2=n3=0 + if dob.is==:heading + lv=dob.ln + n=dob.ln - 1 + n1=dob.ln + n2=dob.ln + 1 + n3=dob.ln + 2 + dob.ln - 3 + else lv=nil + end + case lv + when 1..3 + xml_el="" + 3.downto(lv) do |x| + y=x - 1 + if @cont[1] \ + or @cont[2] \ + or @cont[3] + @per.body << "#{Ax[:tab]*5}" + end + @cont[1]=false if @cont[1] + @cont[2]=false if @cont[2] + @cont[3]=false if @cont[3] + ####### attempt to close contents + if @copen[4] # 4~ + [4,3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } + @copen[1]=@copen[2]=@copen[3]=@copen[4]=false + elsif @copen[3] # 3~ + [3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } + @copen[1]=@copen[2]=@copen[3]=false + elsif @copen[2] # 2~ + [2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } + @copen[1]=@copen[2]=@copen[3]=false + elsif @copen[1] # 1~ + [1].each { |v| @per.body << "#{Ax[:tab]*n}" } + @copen[1]=@copen[2]=@copen[3]=false + end + @per.body << "#{Ax[:tab]*y}" if @level[x] + @level[x]=false + end + when 4..7 + 7.downto(lv) do |x| + if @level[x]==true + @xml_contents_close[x]='' + end + end + cv=lv - 3 + xml_el="" + xml_content="\n#{Ax[:tab]*5}" + case lv + when 4 + @per.body << "#{Ax[:tab]*5}" if @cont[1] + if @copen[4]==true # 4~ + [4,3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } + elsif @copen[3]==true # 3~ + [3,2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } + elsif @copen[2]==true # 2~ + [2,1].each { |v| @per.body << "#{Ax[:tab]*n}" } + elsif @copen[1]==true # 1~ + [1].each { |v| @per.body << "#{Ax[:tab]*n}" } + end + @cont[1]=true + when 5 + if @cont[3] \ + or @cont[2] \ + or @cont[1] + @per.body << "#{Ax[:tab]*5}" + end + if @copen[4]==true #4~ + [4,3,2].each { |v| @per.body << "#{Ax[:tab]*n}" } + elsif @copen[3]==true #3~ + [3,2].each { |v| @per.body << "#{Ax[:tab]*n}" } + elsif @copen[2]==true #2~ + [2].each { |v| @per.body << "#{Ax[:tab]*n}" } + end + @cont[2]=true + when 6 + if @cont[4] \ + or @cont[3] \ + or @cont[2] \ + or @cont[1] + @per.body << "#{Ax[:tab]*5}" + end + if @copen[4] #4~ + [4,3].each { |v| @per.body << "#{Ax[:tab]*n}" } + elsif @copen[3] #3~ + [3].each { |v| @per.body << "#{Ax[:tab]*n}" } + end + @cont[3]=true + when 7 + if @cont[4] \ + or @cont[3] \ + or @cont[2] \ + or @cont[1] + @per.body << "#{Ax[:tab]*5}" + end + if @copen[4] #4~ + [4].each { |v| @per.body << "#{Ax[:tab]*n}" } + end + @cont[4]=true + end + end + xml_el ||='' + xml_element(dob,xml_el,xml_content,type) + if lv + @level[lv]=true + ((lv+1)..7).each { |x| @level[x]=false } + end + end + def add_to_body(dob,type='norm') + if defined? dob.obj # main text, contents, body KEEP + if defined? dob.ocn \ + and dob.ocn + @per.body << %{#{Ax[:tab]*6}} + @per.body << %{#{Ax[:tab]*7}#{dob.ocn}} if defined? dob.ocn + end + #@per.body << %{#{Ax[:tab]*7}#{dob.obj}} + #@per.body << %{#{Ax[:tab]*7}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*7}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*8}#{dob.obj}#{Ax[:tab]*1}} + @per.body << %{#{Ax[:tab]*7}} + @per.body << %{#{Ax[:tab]*6}} + end + end + def block_structure(dob) + dob=@trans.markup_block(dob) #decide check & FIX + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/m, + '\1\2 ').strip + dob + end + def group_structure(dob) + dob=@trans.markup_group(dob) #decide check & FIX + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/m, + '\1\2 ').strip + dob + end + def poem_structure(dob) + dob=@trans.markup_group(dob) #decide check & FIX + dob.obj=dob.obj.strip + dob + end + def code_structure(dob) + dob=@trans.markup_group(dob) #decide check & FIX + dob.obj=dob.obj.gsub(/\s\s/,'  ').strip + dob + end + def table_structure(dob) #tables + SiSU_XHTML_Shared::TableXHTML.new(dob) + end + def markup(data) + xml_sc(@md) + @level,@cont,@copen,@xml_contents_close=[],[],[],[] + @rcdc=false + type='norm' + (0..7).each { |x| @cont[x]=@level[x]=false } + (4..7).each { |x| @xml_contents_close[x]='' } + xml_head + data.each do |dob| + @trans.char_enc.utf8(dob) if @sys.locale =~/utf-?8/i #% utf8 + dob=@trans.markup(dob) + if @rcdc==false \ + and (dob.is ==:meta \ + and dob.obj =~/Document Information/) + @rcdc=true + end + if dob !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + @p_num=SiSU_XML_Format::ParagraphNumber.new(@md,dob.ocn) if defined? dob.ocn + if not @rcdc + if defined? dob.ocn \ + and dob.ocn.to_s =~/\d+/ + format_scroll=SiSU_XML_Format::FormatScroll.new(@md,dob) if dob.is==:para and dob.indent ##FIX + x=SiSU_XML_Format::FormatSeg.new(@md,dob) + if dob.is==:heading + if dob.ln==0 + type="heading_section_#{dob.ln.to_s}" + xml_markup(dob) + xml_structure(dob,type) + dob.obj=x.heading_body0 + elsif dob.ln==1 + type="heading_section_#{dob.ln.to_s}" + xml_markup(dob) + xml_structure(dob,type) + dob.obj=x.heading_body1 + elsif dob.ln==2 + type="heading_section_#{dob.ln.to_s}" + xml_markup(dob) + xml_structure(dob,type) + dob.obj=x.heading_body2 + elsif dob.ln==3 + type="heading_section_#{dob.ln.to_s}" + xml_markup(dob) + xml_structure(dob,type) + dob.obj=x.heading_body3 + elsif dob.ln==4 + type="heading_content_#{dob.lv}" + xml_markup(dob) + xml_structure(dob,type) + dob.obj=x.heading_body4 + elsif dob.ln==5 + type="heading_content_#{dob.lv}" + xml_markup(dob) + xml_structure(dob,type) + dob.obj=x.heading_body5 + elsif dob.ln==6 + type="heading_content_#{dob.lv}" + xml_structure(dob,type) + dob.obj=x.heading_body6 + elsif dob.ln==7 + type="heading_content_#{dob.lv}" + xml_structure(dob,type) + dob.obj=x.heading_body7 + end + else + dob.ocn + if dob.is==:verse + type='verse' + poem_structure(dob) #redo + elsif dob.is==:group + type='group' + group_structure(dob) #redo + elsif dob.is==:block + type='block' + block_structure(dob) #redo + elsif dob.is==:code + type='code' + code_structure(dob) #redo + elsif dob.is==:table # tables come as single block #work area 2005w13 + type='table' + table_structure(dob) + elsif dob.is==:para \ + and dob.indent.to_s =~/[1-9]/ \ + and dob.bullet_ + type="indent_bullet#{dob.indent.to_s}" + xml_markup(dob) + elsif dob.is==:para \ + and dob.indent.to_s =~/[1-9]/ \ + and dob.indent == dob.hang + type="indent#{dob.indent.to_s}" + xml_markup(dob) + elsif dob.is==:para \ + and dob.hang.to_s =~/[0-9]/ \ + and dob.indent != dob.hang + type="hang#{dob.hang.to_s}_indent#{dob.indent.to_s}" + xml_markup(dob) + else + type='norm' + xml_markup(dob) + end + add_to_body(dob,type) + end + elsif dob.obj =~/(#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + elsif dob.obj =~/(MetaData)/ + txt_obj={ txt: '
MetaData' } + format_scroll=FormatScroll.new(@md,txt_obj) + dob.obj=format_scroll.bold_para + elsif dob.obj =~/(Owner Details)/ + dob.obj='' + end + if dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/ # -endnote + dob.obj='' + end + if dob.obj =~/.*<:#>.*$/ + dob.obj=if dob.obj =~ /#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/ + txt_obj={ txt: dob.obj } + format_text=FormatTextObject.new(@md,txt_obj) + format_text.scr_inden_ocn_e_no_paranum + end + end + else # + end + dob.obj=dob.obj.gsub(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') if dob.obj + end + end + @content_flag=true + 7.downto(4) do |x| + y=x - 1; v=x - 3 + if @level[x]==true #2004w36 bug fix? watch/test previous logic broke on free.for.all @coontent_flag introduced + if @content_flag==true + @per.body << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" + @content_flag=false + else + @per.body << "\n#{Ax[:tab]*y}" + end + end + end + 3.downto(1) do |x| + y=x - 1 + @per.body << "#{Ax[:tab]*y}" if @level[x]==true + end + end + def pre + rdf=SiSU_XML_Tags::RDF.new(@md) + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_dom').stylesheet + encoding=if @sys.locale =~/utf-?8/i then '' + else '' + end + @per.open =< +WOK + @per.head << '' + @per.body << '' + end + def post + @per.head << @per.sc + @per.head << '' + @per.body << '' + @per.close << '' + end + def publish + content=[] + content << @per.open << @per.head << @per.body # << @per.metadata + content << @per.tail << @per.close + content=content.flatten.compact + Output.new(content,@md).xml + @per.head,@per.body,@per.tail=[],[],[] # check whether should be nil + end + end + class Output + include SiSU_Param + def initialize(data,md) + @data,@md=data,md + @file=SiSU_Env::FileOp.new(@md) + end + def xml + SiSU_Env::FileOp.new(@md).mkdir + filename_xml=@file.write_file.xml_dom + @data.each do |str| + str=str.gsub(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') + filename_xml.puts str unless str.empty? + end + filename_xml.close + end + end + class Tidy + def initialize(md,file) + @md,@file=md,file + @prog=SiSU_Env::InfoProgram.new + end + def xml + if @prog.tidy !=false + if (@md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + unless @md.opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + 'invert', + 'Using XML Tidy', + 'check document structure' + ).colorize + tell=SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + 'invert', + '', + '' + ) + tell.grey_open + end + tidyfile='/dev/null' #don't want one or screen output, check for alternative flags + tidy=SiSU_Env::SystemCall.new(@file,tidyfile) + tidy.well_formed? + tell.p_off unless @md.opt.act[:quiet][:set]==:on + end + end + end + end + end +end +__END__ +,** Notes: tidy -xml dom.xml >> index.tidy +#+END_SRC + +#+END_SRC + +* xml shared +** xml_shared.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_shared.rb" +# <> +module SiSU_XML_Munge + require_relative 'xml_parts' # xml_parts.rb + class Trans + include SiSU_Parts_XML + def initialize(md) + @md=md + @sys=SiSU_Env::SystemCall.new + @dir=SiSU_Env::InfoEnv.new(@md.fns) + 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', + 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 + 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]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.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]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Dx[:url_o]}/,"#{Dx[:url_o_xml]}"). + gsub(/#{Dx[:url_c]}/,"#{Dx[:url_c_xml]}"). + gsub(/ |#{Mx[:nbsp]}/m,' '). + gsub(/;&([^#]|(?:[^gl][^t]|[^a][^m][^p]|[^n][^b][^s][^p])[^;])/,';&\1') # pattern not to match + 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]}/,' '). + gsub(/;&([^#]|(?:[^gl][^t]|[^a][^m][^p]|[^n][^b][^s][^p])[^;])/,';&\1') # pattern not to match + 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,'● '). #  not available + gsub(/#{Mx[:nbsp]}/,' '). #  not available + gsub(/<(p|br)>/,'<\1 />') + clean(str) + end + def markup_docbook(dob='') # work on, initially a copy of fictionbook! + if dob.is !=:code + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s*(.+?)#{Mx[:en_a_c]}/m,'\2'). + gsub(/\\\\/,''). + 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[: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, + %{#{Xx[:split]}:spaces0:
\n:spaces1:\n:spaces1:\n:spaces0:
#{Xx[:split]}}). # common image location, else use ./images + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/, + '\1'). + gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/, + '\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,'● '). #  not available + gsub(/#{Mx[:nbsp]}/,' '). #  not available + gsub(/<(p|br)>/,'<\1 />') + dob.obj=clean(dob.obj) + elsif dob.is == :code + dob.obj=dob.obj.gsub(/&/m,'&'). #sort + gsub(//,'>') + else # p dob.is ?? + end + 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 'dp' # dp.rb + include SiSU_Param + class RDF + include SiSU_Parts_XML + 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 + end + def meta_content_clean(content='') + content=if not content.nil? + content=content.tr('"',"'"). + gsub(/&/,'&') + else content + end + end + def rdfseg #segHead + rdftoc + end + def comment_xml(extra='') + generator="Generated by: #{@md.project_details.project} #{@md.project_details.version} of #{@md.project_details.date_stamp} (#{@md.project_details.date})" if @md.project_details.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 +<> +module SiSU_Tables + class Table #_xml + @@tablehead=0 + @@tablefoot=[] #watch #bug??? #check was @@tablefoot + def initialize(one,ocn='') + @one,@parablock,@ocn=one,one,ocn + end + def table_split #% used but, no longer operational, revisit + @new_content=[] + @one.split(/\n/).each do |parablock| + table=TableXML.new("#{parablock}\n") + @new_content << table.table + end + @new_content.join + end + end + class TableXML /,1] + @@tablefoot << m if m + @parablock=@parablock.gsub(//,'') + @@tablehead=1 if @parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u + if @parablock =~/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}/u + @parablock=@parablock.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+);\w\d+;\w\d+#{Mx[:gr_c]}/u, + %{\n#{@ocn}
}) + end + if @parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ + tablefoot=[] + @@tablefoot.each {|x| tablefoot << ''} + @@tablefoot=[] + 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") + @@tablehead=0 + end + @parablock + else + @parablock=@parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{ + + \n\n") + end + @parablock + end + end + class TableXMLdocbook + @@tablehead=0 + @@tablefoot=[] #watch + def initialize(table,id='') + @table_obj,@id=table,id + end + def spaces + Ax[:spaces] + end + def table + table_obj=@table_obj + if table_obj.obj !~/^/,'
') + trc <<= if table_obj.head_ and nr==0 + %{#{spaces*6}#{c}\n} + else %{#{spaces*6}#{c}\n} + end + nc+=1 + end + trc=(trc.is_a?(Array)) ? trc.flatten.join : trc + trc = if table_obj.head_ and nr==0 + "#{spaces*4}
\n#{spaces*5}\n#{trc}#{spaces*5}\n#{spaces*4}\n#{spaces*4}\n" + else + "#{spaces*5}\n#{trc}#{spaces*5}\n" + end + nr+=1 + table_rows << trc + end + tbody_close=if table_obj.head_ + "#{spaces*4}" + else '' + end + table_rows=table_rows.flatten.join + # include table_id
}). + gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{}). + gsub(/#{Mx[:tc_c]}/,"\n
}). + gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{ + }). + gsub(/#{Mx[:tc_c]}/,"\n
+ table_obj.obj=%{#{spaces*3} +#{spaces*4}
+#{spaces*4} +#{table_rows}#{tbody_close} +#{spaces*4} +#{spaces*4}
+#{spaces*3}
} + table_obj + end + end + class TableXMLexp +
' + end + def margin_numless + '' + end + def table_head(inf) + %{ + + + + " + end + def table + m=@parablock[//,1] + @@tablefoot << m if m + @parablock=@parablock.gsub(//,'') + @@tablehead=1 if @parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u + if @parablock =~/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+);\w\d+;\w\d+#{Mx[:gr_c]}/u + @parablock=table_head($1) + end + if @parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ + tablefoot=[] + @@tablefoot.each {|x| tablefoot << ''} + @@tablefoot=[] + if @parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ + @parablock=table_end + end + end + if @@tablehead==1 + if @parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u + if @parablock =~/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u + @parablock=@parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,table_row($1,true)) + end + if @parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u + @parablock=@parablock.gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,table_cell($1,true)) + end + if @parablock =~/#{Mx[:tc_c]}/ + @parablock=@parablock.gsub(/#{Mx[:tc_c]}/,table_row_close(true)) + end + @@tablehead=0 + end + @parablock + else + if @parablock =~/^#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u + @parablock=@parablock.gsub(/^#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,table_row($1)) + end + if @parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u + @parablock=@parablock.gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,table_cell($1)) + end + if @parablock =~/#{Mx[:tc_c]}/ + @parablock=@parablock.gsub(/#{Mx[:tc_c]}/,table_row_close) + end + @parablock + end + @parablock + end + end +end +__END__ +#+END_SRC + +** xml_format.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_format.rb" +# <> +module SiSU_XML_Format + require_relative 'dp' # dp.rb + require_relative 'xml_parts' # xml_parts.rb + include SiSU_Param + class ParagraphNumber + def initialize(md,paranum) + @md=md + @paranum=(paranum ? (/(\d+)/m.match(paranum)[1]) : nil) + end + def display + p_num_display=if @paranum + @paranum.gsub(/(\d+)/, + '' + + '  \1') + else '' + end + p_num_display + end + def name + p_num_name=@paranum.gsub(/(\d+)/,'') + p_num_name + end + def goto + p_num_goto=@paranum.gsub(/(\d+)/,'') + p_num_goto + end + end + class HeadInformation + include SiSU_Parts_XML + def initialize #dc rdf + @full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords='' + @md=@@md + # DublinCore 1 - title + @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 # DublinCore 2 - creator/author (author) + @rdf_author=%{ dc.author="#{@md.creator.author}"\n} + @author=%{\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} + @subject=%{\n} + end + if defined? @md.notes.description \ + and @md.notes.description=~/\S+/ # DublinCore 4 - description + @rdf_description=%{ dc.description="#{@md.notes.description}"\n} + @description=%{\n} + end + if defined? @md.publisher \ + and @md.publisher=~/\S+/ # DublinCore 5 - publisher (current copy published by) + @rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n} + @publisher=%{\n} + end + if defined? @md.creator.contributor \ + and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor + @rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n} + @contributor=%{\n} + end + if defined? @md.date.published \ + and @md.date.published # DublinCore 7 - date year-mm-dd + @rdf_date=%{ dc.date="#{@md.date.published}"\n} + @date=%{\n} + end + if defined? @md.date.created \ + and @md.date.created # 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 # 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 # 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 # 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 # DublinCore 7 - date.modified year-mm-dd + @rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n} + @date_modified=%{\n} + end + if defined? @md.notes.coverage \ + and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage + @rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n} + @coverage=%{\n} + end + if defined? @md.notes.relation \ + and @md.notes.relation=~/\S+/ # DublinCore 13 - relation + @rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n} + @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} + @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} + @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} + # @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} + @source=%{\n} + end + if defined? @md.original.language \ + and @md.original.language=~/\S+/ # DublinCore 12 - language (English) + @rdf_language=%{ dc.language="#{@md.original.title}"\n} + @language=%{\n} + end + if defined? @md.rights.all \ + and @md.rights.all=~/\S+/ # DublinCore 15 - rights + rights=meta_content_clean(@md.rights.all) + copyright=meta_content_clean(@md.rights.copyright.all) + @rdf_rights=%{ dc.rights="#{rights}"\n} + @rights=%{\n} + end + @copyright=%{\n} \ + if @md.rights.copyright.all # possibly redundant see dc.rights + @owner=%{\n} if @md.owner + @keywords=%{\n} if @md.keywords + @index='index' + end + def meta_content_clean(content='') + content=if not content.nil? + content=content.tr('"',"'"). + gsub(/&/,'&') + content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content) + else content + end + end + def table_close + '
+ + +} + end + def table_end(tablefoot='') + %{
#{the_margin_numless}#{the_margin_numless} #{the_table_close} +#{tablefoot}} + end + def table_row(inf,h=false) + bold=h ? '' : '' + %{ +
#{bold}} + end + def table_cell(inf,h=false) + if h; %{} + else %{} + end + end + def table_row_close(h=false) + bold_close=h ? '' : '' + "#{bold_close}
' + end + def toc_head + < + +#{@md.html_title} + + + +#{@full_title} +#{@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} +#{@png.ico} +#{@txt.generator} +#{@js.head} +\n +#{@color.body} +#{@font.css_table_file} + + + +#{@js.top} +WOK + end + end + class FormatTextObject + include SiSU_Parts_XML + attr_accessor :md,:txt,:format,:paranum,:p_num,:para_id,:headname,:font + def initialize(md,dob) + @md,@dob=md,dob + if @dob[:ocn]=~/\d+/ + @paranum=/(\d+)/m.match(@dob[:ocn])[1] + @headname='' + @headname=%{} if defined? dob.name + @p_num=SiSU_XML_Format::ParagraphNumber.new(@md,dob.ocn) + end + rgx=/^[1-6-]~{1,2}/ #watch + @lnk_url=@lnk_url.gsub(rgx,'') if @lnk_url =~rgx + rgx=/~\{\d+\s+(.+?)\}~/ + @lnk_url=@lnk_url.gsub(rgx,'\1') if @lnk_url =~rgx + end + def scr_endnote_body + "#{@txt} " + end + end + class FormatScroll < FormatTextObject + def initialize(md,dob) + super(md,dob) + end + def heading_body + %{

#{@p_num.name}#{@headname}#{@dob.obj}

} + + %{

  #{@dob.ocn}

\n} + end + def heading_body0 + %{

#{@p_num.name}#{@headname}#{@dob.obj}

} + + %{

  #{@dob.ocn}

\n} + end + def heading_body1 + %{

#{@p_num.name}#{@headname}#{@dob.obj}

} + + %{

  #{@dob.ocn}

\n} + end + def heading_body2 + %{

#{@p_num.name}#{@headname}#{@dob.obj}

} + + %{

  #{@dob.ocn}

\n} + end + def heading_body3 + %{

#{@p_num.name}#{@headname}#{@dob.obj}

} + + %{

  #{@dob.ocn}

\n} + end + def heading_body4 + %{
#{@p_num.name}#{@headname}#{@dob.obj}
} + + %{

  #{@dob.ocn}

\n} + end + def heading_body5 + %{
#{@p_num.name}#{@headname}#{@dob.obj}
} + + %{

  #{@dob.ocn}

\n} + end + def heading_body6 + %{#{@p_num.name}#{@headname}#{@dob.obj}} + + %{

  #{@dob.ocn}

\n} + end + end + 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.to_i==0 + @ocn.gsub(/^(\d+|)$/, + %{}) + else + @ocn.gsub(/^(\d+|)$/, + %{}) + end + else + ocn_class='ocn_off' + @ocn.gsub(/^(\d+|)$/, + %{}) + end + end + def name + %{} + end + def id #w3c? "tidy" complains about numbers as identifiers ! annoying + %{id="o#{@ocn}"} + end + def goto + %{} + end + end + class HeadInformation + include SiSU_Parts_XML + attr_reader :md,:sfx,:pdf,:rdf,:vz + def initialize(md) + @md=md + @rdf=SiSU_XML_Tags::RDF.new(md) + # DublinCore 1 - title + @stylesheet=SiSU_Style::CSS_HeadInfo.new(md).stylesheet + @seg_name_html=(SiSU_HTML::Source::Seg.new.seg_name_html || []) + @seg_name_html_tracker=(SiSU_HTML::Source::Seg.new.seg_name_html_tracker || []) + @index='index' + @metalink='#metadata' + @tocband_scroll,@tocband_segtoc=nil,nil + end + def doc_type + %{ +\n} + end + def table_close + %{ +#{the_table_close}} + end + def html_close #moved + %{ +} + end + end + class XML + end + class FormatTextObject + include SiSU_Parts_XML + attr_accessor :md,:dob,: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 + elsif t_o.class.inspect =~/Object/ + @txt=if defined? t_o.obj; t_o.obj + else nil + end + @ocn=if defined? t_o.ocn; t_o.ocn.to_s + else nil + end + @headname=if t_o.is==:heading and defined? t_o.name; t_o.name + else nil + end + else + if @md.opt.act[:maintenance][:set]==:on + p __FILE__ << ':' << __LINE__.to_s + p t_o.class + p caller + end + end + if defined? @t_o.ocn + ocn=((@t_o.ocn.to_s =~/\d+/) ? @t_o.ocn : nil) + @p_num=ParagraphNumber.new(@md,ocn) + end + 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=if headname =~/^[a-zA-Z]/; %{} #consider: h_#{headname} + else %{} + end + end + end + @dob=t_o if defined? t_o.is + end + def endnote_body + %{ +

+ #{@txt} +

+} + end + def endnote_body_indent + %{ +

+ #{@txt} +

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

+ #{@txt} +

+
+} + end + def para_form_css(tag,attrib) # regular paragraphs shaped here + ul=ulc='' + ul,ulc="
    \n ","\n
" if @tag =~/li/ + %{ +
+ #{@p_num.ocn_display} + #{ul}<#{tag} class="#{attrib}" #{@p_num.id}> + #{@txt} + #{ulc} +
+} + end + def para + para_form_css('p','norm') + end + def code + para_form_css('p','code') + end + def center + para_form_css('p','center') + end + def bold + para_form_css('p','bold') + end + def bullet + para_form_css('li','bullet') + end + def format(tag,attrib) + para_form_css(tag,attrib) + end + def heading_normal(tag,attrib) + %{ +
+ #{@p_num.ocn_display} + <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} + #{@headname}#{@txt} + +
+} + end + def heading_body + heading_normal('p','norm') + end + def heading_body0 + heading_normal('h1','norm') + end + def heading_body1 + heading_normal('h1','norm') + end + def heading_body2 + heading_normal('h2','norm') + end + def heading_body3 + heading_normal('h3','norm') + end + def heading_body4 + heading_normal('h4','norm') + end + def heading_body5 + heading_normal('h5','norm') + end + def heading_body6 + heading_normal('h6','norm') + end + def heading_body7 + heading_normal('h7','norm') + end + def title_header(tag,attrib) + %{ +
+<#{tag} class="#{attrib}"> + #{@txt} + +
+} + end + def title_header1 + title_header('h1','tiny') + end + def title_header2 + title_header('h2','tiny') + end + def title_header3 + title_header('h3','tiny') + end + def title_header4 + '' + end + def title_header4_old + %{ +
+ + +
+} + end + def dl #check :trailer + "
#{@txt} #{@trailer}
" + end + def table_css_end # + ' +

+ ' + end + def gsub_body +#fix + @txt=case @txt + when /^\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 /^\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 + %{#{the_margin.txt_0} +

+ #{@txt} +

+#{the_margin.num_css} +     +#{the_table_close}} + end + def bold_header + @txt=@txt.gsub(/[1-9]~(\S+)/,''). + gsub(/[1-9]~/,'') + %{

+ #{@txt} +

+#{the_margin.num_css} +     +#{the_table_close}} + end + def toc_head_copy_at + %{

#{@txt}

\n} + end + def center + %{

#{@txt}

\n} + end + def bold + %{

#{@txt}

\n} + end + def center_bold + %{

#{@txt}

\n} + end + end + class FormatScroll < FormatTextObject + include SiSU_Parts_XML + def initialize(md,txt) + super(md,txt) + end + end + class FormatSeg < FormatTextObject + def initialize(md,txt) + super(md,txt) + end + def navigation_toc_lev1_advert + %{#{@banner.home_button}\n +
+#{@txt} +#{@two} +

} + end + def navigation_toc_lev1 + %{#{@banner.nav_toc}} + end + def navigation_toc_lev2 #change bold use css + %{

+ + +
+ + + #{@txt} + +

+#{the_table_close}} + end + def navigation_toc_lev3 #change bold use css + %{

+ + +
+ + + #{@txt} + +

+#{the_table_close}} + end + def navigation_toc_lev4 + %{ + +
+ +

+ #{@txt} +

+#{the_table_close}} + end + def navigation_toc_lev5 + end + def navigation_toc_lev6 + end + def endnote_seg_body(fn='') #FIX #url construction keep within single line... BUG WATCH 200408 + fn='doc' if fn.empty? #you may wish to reconsider, sends to 'doc' where no segment info # Sfx[:html] or Sfx[:xhtml] ? + %{ +

+ #{@endnote_part_a}#{fn}#{@md.lang_code_insert}#{Sfx[:html]}#{@endnote_part_b} +

+} + end + def subtoc_lev(tag,attrib) + 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]}\s*)/m + 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(/ \d+<\/sup> /m,'') + 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 subtoc_lev7 + subtoc_lev('h7','subtoc') if @txt + end + #% para sisu + def header_sub(tag,attrib) + @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} #{@headname} + #{@txt} + +
+} + end + def header4 + %{ +
+ #{@p_num.ocn_display} +

#{@p_num.name} + #{@t_o[:format]} + #{@txt} +

+
+} + end + def header5 + header_sub('p','bold') + end + def header6 + header_sub('p','bold') + end + def header7 + header_sub('p','bold') + end + def navigation_header4 + %{ + +
+

+ #{@txt} +

+#{the_table_close}} + end + def navigation_header5 + %{

+ #{@txt} +

} + end + def navigation_header6 + %{

+ #{@txt} +

} + end + def navigation_header7 + %{

+ #{@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 lev7 + lev('h7','toc') + #lev('b','toc') + end + def lev0 #docinfo + lev('h0','toc') + end + def mini_lev1 + lev('h1','minitoc') + end + def mini_lev2 + lev('h2','minitoc') + end + def mini_lev3 + lev('h3','minitoc') + end + def mini_lev4 + lev('h4','minitoc') + end + def mini_lev5 + lev('h5','minitoc') + end + def mini_lev6 + lev('h6','minitoc') + end + def mini_lev7 + lev('h7','minitoc') + end + def mini_lev0 #docinfo + lev('h0','minitoc') + end + def mini_tail + %{ +

    + Manifest (alternative outputs) +

    +} + end + def mini_concord_tail + %{ +

    + Concordance (wordlist) +

    +

    + Manifest (alternative outputs) +

    +} + end + end + class XML + end +end +__END__ +,** Notes: tidy -xml index.xml >> index.tidy +#+END_SRC + +** xml_md_oai_pmh_dc.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_md_oai_pmh_dc.rb" +# <> +module SiSU_XML_Metadata + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'dp' # dp.rb + include SiSU_Param + class OAI_PMH + def initialize(opt) + @md=SiSU_Param::Parameters.new(opt).get + @oai_pmh=[] + end + def read + output + end + def pre +< + +WOK + end + def body + if defined? @md.title.full \ + and @md.title.full=~/\S+/ # DublinCore 1 - title + @oai_pmh << %{ #{@md.title.full}\n} + end + if defined? @md.creator.author \ + and @md.creator.author=~/\S+/ # DublinCore 2 - creator/author (author) + txt=meta_content_clean(@md.creator.author) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.classify.subject \ + and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???) + txt=meta_content_clean(@md.classify.subject) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.classify.keywords \ + and @md.classify.keywords=~/\S+/ + txt=meta_content_clean(@md.classify.keywords) + @oai_pmh << %{ #{txt}\n} + end + if @md.publisher # DublinCore 5 - publisher (current copy published by) + txt=meta_content_clean(@md.publisher) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.creator.contributor \ + and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor + txt=meta_content_clean(@md.creator.contributor) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.date.published \ + and @md.date.published=~/\S+/ # DublinCore 7 - date year-mm-dd + @oai_pmh << %{ #{@md.date.published}\n} + end + if defined? @md.date.created \ + and @md.date.created=~/\S+/ # DublinCore 7 - date.created + @oai_pmh << %{ #{@md.date.created}\n} + end + if defined? @md.date.issued \ + and @md.date.issued=~/\S+/ # DublinCore 7 - date.issued + @oai_pmh << %{ #{@md.date.issued}\n} + end + if defined? @md.date.available \ + and @md.date.available=~/\S+/ # DublinCore 7 - date.available + @oai_pmh << %{ #{@md.date.available}\n} + end + if defined? @md.date.valid \ + and @md.date.valid=~/\S+/ # DublinCore 7 - date.valid + @oai_pmh << %{ #{@md.date.valid}\n} + end + if defined? @md.date.modified \ + and @md.date.modified=~/\S+/ # DublinCore 7 - date.modified + @oai_pmh << %{ #{@md.date.modified}\n} + end + if defined? @md.notes.description \ + and @md.notes.description=~/\S+/ # DublinCore 4 - description + txt=meta_content_clean(@md.notes.description) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.notes.coverage \ + and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage + txt=meta_content_clean(@md.notes.coverage) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.notes.relation \ + and @md.notes.relation=~/\S+/ # DublinCore 13 - relation + txt=meta_content_clean(@md.notes.relation) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.notes.type \ + and @md.notes.type=~/\S+/ # DublinCore 8 - type + txt=meta_content_clean(@md.notes.type) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.notes.format \ + and @md.notes.format=~/\S+/ # DublinCore 9 - format + txt=meta_content_clean(@md.notes.format) + @oai_pmh << %{ #{txt}\n} + end + #if defined? @md.identifier.sisupod \ + #and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier + # txt=meta_content_clean(@md.identifier.sisupod) + # @oai_pmh << %{ #{txt}\n} + #end + if defined? @md.original.source \ + and @md.original.source=~/\S+/ # DublinCore 11 - source + txt=meta_content_clean(@md.original.source) + @oai_pmh << %{ #{txt}\n} + end + if defined? @md.title.language \ + and @md.title.language=~/\S+/ # DublinCore 12 - language (English) + @oai_pmh << %{ #{@md.title.language}\n} + end + if defined? @md.original.language \ + and @md.original.language=~/\S+/ + @oai_pmh << %{ #{@md.original.language}\n} + end + if defined? @md.rights.all \ + and @md.rights.all=~/\S+/ # DublinCore 15 - rights + txt=meta_content_clean(@md.rights.all) + @oai_pmh << %{ #{txt}\n} + end + @oai_pmh + end + def meta_content_clean(content='') + unless content.nil? + content=content.tr('"',"'") + end + content + end + def post + '' + end + def output + SiSU_Env::FileOp.new(@md).mkdir + oai_pmh=SiSU_Env::FileOp.new(@md,@md.fn[:oai_pmh]).mkfile #implement in param + oai_pmh << pre + body.each do |x| + oai_pmh << x + end + oai_pmh << post + end + end +end +__END__ +http://www.openarchives.org/pmh/ +http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm#dublincore +http://es.dublincore.org/documents/usageguide/elements.shtml +http://dublincore.org/documents/dces/ +see also http://dublincore.org/documents/dcmes-xml/ +#http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm#dublincore +#sample implementation, e.g. 2 + + + Grassmann's space analysis + Hyde, E. W. (Edward Wyllys) + LCSH:Ausdehnungslehre; LCCN QA205.H99 + J. Wiley & Sons + Created: 1906; Available: 1991 + text + http://resolver.library.cornell.edu/math/1796949 + + english + Public Domain + +#+END_SRC + +** xml_parts.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_parts.rb" +# <> +module SiSU_Parts_XML + require_relative 'generic_parts' # generic_parts.rb + include SiSU_Parts_Generic + def the_line_break + '
    ' + end + def the_table_close + '
    ' + end + def the_url_decoration + def xml_open #'<' + Dx[:url_o] + end + def xml_close #'>' + Dx[:url_c] + end + def txt_open + '<' + end + def txt_close + '>' + end + self + end + def the_color + def white + '#ffffff' + end + def black + '#000000' + end + def grey_pale + '#eeeeee' + end + def grey_medium + '#cccccc' + end + def grey + '#999999' + end + def blue_ink + '#003399' + end + def blue_tinge + '#e3ecef' + end + def yellow_light + '#fff3b6' + end + def table1 + 'ffffcc' + end + def table2 + 'c0d0f0' + end + def band1 + %{"#{white}"} + end + def band2 + %{"#{white}"} + end + self + end + def the_png + def _url_path_image_base #used for html image display + "#{Xx[:html_relative2]}_sisu/image" + end + def ico + %{ } + end + def png_home + %{#{the_text.home} -->} + end + def png_home_button + rel=@dir.path_rel_links.html_scroll_2 + %{#{the_text.home} -->} + end + self + end + def the_font + def set_fonts + 'verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman' + #'verdana, arial, georgia, tahoma, sans-serif, helvetica, "times new roman", times, roman' + end + def set_face + %{face="#{set_fonts}"} + end + #def set_color + # 'color="#000000"' + #end + #def set_size_endnote + # 'size="3"' + #end + #def set_small + # 'size="3"' + #end + #def set_tiny + # 'size="2"' + #end + #def paragraph_font_tiny + # %{} + #end + #def paragraph_font_small + # %{} + #end + self + end + def the_banner + def home_button_only + %{ + #{the_png.png_home_button} + } + end + def banner_band + %{ + +
    + + #{the_png.png_home} + + +#{the_table_close}} + end + self + end +end +module SiSU_Proj_XML + require_relative 'html_parts' # html_parts.rb + require_relative 'se' # se.rb + include SiSU_Env + class Bits < SiSU_Proj_HTML::Bits + end +end +__END__ +#+END_SRC + +** xml_persist.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_persist.rb" +# <> +module SiSU_XML_Persist + class Persist + @@persist=nil + attr_accessor :head,:toc,:body,:tail,:open,:close,:sc,:endnotes,:book_idx,:metadata + #attr_accessor :head,:body,:tail,:open,:close,:sc +#@@odf={ body: [], head: [], toc: [], metadata: [], tail: [], book_idx: [], endnotes: [] } + def initialize(args=nil) + @@persist=args=(args ? args : (@@persist || persist_init_hash_values)) + @head=args[:head] + @toc=args[:toc] + @body=args[:body] + @tail=args[:tail] + @open=args[:open] + @close=args[:close] + @sc=args[:sc] + @endnotes=args[:endnotes] + @book_idx=args[:book_idx] + @metadata=args[:metadata] + end + def head + @head + end + def toc + @toc + end + def body + @body + end + def tail + @tail + end + def open + @open + end + def close + @close + end + def sc + @sc + end + def endnotes + @endnotes + end + def book_idx + @book_idx + end + def metadata + @metadata + end + def persist_init_hash_values + { + head: [], + toc: [], + body: [], + tail: [], + open: [], + close: [], + sc: [], + endnotes: [], + book_idx: [], + metadata: [], + } + end + def persist_init + @@persist=nil + Persist.new(persist_init_hash_values) + end + end +end +__END__ +#+END_SRC + +** xml_scaffold_structure_collapsed.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_scaffold_structure_collapsed.rb" +# <> +module SiSU_XML_Scaffold_Structure_Collapse + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def spaces + Ax[:spaces] + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + SiSU_XML_Scaffold_Structure_Collapse::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll + def collapsed + [ '0', + '1', + '2', + '3', + '4', + '5', + '6' + ] + end + def docbook + end + def fictionbook + end + self + end + def output(o,lev=nil,comment='') + puts lev == (0..6) \ + ? "#{spaces*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + end + def structure_collapsed(data) + puts "\ncollapsed structure, heading outline --->\n\n" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + output(o,o.lc) + end + end + end + def structure_build_collapsed(data) + @s=tags.collapsed + puts "\nXML [#{@t} type] structure outline --->\n\n" + h=[0,false,false,false] + puts "<#{@s[0]}>" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + lev=o.lc + structure_build_tag_close(lev,h) + puts "#{spaces*lev}<#{@s[lev]}>\n#{spaces*lev} [#{o.ocn}] #{lev} {#{o.node}}" + h[0]=lev + end + end + structure_build_tag_close(0,h) + end + def structure_build_tag_close(lev,h) + case h[0] + when 1 + puts "#{spaces*1}" if (lev <= 1) + puts "" if (lev==0) + when 2 + puts "#{spaces*2}" if (lev <= 2) + puts "#{spaces*1}" if (lev <= 1) + puts "" if (lev==0) + when 3 + puts "#{spaces*3}" if (lev <= 3) + puts "#{spaces*2}" if (lev <= 2) + puts "#{spaces*1}" if (lev <= 1) + puts "" if (lev==0) + when 4 + puts "#{spaces*4}" if (lev <= 4) + puts "#{spaces*3}" if (lev <= 3) + puts "#{spaces*2}" if (lev <= 2) + puts "#{spaces*1}" if (lev <= 1) + puts "" if (lev==0) + when 5 + puts "#{spaces*5}" if (lev <= 5) + puts "#{spaces*4}" if (lev <= 4) + puts "#{spaces*3}" if (lev <= 3) + puts "#{spaces*2}" if (lev <= 2) + puts "#{spaces*1}" if (lev <= 1) + puts "" if (lev==0) + when 6 + puts "#{spaces*6}" if (lev <= 6) + puts "#{spaces*5}" if (lev <= 5) + puts "#{spaces*4}" if (lev <= 4) + puts "#{spaces*3}" if (lev <= 3) + puts "#{spaces*2}" if (lev <= 2) + puts "#{spaces*1}" if (lev <= 1) + puts "" if (lev==0) + end + end + end + end +end +__END__ +@s=['0', + 'A', + 'B', + 'C', + '1', + '2', + '3' +] +#@t='docbook' #@t='fictionbook' +#@s=['book', #@s=['body', +# 'part', # 'section', +# 'subpart N/A', # 'section', +# 'sub-subpart N/A', # 'section', +# 'chapter', # 'section', +# 'sect1', # 'section', +# 'sect2' # 'section' +#] #] +#+END_SRC + +** xml_scaffold_structure_sisu.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_scaffold_structure_sisu.rb" +# <> +module SiSU_XML_Scaffold_Structure_Sisu + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def spaces + Ax[:spaces] + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + SiSU_XML_Scaffold_Structure_Sisu::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll \n\n" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + puts "#{spaces*o.ln}<#{tags.sisu[o.ln]}>[#{o.ocn}] #{o.ln} #{o.obj}" + end + end + end + def output(o,lev=nil,comment='') + puts lev == (0..6) \ + ? "#{spaces*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + end + def structure_build_sisu(data) + @s=tags.sisu + puts "\nXML [#{@t} type] structure outline --->\n\n" + h=[0,false,false,false] + puts "<#{@s[0]}>" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + structure_build_tag_close(o.ln,h) + puts "#{spaces*o.ln}<#{@s[o.ln]}>\n#{spaces*o.ln} [#{o.ocn}] #{o.ln} {#{o.node}}" + case o.ln + when 1 + h=[o.ln,true,false,false] + when 2 + h=[o.ln,true,true,false] + when 3 + h=[o.ln,true,true,true] + when 4..6 + h[0]=o.ln + end + end + end + structure_build_tag_close(0,h) + end + def structure_build_tag_close(lev,h) + case h[0] + when 1 + puts "#{spaces*1}" if (lev <= 1) && h[1] + puts "" if (lev==0) + when 2 + puts "#{spaces*2}" if (lev <= 2) && h[2] + puts "#{spaces*1}" if (lev <= 1) && h[1] + puts "" if (lev==0) + when 3 + puts "#{spaces*3}" if (lev <= 3) && h[3] + puts "#{spaces*2}" if (lev <= 2) && h[2] + puts "#{spaces*1}" if (lev <= 1) && h[1] + puts "" if (lev==0) + when 4 + puts "#{spaces*4}" if (lev <= 4) + puts "#{spaces*3}" if (lev <= 3) && h[3] + puts "#{spaces*2}" if (lev <= 2) && h[2] + puts "#{spaces*1}" if (lev <= 1) && h[1] + puts "" if (lev==0) + when 5 + puts "#{spaces*5}" if (lev <= 5) + puts "#{spaces*4}" if (lev <= 4) + puts "#{spaces*3}" if (lev <= 3) && h[3] + puts "#{spaces*2}" if (lev <= 2) && h[2] + puts "#{spaces*1}" if (lev <= 1) && h[1] + puts "" if (lev==0) + when 6 + puts "#{spaces*6}" if (lev <= 6) + puts "#{spaces*5}" if (lev <= 5) + puts "#{spaces*4}" if (lev <= 4) + puts "#{spaces*3}" if (lev <= 3) && h[3] + puts "#{spaces*2}" if (lev <= 2) && h[2] + puts "#{spaces*1}" if (lev <= 1) && h[1] + puts "" if (lev==0) + end + end + end + end +end +__END__ +@s=['0', + 'A', + 'B', + 'C', + '1', + '2', + '3' +] +#@t='docbook' #@t='fictionbook' +#@s=['book', #@s=['body', +# 'part', # 'section', +# 'subpart N/A', # 'section', +# 'sub-subpart N/A', # 'section', +# 'chapter', # 'section', +# 'sect1', # 'section', +# 'sect2' # 'section' +#] #] +#+END_SRC + +* odf +** xml_odf_odt.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_odf_odt.rb" +# <> +module SiSU_XML_ODF_ODT + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'xml_parts' # xml_parts.rb + 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 + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + require_relative 'xml_persist' # xml_persist.rb + @@alt_id_count,@@alt_id_count=0,0 + class Source + begin + require 'zlib' + require 'find' + rescue LoadError + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). + error('zlib or find NOT FOUND (LoadError)') + end + 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.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + Dir.chdir(@opt.f_pth[:pth]) + 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 + @per.book_idx=idx_arr.join + end + end + def odf_metadata + @per.metadata=SiSU_Metadata::Summary.new(@md). + odf.metadata + end + def odf_tail + manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" + @per.tail << %{Available document outputs:
    <#{manifest}>
    } + @per.tail << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} + @per.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.to_s =~m \ + or @md.pagebreak.to_s =~m) + ' ' + elsif @md.pageline \ + and @md.pageline =~m #fix + else '' + end + end + @@docstart=false + if dob.use_ != :dummy + dob.tmp=dob.obj + dob.obj=%{#{breakpage}} \ + + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + else dob.tmp,dob.obj='','' + end + dob + end + def toc(dob,p_num) + hardspace=(dob.lv =~/[A-D]/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(@md)}/#{i}") #review + @env.path.image_source_include(@md) + 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(@md)}/#{i}") + @env.path.image_source_sisu_includes(@md) + 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 \ + + @md.opt.sisu_data_dir? + ).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]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.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]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.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]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.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]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.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 @make.build.odt_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Integer) + p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(@make,dob.ocn).set_bookmark_and_display + end + end + end + if dob.is==:heading + @per.body << heading(dob,p_num).obj << break_line*2 + if SiSU_Env::ProcessingSettings.new(md).build.toc? + if dob.lv =~/[A-D1]/i + @per.toc << toc(dob,p_num).obj + end + end + elsif dob.is ==:verse + @per.body << poem(dob,p_num).obj << break_line*2 + elsif dob.is==:group + @per.body << group(dob,p_num).obj << break_line*2 + elsif dob.is==:block + @per.body << block(dob,p_num).obj << break_line*2 + elsif dob.is==:code + @per.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..7).each { |x| @cont[x]=@level[x]=false } + (4..7).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.selections.str =~/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.obj =~/^(?:#{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.obj =~/#{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.to_s =~/\d+/ + @p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(@make,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 + @per.head << x + end + def publish + content=[] + br_pg=' ' + content << + @per.head << + @per.toc << + br_pg << + @per.body << + @per.book_idx << + br_pg << + @per.metadata << + @per.tail + SiSU_XML_ODF_ODT::Source::Output.new(content,@md,@env).odf + @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } + end + end + class Output > +module SiSU_XML_ODF_ODT_Format + require_relative 'dp' # dp.rb + include SiSU_Param + class ParagraphNumber + def initialize(make,paranum) + @make=make + @paranum=/(\d+)/m.match(paranum.to_s)[1] + end + def set_ref_and_display + set_ref=@paranum.gsub(/(\d+)/, + ' ') + disp=@paranum.gsub(/(\d+)/, + (@make.build.odt_ocn?) \ + ? %{ #{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+)/, + (@make.build.odt_ocn?) \ + ? %{ #{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 + 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 + def heading_body7 + end + end + class Table + @@table_counter=0 + @@tablefoot=[] #watch + @@fns='' + def initialize(md,dob,p_num) + @md,@dob,@p_num=md,dob,p_num + @txt=dob.obj + 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 then 'A' + when 2 then 'B' + when 3 then 'C' + when 4 then 'D' + when 5 then 'E' + when 6 then 'F' + when 7 then 'G' + when 8 then 'H' + when 9 then 'I' + when 10 then 'J' + when 11 then 'K' + when 12 then 'L' + when 13 then 'M' + when 14 then '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.project_details.project} #{@md.project_details.version} #{@md.project_details.date_stamp} (#{@md.project_details.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__ +#+END_SRC + +* docbook5rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_docbook5.rb" +# <> +module SiSU_XML_Docbook_Book + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + require_relative 'shared_metadata' # shared_metadata.rb + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + @env=@particulars.env + report + SiSU_XML_Docbook_Book::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + #SiSU_Env::CreateSite.new(@opt.selections.str).cp_css + #SiSU_Env::CreateSite.new(@opt.selections.str).cp_base_images + Dir.chdir(@opt.f_pth[:pth]) + end + end + private + def report + 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.docbook_viewer} #{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}" + : "[#{@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], + 'DocBook', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'DocBook', + 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.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}" + ).flow + end + end + end + class Scroll 0 + #tail + end + def document_images + img_pth={ + src: @md.opt.image_src_path, + dest: @md.env.path.webserv + '/_sisu/image', + } + unless FileTest.directory?(img_pth[:dest]) + #mkdir? + end + if FileTest.directory?(img_pth[:dest]) + @md.ec[:image].each do |x| + img={ + src: "#{img_pth[:src]}/#{x}", + dest: "#{img_pth[:dest]}/#{x}", + } + if FileTest.file?(img[:src]) + FileUtils::cp(img[:src],img[:dest]) + else p "Not Found: #{img[:src]}/#{x}" + end + end + end + end + def spaces + Ax[:spaces] + end + def tags + # collapsed --> + def collapsed + %w[ 0 1 2 3 4 5 ] + end + def docbook_tag(lc,chlv='') + case lc + when 0 then 'book' + when 1 then lc==chlv ? 'chapter' : 'section' + when 2 then lc==chlv ? 'chapter' : 'section' + when 3 then lc==chlv ? 'chapter' : 'section' + when 4 then 'section' + when 5 then 'section' + when 6 then 'section' + end + end + self + end + def put(line) + #@file_docbook.puts line #look into and use perhaps + puts line if @md.opt.act[:verbose_plus][:set]==:on + end + def head + rdf=SiSU_XML_Tags::RDF.new(@md) + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_docbook').stylesheet + <<-WOK + +#{stylesheet.css_head_xml} +#{rdf.comment_xml} + + WOK + end + def markup_text(data) + data.each_with_index do |o,i| + if o.is ==:heading \ + || o.is ==:para \ + || o.of ==:block \ + || o.is ==:open_close_tags + o=@trans.markup_docbook(o) #unless o.obj==nil + end + end + data + end + def tail + tail=<<-WOK + + WOK + put(tail) + end + def output(o,comment='') + puts o.lc == (0..6) \ + ? "#{spaces*o.lc}<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + end + def structure_collapsed(data) + puts "\ncollapsed structure, heading outline --->\n\n" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + output(o) + end + end + end + #def chapterlevel + #end + def xml_head + [ + '', + SiSU_Metadata::Summary.new(@md).xml_docbook.metadata, + '' + ].flatten + end + def code_output(o,ocn,filename_docbook) + filename_docbook.puts o.obj.gsub(/\n?(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\n?/m,"\n") + end + def adjust_output(o,ocn,filename_docbook,splv) + if o.obj =~/#{Xx[:split]}/ + outs=o.obj.split(/#{Xx[:split]}/) + outs.each do |out| + if out =~/
    " + : '' + id=%{ id="o#{o.ocn}" } + else + ocn,id='','' + end + if (o.is ==:heading || o.is ==:heading_insert) + chlv=(o.lv.to_i == 1) \ + ? @chlv=o.lc.to_i + : 0 + @splv=o.lc + tag_id=o.tags[0] ? %{ id="#{o.tags[0]}" } : '' + if doc_position ==:head + filename_docbook.puts %{#{spaces*o.lc}} + doc_position=:body_and_tail + else + filename_docbook.puts structure_build_tag_close(o.lc,h) + filename_docbook.puts %{#{spaces*(o.lc)}<#{tags.docbook_tag(o.lc,chlv)}#{tag_id}> +#{spaces*o.lc} +} + end + adjust_output(o,ocn,filename_docbook,@splv) + filename_docbook.puts %{#{spaces*o.lc}} + h=o.lc + elsif o.of ==:layout \ + and o.is ==:open_close_tags + xml_tag=case o.sym + when :quote_open then '
    ' + when :quote_close then '
    ' + else '' + end + unless xml_tag.empty? + filename_docbook.puts "#{spaces*(@splv)}#{xml_tag}" + end + elsif o.of ==:block + if o.is ==:table + filename_docbook.puts SiSU_Tables::TableXMLdocbook.new(o,id).table.obj + elsif o.is ==:code + filename_docbook.puts "#{spaces*(@splv)}" + filename_docbook.puts "#{spaces*(@splv+1)}" + code_output(o,ocn,filename_docbook) + filename_docbook.puts "#{spaces*(@splv+1)}" + filename_docbook.puts "#{spaces*(@splv)}" + else + filename_docbook.puts "#{spaces*(@splv)}" + adjust_output(o,ocn,filename_docbook,@splv) + filename_docbook.puts "#{spaces*(@splv)}" + end + elsif o.of ==:para + filename_docbook.puts "#{spaces*(@splv)}" + adjust_output(o,ocn,filename_docbook,@splv) + filename_docbook.puts "#{spaces*(@splv)}" + end + end + filename_docbook.puts structure_build_tag_close(0,h) + filename_docbook.close + end + def structure_build_tag_close(lc,h) + x=[] + case h + when 0 + x << "#{spaces*0}" if (lc <= 0) + when 1 + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 2 + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 3 + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 4 + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 5 + x << "#{spaces*5}" if (lc <= 5) + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*5}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 6 + x << "#{spaces*6}" if (lc <= 6) + x << "#{spaces*5}" if (lc <= 5) + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + end + x.join("\n") + end + end + end +end +__END__ +#+END_SRC + +* fictionbook2.rb + +#+BEGIN_SRC ruby :tangle "../lib/sisu/xml_fictionbook2.rb" +# <> +module SiSU_XML_Fictionbook + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + @env=@particulars.env + report + SiSU_XML_Fictionbook::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + Dir.chdir(@opt.f_pth[:pth]) + end + end + private + def report + 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.fictionbook_viewer} #{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}" + : "[#{@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], + 'Fictionbook', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Fictionbook', + 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.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}" + ).flow + end + end + end + class Scroll + def collapsed + %w[ 0 1 2 3 4 5 ] + end + def fictionbook + [ + 'section', + 'section', + 'section', + 'section', + 'section', + 'section', + 'section' + ] + end + self + end + def put(line) + puts line if @md.opt.act[:verbose_plus][:set]==:on + end + def head + version=SiSU_Env::InfoVersion.instance.get_version + rb_ver=SiSU_Env::InfoVersion.instance.rbversion + date_available=if defined? @md.date.available; "\n

    #{@md.date.available} Initial version

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

    #{@md.date.modified} Last Modified

    " + else '' + end + coverpageimage=if defined? @md.make.cover_image[:cover] + %{\n } + else '' + end + if defined? @md.authors \ + and @md.authors.length > 0 + authors=[] + @md.authors.each do |author| + authors << ' ' + if not author[:others].empty? + authors << %{ #{author[:others]}} + end + if not author[:the].empty? + authors << %{ #{author[:the]}} + end + authors << ' ' + end + authors=authors.join("\n") + end + <<-WOK + + + + + *** +#{authors} + #{@md.title.full}#{coverpageimage} + + + #{@md.date.published} + + + + + + + + #{version.project} #{version.version} and #{rb_ver} + #{version.date} + #{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest} + + 1.0 + #{date_available}#{date_modified} + + + + + WOK + end + def extract_endnotes #work on + endnotes,endnotes_raw,endnotes_b=[],[],[] + @data.each do |para| + endnotes_raw << para.obj.scan(/#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m) + endnotes_b << para.obj.scan(/#{Mx[:en_b_o]}(.+?)#{Mx[:en_b_c]}/m) + end + endnotes_raw.flatten.each do |en| + en=@trans.markup_fictionbook(en) + endnotes << en.gsub(/([\d+*]+)\s+(.+)/m, + %{
    \n +<p>\\1.</p>\n +

    \\2

    \n +
    }) + end + endnotes_raw=[] + endnotes + end + def extract_images #work on + begin + require 'base64' + rescue LoadError + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). + error('base64 NOT FOUND (LoadError)') + end + images_raw,images_base64_fb2=[],[] + images_base64={} + if defined? @md.make.cover_image[:cover] + images_raw << @md.make.cover_image[:cover] + end + @data.each do |para| + images_raw << para.obj.scan(/#{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) + end + images_raw.flatten.sort.each do |img| + imgpth=@env.url.images_local + '/' + img + open(imgpth) + if FileTest.file?(imgpth) + images_base64[img]=Base64.encode64(File.read(imgpth)) + end + end + images_raw=[] + images_base64.each_key do |k| + imgtype=case k + when /\.jpg/ then 'jpeg' + when /\.png/ then 'png' + when /\.gif/ then 'gif' + else 'jpeg' + end + images_base64_fb2 << %{#{images_base64[k]} + +} + end + images_base64_fb2.join("\n") + end + def markup_text(data) + data.each_with_index do |o,i| + if o.is ==:heading || o.is ==:para + o.obj=@trans.markup_fictionbook(o.obj,o.is) #unless o.obj==nil + end + end + data + end + def tail(images_base64_fb2) + <<-WOK + +#{images_base64_fb2} +
    + WOK + end + def output(o,comment='') + puts o.lc == (0..6) \ + ? "#{spaces*o.lc}<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + end + def structure_collapsed(data) + puts "\ncollapsed structure, heading outline --->\n\n" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + output(o) + end + end + end + def endnotes_build(endnotes,filename_fictionbook) + if endnotes.length > 0 + filename_fictionbook.puts %{} + endnotes.each do |en| + filename_fictionbook.puts SiSU_TextUtils::Wrap.new(en,80,6).line_wrap + end + end + end + def structure_build_collapsed(data,endnotes,images_base64) + file=SiSU_Env::FileOp.new(@md) + filename_fictionbook=file.write_file.xml_fictionbook + h=0 + doc_position=:head + filename_fictionbook.puts head + data.each_with_index do |o,i| + ocn=if @make.build.ocn? + (defined? o.ocn and not o.ocn.nil?) \ + ? "\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}" + : '' + else '' + end + if o.is ==:heading + unless doc_position==:head + filename_fictionbook.puts structure_build_tag_close(o.lc,h) + end + doc_position=:body_and_tail + filename_fictionbook.puts %{#{spaces*o.lc}<#{tags.fictionbook[o.lc]}> +#{spaces*o.lc} +} + filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,(o.lc*2+2)).line_wrap + filename_fictionbook.puts %{#{spaces*o.lc}} + h=o.lc + elsif o.is ==:heading_insert \ + and o.obj =~/Endnotes/ \ + and o.ln == 1 + break + elsif (o.of ==:para or o.of ==:block) + filename_fictionbook.puts SiSU_TextUtils::Wrap.new("

    #{o.obj}#{ocn}

    ",80,6).line_wrap + end + end + filename_fictionbook.puts structure_build_tag_close(0,h) + endnotes_build(endnotes,filename_fictionbook) + filename_fictionbook.puts tail(images_base64) + filename_fictionbook.close + end + def structure_build_tag_close(lc,h) + x=[] + case h + when 0 + x << "#{spaces*0}" if (lc <= 0) + when 1 + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 2 + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 3 + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 4 + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 5 + x << "#{spaces*5}" if (lc <= 5) + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 6 + x << "#{spaces*6}" if (lc <= 6) + x << "#{spaces*5}" if (lc <= 5) + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + end + x.join("\n") + end + end + end +end +__END__ +#+END_SRC + +* document header + +#+NAME: sisu_document_header +#+BEGIN_SRC text +encoding: utf-8 +- Name: SiSU + + - Description: documents, structuring, processing, publishing, search + xml + + - Author: Ralph Amissah + + + - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, + 2020, 2021, 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 + + - Homepages: + + + - Git + + + +#+END_SRC -- cgit v1.2.3