# encoding: utf-8 =begin * Name: SiSU ** Description: documents, structuring, processing, publishing, search ** xml template ** Author: Ralph Amissah ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah, All Rights Reserved. ** License: GPL 3 or later: SiSU, a framework for document structuring, publishing and search Copyright (C) Ralph Amissah This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . If you have Internet connection, the latest version of the GPL should be available at these locations: ** SiSU uses: * Standard SiSU markup syntax, * Standard SiSU meta-markup syntax, and the * Standard SiSU object citation numbering and system ** Hompages: ** Git =end 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 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