aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-12-02 23:16:24 -0500
committerRalph Amissah <ralph@amissah.com>2013-12-02 23:16:24 -0500
commit85ec6bab386b1e9b1ccbcab1fd97e6529b020032 (patch)
tree8fb513d342d11cd2cca54ce3256e12559b36db78 /lib/sisu/v5
parentv5: dal_endnotes, removed a space that should no longer be necessary (diff)
v5: minor code related to line-breaks
Diffstat (limited to 'lib/sisu/v5')
-rw-r--r--lib/sisu/v5/manpage.rb22
-rw-r--r--lib/sisu/v5/odf.rb21
-rw-r--r--lib/sisu/v5/odf_format.rb32
-rw-r--r--lib/sisu/v5/plaintext.rb50
-rw-r--r--lib/sisu/v5/shared_txt.rb6
5 files changed, 72 insertions, 59 deletions
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] <<<<WOK
-#{@br}
+#{break_line}
.TP
.SH SEE ALSO
sisu(1),
@@ -235,21 +237,21 @@ WOK
times=wrapped.length
times=78 if times > 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 =~/<a name="n\d+">/ \
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 =~ /<!Th?¡/u
- @@odf[:body] << table(dob,p_num).obj << @br*2
+ @@odf[:body] << table(dob,p_num).obj << break_line*2
elsif dob.is==:break
- @@odf[:body] << obj_break(dob).obj << @br*2
+ @@odf[:body] << obj_break(dob).obj << break_line*2
else
- @@odf[:body] << normal(dob,p_num).obj << @br*2 # main text, contents, body KEEP
+ @@odf[:body] << normal(dob,p_num).obj << break_line*2 # main text, contents, body KEEP
end
@@endnotes_para=[]
end
diff --git a/lib/sisu/v5/odf_format.rb b/lib/sisu/v5/odf_format.rb
index 28c69c44..3d40f943 100644
--- a/lib/sisu/v5/odf_format.rb
+++ b/lib/sisu/v5/odf_format.rb
@@ -170,6 +170,10 @@ module SiSU_ODF_Format
@@fns=@md.fns
end
end
+ def break_line
+ (@md.opt.act[:maintenance][:set]==:on) \
+ ? "\n" : ''
+ end
def table_head_open(count)
type=(@dob.head_) \
? 1
@@ -192,8 +196,8 @@ module SiSU_ODF_Format
else 'D'
end
tag=SiSU_ODF_Format::Tags.new.set_bookmark_tag(@dob)
- %{<table:table table:name="Table#{count}" table:style-name="Table#{type}">#{@p_num[:set_ref]}#{tag}#{@br}} +
- %{<table:table-column table:style-name="Table#{type}.#{alpha}" table:number-columns-repeated="#{@dob.cols}"/>#{@br}}
+ %{<table:table table:name="Table#{count}" table:style-name="Table#{type}">#{@p_num[:set_ref]}#{tag}#{break_line}} +
+ %{<table:table-column table:style-name="Table#{type}.#{alpha}" table:number-columns-repeated="#{@dob.cols}"/>#{break_line}}
end
def table_close(tablefoot='')
'</table:table>' \
@@ -206,16 +210,16 @@ module SiSU_ODF_Format
else 'P_table_cell'
end
str=str.gsub(/^~$/,'') # tilde / empty cell
- %{<table:table-cell office:value-type="string">#{@br}} +
- %{<text:p text:style-name="#{txt_name_cell}">#{@br}} +
+ %{<table:table-cell office:value-type="string">#{break_line}} +
+ %{<text:p text:style-name="#{txt_name_cell}">#{break_line}} +
%{#{str}} +
- %{</text:p>#{@br}} +
- %{</table:table-cell>#{@br}}
+ %{</text:p>#{break_line}} +
+ %{</table:table-cell>#{break_line}}
end
def table_tag_row(str,i)
- %{<table:table-row>#{@br}} +
+ %{<table:table-row>#{break_line}} +
%{#{str}} +
- %{</table:table-row>#{@br}}
+ %{</table:table-row>#{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
- %{<table:table-row>#{@br}} +
- %{<table:table-cell office:value-type="string">#{@br}} +
- %{<text:p text:style-name="#{txt_name_row}">#{@br}} +
+ %{<table:table-row>#{break_line}} +
+ %{<table:table-cell office:value-type="string">#{break_line}} +
+ %{<text:p text:style-name="#{txt_name_row}">#{break_line}} +
%{#{str}} +
- %{</text:p>#{@br}} +
- %{</table:table-cell>#{@br}} +
- %{</table:table-row>#{@br}}
+ %{</text:p>#{break_line}} +
+ %{</table:table-cell>#{break_line}} +
+ %{</table:table-row>#{break_line}}
end
def table_row(row,i)
row='' if row =~/^<!$/
diff --git a/lib/sisu/v5/plaintext.rb b/lib/sisu/v5/plaintext.rb
index b82013aa..49c198e7 100644
--- a/lib/sisu/v5/plaintext.rb
+++ b/lib/sisu/v5/plaintext.rb
@@ -133,13 +133,15 @@ module SiSU_Plaintext
when /--endnote/; true
else true
end
- @br="\n"
@plaintext={ body: [], open: [], close: [], head: [], metadata: [], tail: [] }
end
def songsheet
plaintext=markup(@data)
publish(plaintext)
end
+ def break_line
+ "\n"
+ end
# Used for extraction of endnotes from paragraphs
def extract_endnotes(dob='')
notes=dob.obj.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/)
@@ -198,18 +200,18 @@ WOK
lastdone="Last Generated on: #{Time.now}"
rubyv="Ruby version: #{@md.ruby_version}"
sc=if @md.sc_info
- "Source file: #{@md.sc_filename}#{@br}Version number: #{@md.sc_number}#{@br}Version date: #{@md.sc_date}#{@br}"
+ "Source file: #{@md.sc_filename}#{break_line}Version number: #{@md.sc_number}#{break_line}Version date: #{@md.sc_date}#{break_line}"
else ''
end
@plaintext[:tail] <<<<WOK
-#{@br}
+#{break_line}
plaintext (plain text):
- #{@md.file.output_path.txt.url}/#{@md.file.base_filename.txt}#{@br}
-Other versions of this document: #{@br}
+ #{@md.file.output_path.txt.url}/#{@md.file.base_filename.txt}#{break_line}
+Other versions of this document: #{break_line}
manifest:
- #{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}#{@br}
+ #{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}#{break_line}
at:
- #{@md.file.output_path.base.url}#{@br}
+ #{@md.file.output_path.base.url}#{break_line}
#{sc}
* #{generator}
@@ -376,19 +378,19 @@ WOK
times=wrapped.length
times=@wrap_width if times > @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 =~/<a name="n\d+">/ \
and dob.obj =~/^(-\{{2}~\d+|<!e[:_]\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]=''