class SiSU_ConvertFootnotes::Make
Public Class Methods
new(md,data)
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 179 def initialize(md,data) @md,@data=md,data @@word_mode=[] @env=SiSU_Env::InfoEnv.new(@md.fns) l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language @language=l[:n] @translate=SiSU_Translate::Source.new(@md,@language) end
Public Instance Methods
reset()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 187 def reset @@counter=@@column=@@columns=@@flag_vocab=0 @@endnote={} @@endnote_array=@@word_mode=[] @@endnote_call_counter=1 @@line_mode='' end
song()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 194 def song reset data=@data @metafile="#{@env.processing_path.ao}/#{@md.fns}.meta" SiSU_Env::CreateFile.new(@md.fns) data=data.join.split("\n\n") data_new=[] data.each do |x| data_new << (x =~ /\n\n/m) \ ? (x.split(/\n\n+/)) : x end data=data_new.flatten data=SiSU_ConvertFootnotes::Make.new(@md,data).character_check data=SiSU_ConvertFootnotes::Make.new(@md,data).endnotes SiSU_ConvertFootnotes::Output.new(@md,data).hard_output reset data end
Protected Instance Methods
character_check()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 228 def character_check reset data=@data @tuned_file=[] endnote_no=1 data.each do |para| para.strip! para.gsub!(/^[{~}]\s*$/,'') para.gsub!(/^#{@@comment}.*/,'') #remove comment and divider #% para.gsub!(/<~#>|~#\s*/,'~#') para.gsub!(/-#\s*/,'-#') para.gsub!(/(~\{ )\s+/,'\1') para.gsub!(/ \/\//,'<br />') #added 2004w29 para.gsub!(/<br>/,'<br />') #needed by xml, xhtml etc. para.gsub!(/`/,"'") para.gsub!(/\342\200\231/,"'") #if para =~/’/ #Avoid #‘ ’ #“ ” para.gsub!(/\t/,' ') para.gsub!(/�/,' ') #watch, replace with char code para.gsub!(/[“”]/,'""') para.gsub!(/[–—]/,'-') #— – chk para.gsub!(/·/,'*') para.gsub!(/\\copy(?:right)?\b/,'©') para.gsub!(/\\trademark\b|\\tm\b/,'®') para.gsub!(/\44/,'$') #$ watch para=para + "\n" case para when /\^~/ # endnotes #% Note must do this first (earlier loop) and then enter gathered data into ~^\d+ sub_para=para.dup @@endnote_array << sub_para.gsub!(/\n/,'').gsub!(/\^~\s+(.+)\s*/,'~{ \1 }~').strip endnote_no+=1 para=nil if para =~/\^~ .+/ #removes 'binary' endnote now in endnote array for later insertion end @tuned_file << para unless para.nil? end @tuned_file end
endnote_call_number()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 400 def endnote_call_number data=@data data.each do |word| case word when /~\{/ unless word =~/~\{\*+/ @@endnote_call_counter+=1 end when /~\^|<:e>/ word.gsub!(/~\^|<:e>/,"#{@@endnote_array[@@endnote_call_counter-1]}") @@endnote_call_counter+=1 end end end
endnotes()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 378 def endnotes #% endnote work zone data=@data @tuned_file=[] endnote_ref=1 data.each do |para| case para # manually numbered endnotes <!e(\d)!> <!e_(\d)!> --> when /~\{\s+.+?\}~/ # auto-numbered endnotes <!e!> <!e_!> --> para.gsub!(/\s*\}~/,' }~') # required 2003w31 @word_mode=para.scan(/\S+/) word_mode=SiSU_ConvertFootnotes::Make.new(@md,@word_mode).endnote_call_number para=word_mode.join(' ') endnote_ref+=1 when /~\^(?:\s|$)|<:e>/ #%Note inserts endnotes previously gathered from /^(<!e[:_]!>|[-~]\{{3})/ (in earlier loop) word_mode=para.scan(/\S+/) word_mode=SiSU_ConvertFootnotes::Make.new(@md,word_mode).endnote_call_number para=word_mode.join(' ') endnote_ref+=1 end @tuned_file << para end @tuned_file end
name_endnote_seg()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 265 def name_endnote_seg data=@data @tuned_file=[] data.each do |para| para.gsub!(/<:3>\s*<:ee>/, "#{@@endnote['special_align']} <p /><br />\r " + "#{@@endnote['seg_name_3']} <p /> " + "#{@@endnote['special_align_close']}") para.gsub!(/<:2>\s*<:ee>/, "#{@@endnote['special_align']} <p /><br />\r " + "#{@@endnote['seg_name_2']} <p />" + "#{@@endnote['special_align_close']}") para.gsub!(/<:1>\s*<:ee>/, "#{@@endnote['special_align']} <p /><br />\r " + "#{@@endnote['seg_name_1']} <p /> " + "#{@@endnote['special_align_close']}") @tuned_file << para end if @md.flag_auto_endnotes \ and @md.flag_separate_endnotes_make @tuned_file << "\n1~endnotes Endnotes" #prob numbering, revisit end @tuned_file << "\n<ENDNOTES>" @tuned_file end
number_sub_heading(para,num,title_no)
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 293 def number_sub_heading(para,num,title_no) case para when /#{num}~- / then para.gsub!(/#{num}~- /,"#{title_no} ") when /^#{num}~#\s*/ then para.gsub!(/^#{num}~#\s*/,"#{title_no} ") when /^#{num}~[a-z_\.]+ / para.gsub!(/^#{num}~([a-z_\.]+)\s+(.+)/i,%{#{num}~\\1 #{title_no} \\2 <:name##{title_no}>}) else para.gsub!(/^#{num}~ /,"#{num}~#{title_no} #{title_no} ") #main end if @md.toc_lev_limit \ and @md.toc_lev_limit < num para.gsub!(/^[2-6]~(?:~\S+)?\s*/,'!_ ') end para end
owner_details_seg()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 290 def owner_details_seg data << '1~owner.details Owner Details' end
set_header_title()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 356 def set_header_title #% make sure no false positives unless @md.set_header_title if (@md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) puts "\t no document title provided, (will have to manufacture one)" end data=@data @tuned_file=[] data.each do |para| unless @md.set_header_title if para !~/^%{1,2}\s/m \ and para !~/\A\s*\Z/m @tuned_file << "0~title #{@md.heading_seg_first}" @md.title.full=@md.heading_seg_first @md.set_header_title=true end end @tuned_file << para end @tuned_file end end
set_heading_seg()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 331 def set_heading_seg #% make sure no false positives unless @md.set_heading_seg if (@md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) puts "\tdocument contains no segment level, (will have to manufacture one)" end data=@data @tuned_file=[] data.each do |para| unless @md.set_heading_seg if para !~/^(?:@\S+:|0~\S+|:[ABC]~)/m \ and para !~/\A\s*\Z/m \ and para !~/<:p[bn]>/ @md.set_heading_seg=true head=(@md.title.full) \ ? ("1~seg [#{@md.title.full}]") : ('1~seg [segment]') @tuned_file << head end end @tuned_file << para end @tuned_file end end
set_heading_top()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 307 def set_heading_top #% make sure no false positives unless @md.set_heading_top if (@md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) puts "\tdocument contains no top level heading, (will have to manufacture one)" end data=@data @tuned_file=[] data.each do |para| unless @md.set_heading_top if para !~/^(?:@\S+:|0~\S+)\s/m \ and para !~/\A\s*\Z/m @md.set_heading_top=true head=(@md.title.full) \ ? (":A~ #{@md.title.full}") : (':A~ [no title provided]') @tuned_file << head end end @tuned_file << para end @tuned_file end end
strip_clean_extra_spaces(s)
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 414 def strip_clean_extra_spaces(s) # ao output tuned s=s.dup s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') s=s.gsub(/ [ ]+/,' ') s=s.gsub(/^ [ ]+/,'') s=s.gsub(/ [ ]+$/,'') s=s.gsub(/(<\/[bi]>')[ ]+(s )/,'\1\2') end
strip_clean_of_markup(s)
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 422 def strip_clean_of_markup(s) # used for digest, define rules, make same as in db clean s=s.dup s=s.gsub(/(?:<\/?[ib]>|^:[A-C]~\S+|^[1-6]~\S+|~\{\d+\s.+?\}~)/,'') # markup and endnotes removed #% same as db clean --> s=s.gsub(/<del>(.+?)<\/del>/,'DELETED(\1)') # deletions s=s.gsub(/<sup>(\d+)<\/sup>/,'[\1]') s=s.gsub(/(?: \\;|#{Mx[:nbsp]})+/,' ') #checking source Mx not necessary s=s.gsub(/\{.+?\.(?:png|jpg|gif).+?\}(?:https?|file|ftp)\\\:\S+ /,' [image] ') # else image names found in search s=s.gsub(/#{Mx[:lnk_o]}.+?\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [image] ') # else image names found in search, re-check s=s.gsub(/\s\s+/,' ') s=s.strip end
vocabulary()
click to toggle source
# File lib/sisu/sst_do_inline_footnotes.rb, line 214 def vocabulary data=@data tuned_file,vocab_insert=[],[] data.each do |para| if para =~/^1~/ \ and @@flag_vocab==0 vocab_insert << '@vocabulary: lex' << "\n\n" << para tuned_file << vocab_insert unless para.nil? @@flag_vocab=1 else tuned_file << para unless para.nil? end end tuned_file end