From d88d970f3ca0e87fed5e6f4195e969fc941ac4f3 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 17 Feb 2010 10:58:01 -0500 Subject: plaintext fix for footnotes/endnotes footnotes to occur immediately after paragraph that contains them (unless endnotes selected instead) --- lib/sisu/v1/plaintext.rb | 61 ++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/lib/sisu/v1/plaintext.rb b/lib/sisu/v1/plaintext.rb index dd2964d9..540c1bce 100644 --- a/lib/sisu/v1/plaintext.rb +++ b/lib/sisu/v1/plaintext.rb @@ -22,7 +22,7 @@ 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 + 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 @@ -73,20 +73,8 @@ module SiSU_Plaintext class Source def initialize(opt) @opt=opt - @@dostype=if @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ - if @opt.mod.inspect =~ /--footnote/ \ - and @opt.mod.inspect =~ /--dos/ - 'msdos footnotes' - elsif @opt.mod.inspect =~ /--endnote/ \ - and @opt.mod.inspect =~ /--dos/ - 'msdos endnotes' - elsif @opt.mod.inspect =~ /--footnote/ - 'unix footnotes' - elsif @opt.mod.inspect =~ /--endnote/ - 'unix endnotes' - else 'unix footnotes' - end - else puts "#{sf} not a processed file type" + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" end end def read @@ -123,23 +111,15 @@ module SiSU_Plaintext @dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern @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]}$/m # 2004w18 pb pn removal added @tab="\t" - @br=if md.mod.inspect =~ /--footnote/ \ - and md.mod.inspect =~ /--dos/ - @@dostype='msdos footnotes' - "\r\n" - elsif md.mod.inspect =~ /--endnote/ \ - and md.mod.inspect =~ /--dos/ - @@dostype='msdos endnotes' - "\r\n" - elsif md.mod.inspect =~ /--footnote/ - @@dostype='unix footnotes' - "\n" - elsif md.mod.inspect =~ /--endnote/ - @@dostype='unix endnotes' - "\n" - else - @@dostype='unix footnotes' - "\n" + @@endnotes_=case md.mod.inspect + when /--footnote/; false + when /--endnote/; true + else true + end + @br=case md.mod.inspect + when /--dos/; "\r\n" + when /--unix/; "\n" + else "\n" end @plaintext={ :body=>[],:open=>[],:close=>[],:head=>[],:metadata=>[],:tail=>[] } end @@ -255,11 +235,11 @@ WOK @plaintext[:body] << wrapped << @br # main text, contents, body KEEP end if @@endnotes[:para] \ - and @@dostype =~/footnote/ #edit out to switch off endnotes following paragraph to which they belong + and not @@endnotes_ @plaintext[:body] << @br @@endnotes[:para].each {|e| @plaintext[:body] << e << @br} elsif @@endnotes[:para] \ - and @@dostype =~/endnote/ + and @@endnotes_ @plaintext[:body] << @br*2 end @@endnotes[:para]=[] @@ -391,11 +371,6 @@ WOK if para !~/#{@vz.margin_txt_0}|#{@vz.margin_txt_1}|#{@vz.margin_txt_2}/ # i don't get the condition for no paranum end - #if para =~/<:center>/ - # one,two=/(.*)<:center>(.*)/.match(para)[1,2] - # format_text=Format_text_object.new(one,two) - # para=format_text.center - #end para.gsub!(/#{Mx[:id_o]}.+?#{Mx[:id_c]}/,' ') if para ## Clean Prepared Text para.gsub!(//,' ') if para ## Clean Prepared Text para.gsub!(/<:\S+>/,' ') if para ## Clean Prepared Text @@ -409,8 +384,8 @@ WOK content << plaintext[:open] content << plaintext[:head] content << plaintext[:body] - content << @@endnotes[:end] if @@dostype =~/endnotes/ - content << "#@br#{divider*78}#@br" + content << @@endnotes[:end] if @@endnotes_ + content << "#{@br}#{divider*78}#{@br}" content << plaintext[:metadata] content << "#@br#{divider*78}#@br" if @md.stmp =~/\w+/ #not used? content << plaintext[:owner_details] if @md.stmp =~/\w+/ #not used? @@ -430,13 +405,13 @@ WOK file_plaintext=SiSU_Env::SiSU_file.new(@md,@md.fn[:plain]).mkfile @sisu=[] @content.each do |para| # this is a hack - if para.class == Array \ + if para.class==Array \ and para.length > 0 para.each do |line| line.gsub!(/\s+$/m,'') file_plaintext.puts line #unix plaintext end - else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ end end file_plaintext.close -- cgit v1.2.3