aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/plaintext.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v0/plaintext.rb')
-rw-r--r--lib/sisu/v0/plaintext.rb142
1 files changed, 79 insertions, 63 deletions
diff --git a/lib/sisu/v0/plaintext.rb b/lib/sisu/v0/plaintext.rb
index ddcf3a42..886e50a2 100644
--- a/lib/sisu/v0/plaintext.rb
+++ b/lib/sisu/v0/plaintext.rb
@@ -70,12 +70,12 @@ module SiSU_Plaintext
class Source
def initialize(opt)
@opt=opt
- if @opt.fns =~/(.+?)\.[_-]?sst$/
- case @opt.cmd
- when /[af]/; @@dostype='unix footnotes'
- when /e/; @@dostype='unix endnotes'
- when /[AF]/; @@dostype='msdos footnotes'
- when /E/; @@dostype='msdos endnotes'
+ @@dostype=if @opt.fns =~/(.+?)\.[_-]?sst$/
+ if @opt.mod.inspect =~ /--footnote/ and @opt.mod.inspect =~ /--dos/; 'msdos footnotes'
+ elsif @opt.mod.inspect =~ /--endnote/ and @opt.mod.inspect =~ /--dos/; 'msdos endnotes'
+ elsif @opt.mod.inspect =~ /--footnote/; 'unix footnotes'
+ elsif @opt.mod.inspect =~ /--endnote/; 'unix endnotes'
+ else 'unix footnotes'
end
else puts "#{sf} not a processed file type"
end
@@ -153,36 +153,36 @@ module SiSU_Plaintext
require "#{SiSU_lib}/defaults"
require "#{SiSU_lib}/shared_txt"
include SiSU_text_utils
- @@endnotes_para=[]
- @@plaintext={ :body=>[],:open=>[],:close=>[],:head=>[],:metadata=>[],:tail=>[],:endnotes=>[] }
+ @@endnotes={ :para=>[],:end=>[] }
@@dp=nil
def initialize(data,md)
@data,@md=data,md
@url_brace=SiSU_Viz::Skin.new.url_decoration
@vz=SiSU_Env::Get_init.instance.skin
@dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern
- @regx=/^(?:(?:<:p[bn]>\s*)?\d~(?:(\S+))?\s+)?(.+?)\s*<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/ #m # 2004w18 pb pn removal added
+ @regx=/^(?:(?:<:p[bn]>\s*)?\d~(?:(\S+))?\s+)?(.+?)\s*<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/m # 2004w18 pb pn removal added
@tab="\t"
- @br=case md.cmd
- when /[af]/
- @@dostype='unix footnotes'
- "\n"
- when /e/
- @@dostype='unix endnotes'
- "\n"
- when /[AF]/
+ @br=if md.mod.inspect =~ /--footnote/ and md.mod.inspect =~ /--dos/
@@dostype='msdos footnotes'
"\r\n"
- when /E/
+ elsif md.mod.inspect =~ /--endnote/ and md.mod.inspect =~ /--dos/
@@dostype='msdos endnotes'
"\r\n"
- else "\n"
+ elsif md.mod.inspect =~ /--footnote/
+ @@dostype='unix footnotes'
+ "\n"
+ elsif md.mod.inspect =~ /--endnote/
+ @@dostype='unix endnotes'
+ "\n"
+ else
+ @@dostype='unix footnotes'
+ "\n"
end
+ @plaintext={ :body=>[],:open=>[],:close=>[],:head=>[],:metadata=>[],:tail=>[] }
end
def songsheet
- @data=markup(@data)
- publish
- #@data.each { |x| puts x.inspect if x =~/\[table/ }
+ plaintext=markup(@data)
+ publish(plaintext)
end
# Used for extraction of endnotes from paragraphs
def extract_endnotes(para='')
@@ -201,13 +201,12 @@ module SiSU_Plaintext
end
notes=@n.flatten
notes.each do |e|
- util=if e.to_s =~/^\[[\d*+]+\]:/; SiSU_text_utils::Wrap.new(e.to_s,70,4,1)
- else SiSU_text_utils::Wrap.new(e.to_s,70,1,1)
+ util=if e.to_s =~/^\[[\d*+]+\]:/; SiSU_text_utils::Wrap.new(e.to_s,78,4,1)
+ else SiSU_text_utils::Wrap.new(e.to_s,78,1,1)
end
wrap=util.line_wrap
if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m
wrap.gsub!(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<GSUB
-
\\1[\\2]: \\3
GSUB
)
@@ -217,14 +216,15 @@ GSUB
GSUB
)
end
- @@plaintext[:endnotes] << wrap
- @@endnotes_para << wrap
+ @@endnotes[:para] << "-#{wrap}"
+ @@endnotes[:end] << wrap
end
+ @@endnotes
end
def plaintext_metadata(meta)
- util=SiSU_text_utils::Wrap.new(meta.text,70,15,1)
+ util=SiSU_text_utils::Wrap.new(meta.text,78,15,1)
txt=util.line_wrap
- @@plaintext[:metadata] <<= if meta.type == 'meta'
+ @plaintext[:metadata] <<= if meta.type == 'meta'
<<WOK
#{@tab}#{meta.el}: #{txt}
@@ -242,7 +242,7 @@ WOK
"Source file: #{@md.sc_filename}#{@br}Version number: #{@md.sc_number}#{@br}Version date: #{@md.sc_date}#{@br}"
else ''
end
- @@plaintext[:tail] <<<<WOK
+ @plaintext[:tail] <<<<WOK
#@br
Other versions of this document: #@br
manifest:
@@ -269,37 +269,35 @@ WOK
n=lv - 1
n3=lv + 2
lv=nil if lv == 0
- extract_endnotes(para)
- para.gsub!(/~[{\[]([\d*+]+)\s+(?:.+?)[}\]]~/,'[^\1]') # endnote marker marked up
wrapped=if para[@regx]
paragraph=para[@regx,2]
if paragraph =~/<:i([1-9])>/
m=$1.to_i
paragraph.gsub!(/<:i#{m}>/,'')
- util=SiSU_text_utils::Wrap.new(paragraph,70,m*2)
- else util=SiSU_text_utils::Wrap.new(paragraph,70,0)
+ util=SiSU_text_utils::Wrap.new(paragraph,78,m*2)
+ else util=SiSU_text_utils::Wrap.new(paragraph,78,0)
end
util.line_wrap
end
if lv
times=wrapped.length
- times=70 if times > 70
- @@plaintext[:body] << case lv
+ times=78 if times > 78
+ @plaintext[:body] << case lv
when 1; wrapped.upcase << @br << '*'*times << @br
when 2..3; wrapped.upcase << @br << '='*times << @br
when 4; wrapped.upcase << @br << '-'*times << @br
when 5..6; wrapped.upcase << @br << '.'*times << @br
end
else
- @@plaintext[:body] << wrapped << @br # main text, contents, body KEEP
+ @plaintext[:body] << wrapped << @br # main text, contents, body KEEP
end
- if @@endnotes_para and @@dostype =~/footnote/ #edit out to switch off endnotes following paragraph to which they belong
- @@plaintext[:body] << @br
- @@endnotes_para.each {|e| @@plaintext[:body] << e << @br}
- elsif @@endnotes_para and @@dostype =~/endnote/
- @@plaintext[:body] << @br*2
+ if @@endnotes[:para] and @@dostype =~/footnote/ #edit out to switch off endnotes following paragraph to which they belong
+ @plaintext[:body] << @br
+ @@endnotes[:para].each {|e| @plaintext[:body] << e << @br}
+ elsif @@endnotes[:para] and @@dostype =~/endnote/
+ @plaintext[:body] << @br*2
end
- @@endnotes_para=[]
+ @@endnotes[:para]=[]
end
def markup(data) # Used for major markup instructions
dir=SiSU_Env::Info_env.new(@md.fns)
@@ -313,29 +311,44 @@ WOK
para.gsub!(/<!Th?¡.+/m,"#@br#{table_message}")
para.gsub!(/.+?<-#>/,'') # remove dummy headings (used by html) #check
para.gsub!(/_\*\s+/,'* ') # bullet markup, marked down
- #para.gsub!(/<br(?: \/)?>/,"\n") # introduces a bug
- para.gsub!(/&#169;/,'©') # bullet markup, marked down
- para.gsub!(/&amp;/,'&') # bullet markup, marked down
para.gsub!(/<sup>(.+?)<\/sup>/,'^\1^')
para.gsub!(/<sub>(.+?)<\/sub>/,'[\1]')
para.gsub!(/<i>(.+?)<\/i>/,'/\1/')
para.gsub!(/<b>(.+?)<\/b>/,'*\1*')
para.gsub!(/<u>(.+?)<\/u>/,'_\1_')
+ unless para =~/<:code>/
+ para.gsub!(/\{(.+?)\}((?:https?|file|ftp):\/\/\S+|image)/,'\1 [link:] \2')
+ para.gsub!(/(^|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([.,]?(?:\s|$))/,"\\1#{@url_brace.txt_open}\\2#{@url_brace.txt_close}\\3")
+ para.gsub!(/_((?:https?|file|ftp):\/\/\S+)/,'\1')
+ extract_endnotes(para)
+ para.gsub!(/~[{\[]([\d*+]+)\s+(?:.+?)[}\]]~/,'[^\1]') # endnote marker marked up
+ para.gsub!(/&amp;/,'&')
+ para.gsub!(/&#033;/,'!')
+ para.gsub!(/&#035;/,'#')
+ para.gsub!(/&#042;/,'*')
+ para.gsub!(/&#045;/,'-')
+ para.gsub!(/&#047;/,'/')
+ para.gsub!(/&#095;/,'_')
+ para.gsub!(/&#123;/,'{')
+ para.gsub!(/&#125;/,'}')
+ para.gsub!(/&#126;/,'~')
+ para.gsub!(/&#169;/,'©')
+ end
if para =~/<:(?:group|verse|alt|code)(?:-end)?>(?:\s+<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>)?/
if para =~/<:code>/
para.gsub!(/_</,'<'); para.gsub!(/_>/m,'>') #code-block: angle brackets special characters
end
para.gsub!(/<br(?: \/)?>/,"\n") # watch
para.gsub!(/<:(?:group|verse|alt|code)(?:-end)?>(?:\s+<~(\d+);(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>)?/,'')
+ else para.gsub!(/<br(?: \/)?>/,"\n\n") # watch introduces a bug
end
para.gsub!(/<:p[bn]>/,'') # remove page breaks
para.gsub!(/^\s*<~\d+;(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/,'') # remove empty lines - check
- para.gsub!(/(^|\s)((?:https?|ftp):\/\/\S+?\.[^'"><\s]+?)([.,]?(?:\s|$))/,"\\1#{@url_brace.txt_open}\\2#{@url_brace.txt_close}\\3")
- para.gsub!(/(^|\s)[_\\]((?:https?|ftp):\/\/\S+?\.[^'"><\s]+?)([.,]?(?:\s|$))/,'\1\2\3')
+ para.gsub!(/(^|\s)[_\\]((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([.,]?(?:\s|$))/,'\1\2\3')
para.gsub!(/<a href=".+?">(.+?)<\/a>/m,'\1')
para.gsub!(/<:name#\S+?>/,'') # remove name links
para.gsub!(/&nbsp;/,' ') # decide on
- para.gsub!(/\{(\S+?\.(?:png|jpg|gif)) .+?\}(?:(?:https?|ftp):\/\/\S+|image)/,' [ \1 ]') #"[ #{dir.url.images_local}\/\\1 ]")
+ para.gsub!(/\{(\S+?\.(?:png|jpg|gif)) .+?\}(?:(?:https?|file|ftp):\/\/\S+|image)/,' [ \1 ]') #"[ #{dir.url.images_local}\/\\1 ]")
para.gsub!(/^\{\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]')
wordlist=para.scan(/\S+/)
if para =~/^0~(\S+)\s+(.+?)\Z/m # for headers
@@ -395,14 +408,14 @@ WOK
para
end
elsif para =~/#{table_message}/
- @@plaintext[:body] << para << @br
+ @plaintext[:body] << para << @br
elsif para =~/(Note|Endnotes?)/ and para !~/<~\d+;(?:\w|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/
elsif para =~/(MetaData)/ and para =~/<~(\d+);[um]\d+;\w\d+><#@dp:#@dp>$/ #debug 2003w46 add rc info ####suspect visit
#formatMono=MonoSiSU.new('<br /><a name="metadata">MetaData</a>')
#para=formatMono.bold_para
elsif para.include? 'Owner Details' and para !~/<~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+><#@dp:#@dp>$/
#formatMono=MonoSiSU.new('<br /><a name="owner.details">Owner Details</a>')
- #@@plaintext[:owner_details]=formatMono.bold_para
+ #@plaintext[:owner_details]=formatMono.bold_para
#para=''
elsif para =~/(¡|<!Th?)/ #tables !
elsif para =~/(.*)<!#!>(.*)/
@@ -430,21 +443,22 @@ WOK
para.gsub!(/<:\S+>/,' ') if para ## Clean Prepared Text
end
end
+ @plaintext
end
- def publish
- divider="="
+ def publish(plaintext)
+ divider='='
content=[]
- content << @@plaintext[:open]
- content << @@plaintext[:head]
- content << @@plaintext[:body]
- content << @@plaintext[:endnotes] if @@dostype =~/endnotes/
- content << "#@br#{divider*70}#@br"
- content << @@plaintext[:metadata]
- content << "#@br#{divider*70}#@br" if @md.stmp =~/\w+/ #not used?
- content << @@plaintext[:owner_details] if @md.stmp =~/\w+/ #not used?
- content << @@plaintext[:tail]
+ content << plaintext[:open]
+ content << plaintext[:head]
+ content << plaintext[:body]
+ content << @@endnotes[:end] if @@dostype =~/endnotes/
+ content << "#@br#{divider*78}#@br"
+ content << plaintext[:metadata]
+ content << "#@br#{divider*78}#@br" if @md.stmp =~/\w+/ #not used?
+ content << plaintext[:owner_details] if @md.stmp =~/\w+/ #not used?
+ content << plaintext[:tail]
Output.new(content,@md).plaintext
- @@plaintext[:head],@@plaintext[:body],@@plaintext[:tail],@@plaintext[:metadata]=[],[],[],[]
+ @@endnotes[:para],@@endnotes[:end]=[],[]
end
end
class Output <Source
@@ -466,8 +480,10 @@ WOK
else filename_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/
end
end
+ filename_plaintext.close
end
end
end
end
__END__
+&#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#