aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v4')
-rw-r--r--lib/sisu/v4/manpage.rb108
-rw-r--r--lib/sisu/v4/shared_txt.rb2
2 files changed, 56 insertions, 54 deletions
diff --git a/lib/sisu/v4/manpage.rb b/lib/sisu/v4/manpage.rb
index 34df23cd..eec73707 100644
--- a/lib/sisu/v4/manpage.rb
+++ b/lib/sisu/v4/manpage.rb
@@ -73,8 +73,9 @@ module SiSU_Manpage
def initialize(opt)
@opt=opt
if @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/
- @@dostype='unix endnotes'
- else puts "#{sf} not a processed file type"
+ @@notes=:end
+ else
+ puts "#{sf} not a processed file type"
end
end
def read
@@ -111,7 +112,7 @@ module SiSU_Manpage
@vz=SiSU_Viz::Defaults.new
@tab="\t"
@br="\n"
- @@dostype='unix endnotes'
+ @@notes=:end
@manpage={ body: [], open: [], close: [], head: [], metadata: [], tail: [], endnotes: [] }
end
def songsheet
@@ -119,13 +120,14 @@ module SiSU_Manpage
publish(manpage)
end
# Used for extraction of endnotes from paragraphs
- def extract_endnotes(para='')
- notes=para.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)\s*(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m)
+ def extract_endnotes(dob='')
+ para=dob.obj.gsub(/#{Mx[:br_line]}/,"\n")
+ notes=para.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+(?:\s|\n)+.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m)
@n=[]
notes.flatten.each do |n| #high cost to deal with <br> appropriately within manpage, consider
n=n.dup.to_s
- if n =~/#{Mx[:br_line]}/
- fix = n.split(/\s*#{Mx[:br_line]}+\s*/) #watch #added
+ if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/
+ fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added
fix.each do |x|
unless x.empty?; @n << x
end
@@ -141,6 +143,7 @@ module SiSU_Manpage
wrap=util.line_wrap
wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m
wrap.gsub(/(^|&nbsp;|#{Mx[:nbsp]}|\s|\*)\\\*/,'\1\\\\\*'). #man page requires
+ gsub(/\s(.[BI])\s/,' ').
gsub(/\s\.(\S+)/,' \\.\1').
gsub(/^\s*([\d*+]+)\s+(.+?)\s*\Z/m, <<GSUB
.TP
@@ -155,7 +158,7 @@ GSUB
)
end
@@endnotes[:para] << wrap
- @@endnotes[:end] << wrap << "\n.br"
+ @@endnotes[:end] << wrap << "\n.BR"
@@endnotes
end
end
@@ -232,25 +235,23 @@ 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
+ 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
end
else
@manpage[:body] << if wrapped =~/^\.BI\s/ # main text, contents, body KEEP
- '.TP' << @br << wrapped.gsub(/^\.BI\s/,'.B ') # sleight ... simpler output (check gsub!)
+ '.TP' << @br << wrapped.gsub(/(^\.B)I\s/,'\1 ') # sleight ... simpler output (check gsub!)
else
- '.br' << @br << wrapped
+ @br + '.BR' + @br << wrapped
end
end
if @@endnotes[:para] \
- and @@dostype =~/footnote/ #edit out to switch off endnotes following paragraph to which they belong
- @manpage[:body] << @br
+ and @@notes==:foot #edit out to switch off endnotes following paragraph to which they belong
@@endnotes[:para].each { |e| @manpage[:body] << e << @br }
elsif @@endnotes[:para] \
- and @@dostype =~/endnote/
- @manpage[:body] << @br*2
+ and @@notes==:end
end
@@endnotes[:para]=[]
end
@@ -259,7 +260,7 @@ WOK
@data_mod,@endnotes,@level,@cont,@copen,@manpage_contents_close=Array.new(6){[]}
(0..6).each { |x| @cont[x]=@level[x]=false }
(4..6).each { |x| @manpage_contents_close[x]='' }
- #manpage_tail #stop call
+ #manpage_tail # stop call
table_message='[table omitted, see other document formats]'
fix=[]
#manpage_metadata
@@ -275,15 +276,22 @@ WOK
gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'--\1--').
gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"').
gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1').
- gsub(/\A\s*#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}#{Mx[:br_line]}([,.:!?](?: |$))?/m,"#{Mx[:br_line]}.I \\1\\2#{Mx[:br_line]}").
- gsub(/\s*#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}([,.:!?](?: |$))?/m,"#{Mx[:br_line]}.I \\1\\2#{Mx[:br_line]}").
- gsub(/\A\s*#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}([,.:!?](?: |$))?#{Mx[:br_line]}/m,"#{Mx[:br_line]}.BI \\1\\2#{Mx[:br_line]}").
- gsub(/\s*#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}([,.:!?](?: |$))?/,"#{Mx[:br_line]}.B \\1\\2#{Mx[:br_line]}").
- gsub(/\s*#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}([,.:!?](?: |$))?/,"#{Mx[:br_line]}.I \\1\\2#{Mx[:br_line]}")
+ gsub(/\A\s*#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}#{Mx[:br_line]}([,.:!?](?: |$))?/m,
+ "#{Mx[:br_line]}.I \\1\\2#{Mx[:br_line]}").
+ gsub(/\s*#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}([,.:!?](?: |$))?/m,
+ "#{Mx[:br_line]}.I \\1\\2#{Mx[:br_line]}").
+ gsub(/\A\s*#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}([,.:!?](?: |$))?#{Mx[:br_line]}/m,
+ "\n.BI \\1\\2#{Mx[:br_line]}").
+ gsub(/\s*#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}([,.:!?](?: |$))?/m,
+ "#{Mx[:br_line]}.B \\1\\2#{Mx[:br_line]}").
+ gsub(/\s*#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}([,.:!?](?: |$))?/,
+ "\n.I \\1\\2#{Mx[:br_line]}")
unless dob.is==:code
- dob.obj=dob.obj.gsub(/(?:^|\s)#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}([,.:!?](?: |$))?/,"\\1 #{@brace_url.txt_open}\\2#{@brace_url.txt_close}\\3").
- gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}([,.:!?](?: |$))?/,"\\1#{@brace_url.txt_open}\\2#{@brace_url.txt_close}\\3")
- @manpage[:endnotes]=extract_endnotes(dob.obj)
+ dob.obj=dob.obj.gsub(/(?:^|\s)#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}([,.:!?](?: |$))?/,
+ "\\1 #{@brace_url.txt_open}\\2#{@brace_url.txt_close}\\3").
+ gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}([,.:!?](?: |$))?/,
+ "\\1#{@brace_url.txt_open}\\2#{@brace_url.txt_close}\\3")
+ @manpage[:endnotes]=extract_endnotes(dob)
dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s*(?:.+?)#{Mx[:en_a_c]}/m,'[^\1]'). # endnote marker marked up
gsub(/#{Mx[:en_b_o]}([\d*+]+)\s*(?:.+?)#{Mx[:en_b_c]}/m,'[^\1]'). # endnote marker marked up
gsub(/#{Mx[:gl_o]}#amp#{Mx[:gl_c]}/,'&'). ##{Mx[:gl_o]}#095#{Mx[:gl_c]}
@@ -300,36 +308,22 @@ WOK
gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©')
else
dob.obj=dob.obj.gsub(/\\/,'\e').
- gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,"\n\n") # watch
- #dob.obj.gsub!(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})+\s*/,"\n") # watch
+ gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,"\n") # watch
end
dob.obj=dob.obj.gsub(/(^|&nbsp;|#{Mx[:nbsp]}|\s|\*)\\\*/,'\1\\\\\*'). #man page requires
gsub(/┆/,'|').
- gsub(/\s\.(\S+)/,' \\.\1').
- gsub(/(\n\.)(\S\S\S+)/m,'\1\\.\2').
- gsub(/-/,'\-') #manpages use this
+ gsub(/^(\.\S{3,})/m,' \1') # ^\. used by interpreter, disable when use not intended
dob.obj=dob.obj.gsub(/&#126;/,'~') if dob.obj #manpages use this
- if dob.is =~/block|group|verse|alt|code/
- if dob.is ==:code
- dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _<
- gsub(/(^|[^}])_([<>])/m,'\1\2'). # _<_<
- gsub(/\A(.+)?\Z/m,".nf\n\n\\1\n\n.fi")
- end
+ if dob.is ==:code
+ dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _<
+ gsub(/(^|[^}])_([<>])/m,'\1\2'). # _<_<
+ gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})+(\s*)/m,"\n\\1"). # watch
+ gsub(/\A(.+?)\s*\Z/m,".nf\n\\1\n.fi")
end
- #dob.obj.gsub!(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})+\s*/m,"\n.br\n") # watch
dob.obj=dob.obj.gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})+\s*/m,"\n\n") # watch
blit=dob.obj.scan(/\[[^\]]+\]|[^\[]+/)
blit_array=[]
- blit.each do |x|
- x=if x =~/^\[/
- x.gsub(/\s+/,' \ ') #manpages use this
- else x
- end
- blit_array << x
- end
- dob.obj=blit_array.join
dob.obj=dob.obj.gsub(/#{Mx[:gl_o]}:name#\S+?#{Mx[:gl_c]}/mi,''). #added
- #gsub(/\s\\\s+(#{Mx[:br_line]}|#{Mx[:br_nl]})/,'\1'). #a messy solution
gsub(/#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}/,''). # remove page breaks
gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1\2').
gsub(/<a href=".+?">(.+?)<\/a>/m,'\1').
@@ -367,8 +361,7 @@ WOK
dob.obj=''
end
if dob.obj
- dob.obj=dob.obj.gsub(/\s(\[)/m,' \ \1').
- gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,"\n\n"). # watch
+ dob.obj=dob.obj.gsub(/(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,"\n\n"). # watch
gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~').
gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').
gsub(/#{Mx[:pa_o]}\S+#{Mx[:pa_c]}/,' ')
@@ -400,7 +393,7 @@ WOK
content << manpage[:open]
content << manpage[:head]
content << manpage[:body]
- content << @@endnotes[:end] if @@dostype =~/endnotes/
+ content << @@endnotes[:end] if @@notes==:end
content << manpage[:metadata]
content << manpage[:tail]
Output.new(@md,content).manpage
@@ -417,12 +410,21 @@ WOK
SiSU_Env::FileOp.new(@md).mkdir
filename_manpage=SiSU_Env::FileOp.new(@md).write_file.manpage
@sisu=[]
+ emptyline=0
@content.each do |para| # this is a hack
if para.is_a?(Array) \
and para.length > 0
para.each do |line|
- line=line.gsub(/\s+$/m,'')
- filename_manpage.puts line #unix manpage
+ if line
+ line=line.gsub(/[ \t]+$/m,'').
+ gsub(/^\A[ ]*\Z/m,'')
+ (line=~/^\A\Z/) \
+ ? (emptyline+=1)
+ : emptyline=0
+ if emptyline < 2 #remove additional empty lines
+ filename_manpage.puts line #unix manpage
+ end
+ end
end
else filename_manpage.puts para #unix manpage # /^([*=-]|\.){5}/
end
diff --git a/lib/sisu/v4/shared_txt.rb b/lib/sisu/v4/shared_txt.rb
index 4e5c659f..343b70b5 100644
--- a/lib/sisu/v4/shared_txt.rb
+++ b/lib/sisu/v4/shared_txt.rb
@@ -71,7 +71,7 @@ module SiSU_TextUtils
out[line]=''
@para=@para.gsub(/<br>/,' \\ ').
gsub(/#{Mx[:br_nl]}/,"\n\n")
- words=@para.scan(/\n\n|<br>|\S+/m)
+ words=@para.scan(/\n\n|\s+\\\s+|<br>|\S+/m)
while words != ''
word=words.shift
if not word