aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2012-12-29 23:47:18 -0500
committerRalph Amissah <ralph@amissah.com>2012-12-29 23:47:18 -0500
commita757467e1f69713b7318a1c10848cf4bc341778d (patch)
tree96fe6e7b62460b42f7ae81e57c2849a3415efce7
parentv4 v3: plaintext, in code blocks retain a blank empty line, a fix (diff)
v4 v3: manpage, attempt to improve output (line-spacing)
-rw-r--r--data/doc/sisu/CHANGELOG_v32
-rw-r--r--data/doc/sisu/CHANGELOG_v42
-rw-r--r--lib/sisu/v3/manpage.rb110
-rw-r--r--lib/sisu/v3/shared_txt.rb2
-rw-r--r--lib/sisu/v4/manpage.rb108
-rw-r--r--lib/sisu/v4/shared_txt.rb2
6 files changed, 117 insertions, 109 deletions
diff --git a/data/doc/sisu/CHANGELOG_v3 b/data/doc/sisu/CHANGELOG_v3
index 7c5ddb71..7bf70452 100644
--- a/data/doc/sisu/CHANGELOG_v3
+++ b/data/doc/sisu/CHANGELOG_v3
@@ -44,6 +44,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_3.3.4.orig.tar.xz
[known old bug, affects sisu_manual, fix request from SynrG on irc, re
live-manual]
+* v3: manpage, attempt to improve output (line-spacing)
+
* v3: param, minor change any legacy <br> line break in metadata markup to \\
* v3: debug (internal code use), color markers for line number & file name
diff --git a/data/doc/sisu/CHANGELOG_v4 b/data/doc/sisu/CHANGELOG_v4
index 0b9a390f..60ed276d 100644
--- a/data/doc/sisu/CHANGELOG_v4
+++ b/data/doc/sisu/CHANGELOG_v4
@@ -39,6 +39,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_4.0.1.orig.tar.xz
[known old bug, affects sisu_manual, fix request from SynrG on irc, re
live-manual]
+* v4: manpage, attempt to improve output (line-spacing)
+
* v4: param, minor change any legacy <br> line break in metadata markup to \\
* v4: debug (internal code use), color markers for line number & file name
diff --git a/lib/sisu/v3/manpage.rb b/lib/sisu/v3/manpage.rb
index 81f2ed2c..4038f875 100644
--- a/lib/sisu/v3/manpage.rb
+++ b/lib/sisu/v3/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
@@ -112,7 +113,7 @@ module SiSU_Manpage
@vz=SiSU_Env::GetInit.instance.skin
@tab="\t"
@br="\n"
- @@dostype='unix endnotes'
+ @@notes=:end
@manpage={ body: [], open: [], close: [], head: [], metadata: [], tail: [], endnotes: [] }
end
def songsheet
@@ -120,13 +121,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
@@ -142,6 +144,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
@@ -156,7 +159,7 @@ GSUB
)
end
@@endnotes[:para] << wrap
- @@endnotes[:end] << wrap << "\n.br"
+ @@endnotes[:end] << wrap << "\n.BR"
@@endnotes
end
end
@@ -229,25 +232,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
@@ -256,10 +257,10 @@ 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 #($1,$2)
+ #manpage_tail # stop call
table_message='[table omitted, see other document formats]'
fix=[]
- manpage_metadata
+ #manpage_metadata
data.each do |dob|
if dob.is==:comment \
|| dob.is==:heading_insert
@@ -272,15 +273,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]}
@@ -297,36 +305,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').
@@ -364,8 +358,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]}/,' ')
@@ -397,7 +390,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
@@ -414,12 +407,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/v3/shared_txt.rb b/lib/sisu/v3/shared_txt.rb
index 9603fda6..f8938da3 100644
--- a/lib/sisu/v3/shared_txt.rb
+++ b/lib/sisu/v3/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
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