diff options
author | Ralph Amissah <ralph@amissah.com> | 2008-07-22 20:03:57 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2008-07-22 20:03:57 -0400 |
commit | 812a2ffaf4ff90abc6225e1dde8f4fbb6c92c2c0 (patch) | |
tree | 67efd138f4f690c75efd38d75d53e1b72c0024e2 /lib/sisu/v0/xml_dom.rb | |
parent | Updated sisu-0.67.5 (diff) | |
parent | changelog and version updated (diff) |
Merge branch 'upstream' into debian/sid
Diffstat (limited to 'lib/sisu/v0/xml_dom.rb')
-rw-r--r-- | lib/sisu/v0/xml_dom.rb | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/lib/sisu/v0/xml_dom.rb b/lib/sisu/v0/xml_dom.rb index 008a8ed2..9bcb15ec 100644 --- a/lib/sisu/v0/xml_dom.rb +++ b/lib/sisu/v0/xml_dom.rb @@ -112,15 +112,15 @@ module SiSU_XML_DOM end end class Scroll - @@xml={ :body=>[],:open=>[],:close=>[],:head=>[],:sc=>[] } require "#{SiSU_lib}/shared_txt" include SiSU_text_utils @@dp=nil + @@xml={ :body=>[],:open=>[],:close=>[],:head=>[],:sc=>[] } def initialize(particulars) @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array @vz=SiSU_Env::Get_init.instance.skin @dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern - @regx=/^(?:(?:<:p[bn]>\s*)?\d~(?:(\S+))?\s+)?(.+?)\s*<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ # + @regx=/^(?:(?:#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}\s*)?#{Mx[:lv_o]}\d:(\S*)#{Mx[:lv_c]}\s*)?(.+?)\s*#{Mx[:id_o]}~(\d+);(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ @tab="\t" @trans=SiSU_XML_munge::Trans.new(@md) @sys=SiSU_Env::System_call.new @@ -133,16 +133,16 @@ module SiSU_XML_DOM end protected def xml_markup(para='') - para.gsub!(/~\{(\d+)\s+(.+?)\s*<#@dp>\}~/, + para.gsub!(/#{Mx[:en_a_o]}(\d+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/, '<endnote><number>\1</number><note>\2</note></endnote> ') - para.gsub!(/~\[([*+]\d+)\s+(.+?)\s*<#@dp>\]~/, + para.gsub!(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_b_c]}/, '<endnote><symbol>\1</symbol><note>\2</note></endnote> ') - para.gsub!(/~\{([*+]+)\s+(.+?)\s*<#@dp>\}~/, + para.gsub!(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/, '<endnote><symbol>\1</symbol><note>\2</note></endnote> ') end def xml_head(meta) txt=meta.text - txt.gsub!(/<br(?: \/)?>/,'') + txt.gsub!(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,' ') txt.gsub!(/ & /,' and ') el=meta.el.gsub(/\./,'_') el_txt=meta.el.gsub(/\./,' ') @@ -301,9 +301,9 @@ WOK ((lv+1)..6).each { |x| @level[x]=false } end def group_structure(para='',ocn='') - para.gsub!(/<:group(?:-end)?>/,'') + para.gsub!(/#{Mx[:gr_o]}group(?:-end)?#{Mx[:gr_c]}/,'') para=@trans.markup_group(para) - para.gsub!(/~\{(\d+)\s+(.+?)\s*<#@dp>\}~/m, + para.gsub!(/#{Mx[:en_a_o]}(\d+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/m, '<endnote><number>\1</number><note>\2</note></endnote> ') para.strip! @@xml[:body] << %{#{@tab*6}<object id="#{ocn}">} << "\n" @@ -314,7 +314,7 @@ WOK @@xml[:body] << "#{@tab*6}</object>" << "\n" end def poem_structure(para='',ocn='') - para.gsub!(/<:verse(?:-end)?>/,'') + para.gsub!(/#{Mx[:gr_o]}verse(?:-end)?#{Mx[:gr_c]}/,'') para=@trans.markup_group(para) para.strip! @@xml[:body] << %{#{@tab*6}<object id="#{ocn}">} << "\n" @@ -325,7 +325,7 @@ WOK @@xml[:body] << "#{@tab*6}</object>" << "\n" end def code_structure(para='',ocn='') - para.gsub!(/<:code(?:-end)?>/,'') + para.gsub!(/#{Mx[:gr_o]}code(?:-end)?#{Mx[:gr_c]}/,'') para=@trans.markup_group(para) para.gsub!(/\s\s/,'  ') para.strip! @@ -344,82 +344,82 @@ WOK end def markup(data) xml_sc(@md) - @rcdc=false @level,@cont,@copen,@xml_contents_close=[],[],[],[] + @rcdc=false (0..6).each { |x| @cont[x]=@level[x]=false } (4..6).each { |x| @xml_contents_close[x]='' } data.each do |para| para=@trans.markup(para) @trans.char_enc.utf8(para) if @sys.locale =~/utf-?8/i #% utf8 - if para =~/^0~(\S+)\s+(.+?)$/ # for headers + if para =~/^#{Rx[:meta]}\s*(.+?)$/ # for headers d_meta=SiSU_text_utils::Header_scan.new(@md,para).meta if d_meta; xml_head(d_meta) end end if @rcdc==false \ and (para =~/~metadata/ \ - or para =~/1~meta\s+Document Information/) + or para =~/#{Mx[:lv_o]}1:meta#{Mx[:lv_x]}\s*Document Information/) @rcdc=true end - if para !~/(^0~|<ENDNOTES>|<EOF>)/ - if para =~/.+?<~\d+;(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ + if para !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + if para =~/.+?#{Mx[:id_o]}~\d+;(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ paranum=para[@regx,3] @p_num=SiSU_XML_format::Paragraph_number.new(@md,paranum) end - @sto=SiSU_text_parts::Split_text_object.new(@md,para).lev_segname_para_ocn + @sto=SiSU_text_parts::Split_text_object.new(@md,para).xml ### problem in scroll, it appears tables are getting paragraph numbers unless @rcdc - m=/<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ + m=/#{Mx[:id_o]}~(\d+);(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ if para =~m - format_scroll=SiSU_XML_format::Format_scroll.new(@md,@sto.text) if @sto.format =~/i[12]|null/ + format_scroll=SiSU_XML_format::Format_scroll.new(@md,@sto.text) if @sto.format =~/i[1-9]|null/ case @sto.format - when /^(1)~(?:(\S+))?/ + when /^(1):(\S*)/ xml_markup(para) xml_structure($1,@sto.ocn,para,$2) para=@sto.lev_para_ocn.heading_body1 #if para =~m - when /^(2)~(?:(\S+))?/ + when /^(2):(\S*)/ xml_markup(para) xml_structure($1,@sto.ocn,para,$2) para=@sto.lev_para_ocn.heading_body2 #if para =~m - when /^(3)~(?:(\S+))?/ + when /^(3):(\S*)/ xml_markup(para) xml_structure($1,@sto.ocn,para,$2) para=@sto.lev_para_ocn.heading_body3 #if para =~m - when /^(4)~(\S+)/ # work on see SiSU_text_parts::Split_text_object + when /^(4):(\S+)/ # work on see SiSU_text_parts::Split_text_object xml_markup(para) xml_structure($1,@sto.ocn,para,$2) para=@sto.lev_para_ocn.heading_body4 #if para =~m - when /^(5)~(?:(\S+))?/ + when /^(5):(\S*)/ xml_markup(para) xml_structure($1,@sto.ocn,para,$2) para=@sto.lev_para_ocn.heading_body5 #if para =~m - when /^(6)~(?:(\S+))?/ + when /^(6):(\S*)/ xml_markup(para) xml_structure($1,@sto.ocn,para,$2) para=@sto.lev_para_ocn.heading_body6 #if para =~m else - matched=/<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/mi.match(para) + matched=/#{Mx[:id_o]}~(\d+);(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/mi.match(para) stamp,ocn=matched[0],matched[1] - if para =~ /<:verse>/ + if para =~ /#{Mx[:gr_o]}verse#{Mx[:gr_c]}/ para.gsub!(/#{stamp}/,'') poem_structure(para,ocn) - elsif para =~ /<:group>/ + elsif para =~ /#{Mx[:gr_o]}group#{Mx[:gr_c]}/ para.gsub!(/#{stamp}/,'') group_structure(para,ocn) - elsif para =~ /<:code>/ + elsif para =~ /#{Mx[:gr_o]}code#{Mx[:gr_c]}/ para.gsub!(/#{stamp}/,'') code_structure(para,ocn) - elsif para =~/<!Th?.+/ # tables come as single block #work area 2005w13 + elsif para =~/#{Mx[:gr_o]}Th?.+/ # tables come as single block #work area 2005w13 table=SiSU_Tables::Table_xml.new(para,ocn) para=table.table_split @@xml[:body] << table_structure(para,ocn) else #xml_structure(para, nil, nil, nil) type=case para - when /^\s*(?:<:i([1-9])> )?_\*/ + when /^\s*(?:#{Mx[:pa_o]}:i([1-9])#{Mx[:pa_c]}\s*)?#{Mx[:gl_bullet]}/ m=$1 - para.gsub!(/^(\s*(?:<:i[1-9]> )?)_\*/,'\1') + para.gsub!(/^(\s*(?:#{Mx[:pa_o]}:i([1-9])#{Mx[:pa_c]}\s*)?)#{Mx[:gl_bullet]}/,'\1') "indent_bullet#{m}" - when /^\s*<:i([1-9])>/; "indent#{$1}" + when /^\s*#{Mx[:pa_o]}:i([1-9])#{Mx[:pa_c]}/; "indent#{$1}" else 'norm' end xml_markup(para) @@ -432,16 +432,16 @@ WOK @@xml[:body] << "#{@tab*6}</object>" << "\n" if para[@regx] end end - elsif para =~/(Note|Endnotes?)/ \ - and para !~/<~\d+;(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ + elsif para =~/(#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ \ + and para !~/#{Mx[:id_o]}~\d+;(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ #format_scroll=MonoSiSU.new('<br /><a name="notes">Note</a>') #para=format_scroll.boldPara elsif para =~/(MetaData)/ \ - and para =~/<~\d+;[m]\d+;\w\d+><#@dp:#@dp>$/ #debug 2003w46 add rc info + and para =~/#{Mx[:id_o]}~\d+;[m]\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ #debug 2003w46 add rc info format_scroll=Format_scroll.new(@md,'<br /><a name="metadata">MetaData</a>') para=format_scroll.bold_para elsif para =~/(Owner Details)/ \ - and para !~/<~\d+;(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ + and para !~/#{Mx[:id_o]}~\d+;(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/ format_scroll=Format_scroll.new(@md,'<br /><a name="owner.details">Owner Details</a>') @@xml[:owner_details]=format_scroll.bold_para para='' @@ -455,8 +455,7 @@ WOK para='' end if para =~/.*<:#>.*$/ - para=case para - when /<:i[1-9]>/ + para=if para =~ /#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/ format_text=Format_text_object.new(para,'') format_text.scr_inden_ocn_e_no_paranum end @@ -471,8 +470,7 @@ WOK end else # end - para.gsub!(/<:\S+?>/,'') - para.gsub!(/<!.+!>/,' ') ## Clean Prepared Text + para.gsub!(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') if para end end @content_flag=true @@ -535,8 +533,7 @@ WOK filename_xml=SiSU_Env::SiSU_file.new(@md,@md.fn[:dom]).mkfile @data.each do |para| #para.strip! - para.gsub!(/<:\S+?>/,'') - para.gsub!(/<!.+?!>/,'') + para.gsub!(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') #; para.gsub!(/<:\S+?>|<!.+?!>/,'') para="#{para}\n" unless para.empty? filename_xml.puts para end |