From 85ec6bab386b1e9b1ccbcab1fd97e6529b020032 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:16:24 -0500 Subject: v5: minor code related to line-breaks --- data/doc/sisu/CHANGELOG_v5 | 2 ++ lib/sisu/v5/manpage.rb | 22 ++++++++++---------- lib/sisu/v5/odf.rb | 21 ++++++++++--------- lib/sisu/v5/odf_format.rb | 32 ++++++++++++++++------------- lib/sisu/v5/plaintext.rb | 50 ++++++++++++++++++++++++---------------------- lib/sisu/v5/shared_txt.rb | 6 ++++-- 6 files changed, 74 insertions(+), 59 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index d223b5b4..46fb9927 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -36,6 +36,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.1.0.orig.tar.xz * dal endnotes, removed a space that should no longer be necessary, testing required +* minor code related to line breaks, various locations + %% 5.0.25.orig.tar.xz (2013-11-08:44/5) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/sisu_5.0.25 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/debian/sisu_5.0.25-1 diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 3e430b55..44180819 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -120,7 +120,6 @@ module SiSU_Manpage @brace_url=SiSU_Viz::Defaults.new.url_decoration @vz=SiSU_Viz::Defaults.new @tab="\t" - @br="\n" @@notes=:end @manpage={ body: [], open: [], close: [], head: [], metadata: [], tail: [], endnotes: [] } end @@ -128,6 +127,9 @@ module SiSU_Manpage manpage=markup(@data) publish(manpage) end + def break_line + "\n" + end # Used for extraction of endnotes from paragraphs def extract_endnotes(dob='') para=dob.obj.gsub(/#{Mx[:br_line]}/,"\n") @@ -176,7 +178,7 @@ GSUB end def manpage_tail @manpage[:tail] <<< 78 @manpage[:body] << case lv - when 1; '.SH ' << wrapped.upcase << @br << @br - when 2..3; '.SH ' << wrapped.upcase << @br << @br - when 4; '.SH ' << wrapped.upcase << @br << @br - when 5..6; '.SH ' << wrapped.upcase << @br << @br + when 1; '.SH ' << wrapped.upcase << break_line << break_line + when 2..3; '.SH ' << wrapped.upcase << break_line << break_line + when 4; '.SH ' << wrapped.upcase << break_line << break_line + when 5..6; '.SH ' << wrapped.upcase << break_line << break_line end else @manpage[:body] << if wrapped =~/^\.BI\s/ # main text, contents, body KEEP - '.TP' << @br << wrapped.gsub(/(^\.B)I\s/,'\1 ') # sleight ... simpler output (check gsub!) + '.TP' << break_line << wrapped.gsub(/(^\.B)I\s/,'\1 ') # sleight ... simpler output (check gsub!) else - @br + '.BR' + @br << wrapped + break_line + '.BR' + break_line << wrapped end end if @@endnotes[:para] \ and @@notes==:foot #edit out to switch off endnotes following paragraph to which they belong - @@endnotes[:para].each { |e| @manpage[:body] << e << @br } + @@endnotes[:para].each { |e| @manpage[:body] << e << break_line } elsif @@endnotes[:para] \ and @@notes==:end end @@ -349,7 +351,7 @@ WOK manpage_structure(dob) else if dob.obj =~/#{table_message}/ - @manpage[:body] << dob.obj << @br + @manpage[:body] << dob.obj << break_line end end if (dob.obj =~// \ diff --git a/lib/sisu/v5/odf.rb b/lib/sisu/v5/odf.rb index 5e277992..2bc7de01 100644 --- a/lib/sisu/v5/odf.rb +++ b/lib/sisu/v5/odf.rb @@ -121,7 +121,6 @@ module SiSU_ODF @brace_url=SiSU_Viz::Defaults.new.url_decoration @br=(@md.opt.act[:maintenance][:set]==:on) \ ? '' : '' - #@br=(@md.opt.cmd =~/M/) ? "\n" : '' end def songsheet begin @@ -139,6 +138,10 @@ module SiSU_ODF end end end + def break_line + (@md.opt.act[:maintenance][:set]==:on) \ + ? "\n" : '' + end # Used for extraction of endnotes from paragraphs def extract_endnotes(dob='') notes=dob.obj.scan(/#{Mx[:en_a_o]}(\d+\s+.+?)#{Mx[:en_a_c]}/)[1] #FIX @@ -556,26 +559,26 @@ module SiSU_ODF end end if dob.is==:heading - @@odf[:body] << heading(dob,p_num).obj << @br*2 + @@odf[:body] << heading(dob,p_num).obj << break_line*2 if SiSU_Env::ProcessingSettings.new(md).build.toc? if dob.lv =~/[A-C1]/i @@odf[:toc] << toc(dob,p_num).obj end end elsif dob.is ==:verse - @@odf[:body] << poem(dob,p_num).obj << @br*2 + @@odf[:body] << poem(dob,p_num).obj << break_line*2 elsif dob.is==:group - @@odf[:body] << group(dob,p_num).obj << @br*2 + @@odf[:body] << group(dob,p_num).obj << break_line*2 elsif dob.is==:block - @@odf[:body] << block(dob,p_num).obj << @br*2 + @@odf[:body] << block(dob,p_num).obj << break_line*2 elsif dob.is==:code - @@odf[:body] << code(dob,p_num).obj << @br*2 + @@odf[:body] << code(dob,p_num).obj << break_line*2 elsif dob.is==:table #elsif dob.obj =~ /#{@p_num[:set_ref]}#{tag}#{@br}} + - %{#{@br}} + %{#{@p_num[:set_ref]}#{tag}#{break_line}} + + %{#{break_line}} end def table_close(tablefoot='') '' \ @@ -206,16 +210,16 @@ module SiSU_ODF_Format else 'P_table_cell' end str=str.gsub(/^~$/,'') # tilde / empty cell - %{#{@br}} + - %{#{@br}} + + %{#{break_line}} + + %{#{break_line}} + %{#{str}} + - %{#{@br}} + - %{#{@br}} + %{#{break_line}} + + %{#{break_line}} end def table_tag_row(str,i) - %{#{@br}} + + %{#{break_line}} + %{#{str}} + - %{#{@br}} + %{#{break_line}} end def table_tag_row_dump(str,i) txt_name_row=if i==0 \ @@ -223,13 +227,13 @@ module SiSU_ODF_Format 'Table_Heading' else 'P_table_cell' end - %{#{@br}} + - %{#{@br}} + - %{#{@br}} + + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} + %{#{str}} + - %{#{@br}} + - %{#{@br}} + - %{#{@br}} + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} end def table_row(row,i) row='' if row =~/^ @wrap_width @plaintext[:body] << case lv - when 1; wrapped.upcase << @br << decorate.heading_underscore.l1*times + p_num << @br*2 - when 2; wrapped.upcase << @br << decorate.heading_underscore.l2*times + p_num << @br*2 - when 3; wrapped.upcase << @br << decorate.heading_underscore.l3*times + p_num << @br*2 - when 4; wrapped.upcase << @br << decorate.heading_underscore.l4*times + p_num << @br*2 - when 5; wrapped.upcase << @br << decorate.heading_underscore.l5*times + p_num << @br*2 - when 6; wrapped.upcase << @br << decorate.heading_underscore.l6*times + p_num << @br*2 + when 1; wrapped.upcase << break_line << decorate.heading_underscore.l1*times + p_num << break_line*2 + when 2; wrapped.upcase << break_line << decorate.heading_underscore.l2*times + p_num << break_line*2 + when 3; wrapped.upcase << break_line << decorate.heading_underscore.l3*times + p_num << break_line*2 + when 4; wrapped.upcase << break_line << decorate.heading_underscore.l4*times + p_num << break_line*2 + when 5; wrapped.upcase << break_line << decorate.heading_underscore.l5*times + p_num << break_line*2 + when 6; wrapped.upcase << break_line << decorate.heading_underscore.l6*times + p_num << break_line*2 end else - @plaintext[:body] << wrapped + p_num << @br # main text, contents, body KEEP + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP end if @@endnotes[:para] \ and not @@endnotes_ - @@endnotes[:para].each {|e| @plaintext[:body] << e << @br} + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} elsif @@endnotes[:para] \ and @@endnotes_ end @@ -403,7 +405,7 @@ WOK plaintext_metadata table_message='[table omitted, see other document formats]' data.each do |dob| - dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{@br}#{table_message}"). #fix + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, "#{decorate.bold.open}\\1#{decorate.bold.close}"). @@ -449,8 +451,8 @@ WOK end dob.obj=if dob.of==:block # watch 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) + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) end if dob.is==:code dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< @@ -479,17 +481,17 @@ WOK or dob.is==:verse \ or dob.is==:code \ or dob.is==:table - @plaintext[:body] << dob.obj + p_num << @br + @plaintext[:body] << dob.obj + p_num << break_line elsif dob.is==:break sp=' ' ln='-' @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ or dob.obj==Mx[:br_page_new] \ or dob.obj==Mx[:br_page_line] - "#{@br}#{ln*40}#{@br*2}" + "#{break_line}#{ln*40}#{break_line*2}" elsif dob.obj ==Mx[:br_obj] - "#{@br}#{sp*20}* * *#{@br*2}" - end # following empty line (@br) missing, fix + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix end dob='' if (dob.obj =~// \ and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote @@ -508,9 +510,9 @@ WOK content << plaintext[:head] content << plaintext[:body] content << @@endnotes[:end] if @@endnotes_ - content << "#{@br}#{divider*@wrap_width}#{@br}" + content << "#{break_line}#{divider*@wrap_width}#{break_line}" content << plaintext[:metadata] - content << "#{@br}#{divider*@wrap_width}#{@br}" if @md.stmp =~/\w+/ #not used? + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? content << plaintext[:tail] Output.new(content,@md).plaintext @@endnotes={ para: [], end: [] } diff --git a/lib/sisu/v5/shared_txt.rb b/lib/sisu/v5/shared_txt.rb index 8e8e7edb..0e3b6018 100644 --- a/lib/sisu/v5/shared_txt.rb +++ b/lib/sisu/v5/shared_txt.rb @@ -64,12 +64,14 @@ module SiSU_TextUtils def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil) @para,@n_char_max,@n_indent=para,n_char_max,n_indent @n_char_max_extend = n_char_max - @br="\n" @n_hang=n_hang ? n_hang : @n_indent end + def break_line + "\n" + end def line_wrap space=' ' - spaces_indent,spaces_hang="#{@br}#{space*@n_indent}",space*@n_hang + spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang line=0 out=[] out[line]='' -- cgit v1.2.3