From c9898a09a6faf75856628e0470f764cb901c0a3f Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 29 Dec 2012 23:35:47 -0500 Subject: v4 v3: plaintext, in code blocks retain a blank empty line, a fix * [known old bug, affects sisu_manual, fix request from SynrG on irc, re live-manual] --- lib/sisu/v3/plaintext.rb | 53 +++++++++++++++++++++-------------------------- lib/sisu/v3/shared_txt.rb | 2 +- lib/sisu/v4/plaintext.rb | 51 ++++++++++++++++++++------------------------- lib/sisu/v4/shared_txt.rb | 2 +- 4 files changed, 49 insertions(+), 59 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v3/plaintext.rb b/lib/sisu/v3/plaintext.rb index c86fddb9..1869bb3e 100644 --- a/lib/sisu/v3/plaintext.rb +++ b/lib/sisu/v3/plaintext.rb @@ -100,7 +100,7 @@ module SiSU_Plaintext else 78 end #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 - SiSU_Plaintext::Source::Scroll.new(dal_array,md,wrap_width).songsheet + SiSU_Plaintext::Source::Scroll.new(md,dal_array,wrap_width).songsheet SiSU_Env::InfoSkin.new(md).select #watch rescue SiSU_Errors::InfoError.new($!,$@,@opt.cmd,@opt.fns).error do @@ -113,10 +113,10 @@ module SiSU_Plaintext class Scroll @wrap_width @plaintext[:body] << case lv - when 1; wrapped.upcase << @br << Px[:lv1]*times + p_num << @br - when 2; wrapped.upcase << @br << Px[:lv2]*times + p_num << @br - when 3; wrapped.upcase << @br << Px[:lv3]*times + p_num << @br - when 4; wrapped.upcase << @br << Px[:lv4]*times + p_num << @br - when 5; wrapped.upcase << @br << Px[:lv5]*times + p_num << @br - when 6; wrapped.upcase << @br << Px[:lv6]*times + p_num << @br + when 1; wrapped.upcase << @br << Px[:lv1]*times + p_num << @br*2 + when 2; wrapped.upcase << @br << Px[:lv2]*times + p_num << @br*2 + when 3; wrapped.upcase << @br << Px[:lv3]*times + p_num << @br*2 + when 4; wrapped.upcase << @br << Px[:lv4]*times + p_num << @br*2 + when 5; wrapped.upcase << @br << Px[:lv5]*times + p_num << @br*2 + when 6; wrapped.upcase << @br << Px[:lv6]*times + p_num << @br*2 end else @plaintext[:body] << wrapped + p_num << @br # main text, contents, body KEEP end if @@endnotes[:para] \ and not @@endnotes_ - @plaintext[:body] << @br @@endnotes[:para].each {|e| @plaintext[:body] << e << @br} elsif @@endnotes[:para] \ and @@endnotes_ - @plaintext[:body] << @br*2 end @@endnotes[:para]=[] end @@ -326,9 +320,9 @@ WOK gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') end dob.obj=if dob.of==:block # watch - dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/,"* "). - gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n") - else dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n\n") + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,@br) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,@br*2) end if dob.is==:code dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< @@ -413,14 +407,15 @@ WOK and para.length > 0 para.each do |line| if line - line.gsub!(/\s+$/m,'') - line.gsub!(/^\A[ ]*\Z/m,'') - if line=~/^\A[ ]*\Z/m - emptyline+=1 - else emptyline=0 + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line end - file_plaintext.puts line if emptyline < 2 #remove extra line spaces (fix upstream) - end + end end else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ end diff --git a/lib/sisu/v3/shared_txt.rb b/lib/sisu/v3/shared_txt.rb index 228109c1..9603fda6 100644 --- a/lib/sisu/v3/shared_txt.rb +++ b/lib/sisu/v3/shared_txt.rb @@ -69,7 +69,7 @@ module SiSU_TextUtils line=0 out=[] out[line]='' - @para=@para.gsub(/
/,'
'). + @para=@para.gsub(/
/,' \\ '). gsub(/#{Mx[:br_nl]}/,"\n\n") words=@para.scan(/\n\n|
|\S+/m) while words != '' diff --git a/lib/sisu/v4/plaintext.rb b/lib/sisu/v4/plaintext.rb index 29f62ee1..e6ab20f4 100644 --- a/lib/sisu/v4/plaintext.rb +++ b/lib/sisu/v4/plaintext.rb @@ -100,7 +100,7 @@ module SiSU_Plaintext else 78 end #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 - SiSU_Plaintext::Source::Scroll.new(dal_array,md,wrap_width).songsheet + SiSU_Plaintext::Source::Scroll.new(md,dal_array,wrap_width).songsheet rescue SiSU_Errors::InfoError.new($!,$@,@opt.cmd,@opt.fns).error do __LINE__.to_s + ':' + __FILE__ @@ -114,8 +114,8 @@ module SiSU_Plaintext require_relative 'shared_txt' # shared_txt.rb include SiSU_TextUtils @@endnotes={ para: [], end: [] } - def initialize(data,md,wrap_width) - @data,@md,@wrap_width=data,md,wrap_width + def initialize(md,data,wrap_width) + @md,@data,@wrap_width=md,data,wrap_width @env=SiSU_Env::InfoEnv.new(@md.fns) @brace_url=SiSU_Viz::Defaults.new.url_decoration @tab="\t" @@ -124,11 +124,7 @@ module SiSU_Plaintext when /--endnote/; true else true end - @br=case md.opt.mod.inspect - when /--dos/; "\r\n" - when /--unix/; "\n" - else "\n" - end + @br="\n" @plaintext={ body: [], open: [], close: [], head: [], metadata: [], tail: [] } end def songsheet @@ -222,8 +218,8 @@ WOK n3=lv + 2 end util=nil - wrapped=if dob.is ==:para \ - or dob.is==:heading + wrapped=if dob.is==:para \ + || dob.is==:heading if dob.is==:para if dob.hang \ and dob.hang =~/[0-9]/ \ @@ -249,23 +245,21 @@ WOK times=wrapped.length times=@wrap_width if times > @wrap_width @plaintext[:body] << case lv - when 1; wrapped.upcase << @br << Px[:lv1]*times + p_num << @br - when 2; wrapped.upcase << @br << Px[:lv2]*times + p_num << @br - when 3; wrapped.upcase << @br << Px[:lv3]*times + p_num << @br - when 4; wrapped.upcase << @br << Px[:lv4]*times + p_num << @br - when 5; wrapped.upcase << @br << Px[:lv5]*times + p_num << @br - when 6; wrapped.upcase << @br << Px[:lv6]*times + p_num << @br + when 1; wrapped.upcase << @br << Px[:lv1]*times + p_num << @br*2 + when 2; wrapped.upcase << @br << Px[:lv2]*times + p_num << @br*2 + when 3; wrapped.upcase << @br << Px[:lv3]*times + p_num << @br*2 + when 4; wrapped.upcase << @br << Px[:lv4]*times + p_num << @br*2 + when 5; wrapped.upcase << @br << Px[:lv5]*times + p_num << @br*2 + when 6; wrapped.upcase << @br << Px[:lv6]*times + p_num << @br*2 end else @plaintext[:body] << wrapped + p_num << @br # main text, contents, body KEEP end if @@endnotes[:para] \ and not @@endnotes_ - @plaintext[:body] << @br @@endnotes[:para].each {|e| @plaintext[:body] << e << @br} elsif @@endnotes[:para] \ and @@endnotes_ - @plaintext[:body] << @br*2 end @@endnotes[:para]=[] end @@ -324,9 +318,9 @@ WOK gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') end dob.obj=if dob.of==:block # watch - dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/,"* "). - gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n") - else dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n\n") + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,@br) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,@br*2) end if dob.is==:code dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< @@ -411,14 +405,15 @@ WOK and para.length > 0 para.each do |line| if line - line.gsub!(/\s+$/m,'') - line.gsub!(/^\A[ ]*\Z/m,'') - if line=~/^\A[ ]*\Z/m - emptyline+=1 - else emptyline=0 + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line end - file_plaintext.puts line if emptyline < 2 #remove extra line spaces (fix upstream) - end + end end else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ end diff --git a/lib/sisu/v4/shared_txt.rb b/lib/sisu/v4/shared_txt.rb index 6876dabd..4e5c659f 100644 --- a/lib/sisu/v4/shared_txt.rb +++ b/lib/sisu/v4/shared_txt.rb @@ -69,7 +69,7 @@ module SiSU_TextUtils line=0 out=[] out[line]='' - @para=@para.gsub(/
/,'
'). + @para=@para.gsub(/
/,' \\ '). gsub(/#{Mx[:br_nl]}/,"\n\n") words=@para.scan(/\n\n|
|\S+/m) while words != '' -- cgit v1.2.3