aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v3dv/dal_doc_str.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v3dv/dal_doc_str.rb')
-rw-r--r--lib/sisu/v3dv/dal_doc_str.rb137
1 files changed, 68 insertions, 69 deletions
diff --git a/lib/sisu/v3dv/dal_doc_str.rb b/lib/sisu/v3dv/dal_doc_str.rb
index dbf4f066..91fa9458 100644
--- a/lib/sisu/v3dv/dal_doc_str.rb
+++ b/lib/sisu/v3dv/dal_doc_str.rb
@@ -131,11 +131,11 @@ module SiSU_DAL_DocumentStructureExtract
if str.nil?
else
if str =~/(?:^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/
- str.gsub!(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i,
- "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}")
- str.gsub!(/ [ ]+/i,' ')
+ str=str.gsub(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i,
+ "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}").
+ gsub(/ [ ]+/i,' ')
tags=str.scan(/#{Mx[:tag_o]}(\S+?)#{Mx[:tag_c]}/).flatten
- str.gsub!(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks?
+ str=str.gsub(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks?
end
tags=nametag ? (tags << nametag) : tags
end
@@ -148,7 +148,7 @@ module SiSU_DAL_DocumentStructureExtract
@@counter,@verse_count=0,0
@metadata={}
@data.each do |t_o|
- t_o.gsub!(/(?:\n\s*\n)+/m,"\n") unless @@flag['code']
+ t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") unless @@flag['code']
if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \
and not @@flag['code'] \
and not @@flag['poem'] \
@@ -158,7 +158,7 @@ module SiSU_DAL_DocumentStructureExtract
and not @@flag['table']
unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any
idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1
- t_o.gsub!(/\n=\{.+\}\s*$\Z/m,'')
+ t_o=t_o.gsub(/\n=\{.+\}\s*$\Z/m,'')
m
else nil
end
@@ -304,7 +304,7 @@ module SiSU_DAL_DocumentStructureExtract
cols=nil
rws.each do |r|
cols=(cols ? cols : (r.scan('|').length) +1)
- r.gsub!(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
+ r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
rows += r + Mx[:tc_c]
end
col=[]
@@ -337,7 +337,7 @@ module SiSU_DAL_DocumentStructureExtract
rws=tbl.split(/\n/)
rows=''
rws.each do |r|
- r.gsub!(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
+ r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
rows += r + Mx[:tc_c]
end
h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags }
@@ -366,8 +366,8 @@ module SiSU_DAL_DocumentStructureExtract
else
if t_o !~/^table\{/ \
and not t_o.nil?
- t_o.gsub!(/^\n+/m,'') #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2)
- t_o.gsub!(/\n+/m,"#{Mx[:tc_p]}")
+ t_o=t_o.gsub(/^\n+/m,''). #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2)
+ gsub(/\n+/m,"#{Mx[:tc_p]}")
@rows += t_o + Mx[:tc_c]
end
t_o=nil
@@ -447,7 +447,7 @@ module SiSU_DAL_DocumentStructureExtract
t_o=SiSU_DAL_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join
poem=t_o.split(/\n\n/)
poem.each do |v|
- v.gsub!(/\n/m,"#{Mx[:br_nl]}\n")
+ v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n")
obj,tags=extract_tags(v)
h={ obj: obj, tags: tags }
t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.verse(h)
@@ -463,17 +463,17 @@ module SiSU_DAL_DocumentStructureExtract
or @@flag['group'] \
or @@flag['alt']
if t_o.class==String
- t_o.gsub!(/\n/m,"#{Mx[:br_nl]}")
- t_o.gsub!(/[ ][ ]/m,"#{Mx[:nbsp]*2}")
- t_o.gsub!(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
+ t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}").
+ gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}").
+ gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
t_o=t_o + Mx[:br_nl] if t_o =~/\S+/
elsif t_o.is=='group' \
or t_o.is=='block' \
or t_o.is=='alt' \
or t_o.is=='verse'
- t_o.obj.gsub!(/\n/m,"#{Mx[:br_nl]}")
- t_o.obj.gsub!(/[ ][ ]/m,"#{Mx[:nbsp]*2}")
- t_o.obj.gsub!(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
+ t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}").
+ gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}").
+ gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
end
@tuned_block << t_o if t_o =~/\S+/
else tuned_file << t_o
@@ -742,26 +742,26 @@ module SiSU_DAL_DocumentStructureExtract
meta
end
def build_lines(type='')
- data=@data
- data.each do |line|
- if line =~/\S/ \
+ lines,lines_new=@data,[]
+ lines.each do |line|
+ line=if line =~/\S/ \
and line !~/^code\{|^\}code/ \
and line.class != Hash
- line.gsub!(/\s\s/,"#{Mx[:nbsp]*2}")
- line.gsub!(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
- line.gsub!(/^/,"#{Mx[:gr_o]}codeline#{Mx[:gr_c]}") if type=='code' # REMOVE try sort for texpdf special case
- if line =~/(?:https?|file|ftp):\/\/\S+$/
- line.gsub!(/\s*$/," #{Mx[:br_nl]}")
- else line.gsub!(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code'
- end
- if @@flag['code']; @@counter+=1
- else
+ @@counter+=1 if @@flag['code']
+ line=line.gsub(/\s\s/,"#{Mx[:nbsp]*2}").
+ gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
+ line=line.gsub(/^/,"#{Mx[:gr_o]}codeline#{Mx[:gr_c]}") if type=='code' # REMOVE try sort for texpdf special case
+ line=if line =~/(?:https?|file|ftp):\/\/\S+$/
+ line.gsub(/\s*$/," #{Mx[:br_nl]}")
+ else line.gsub(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code'
end
elsif line =~/^\s*$/
- line.gsub!(/\s*$/,"#{Mx[:br_nl]}")
+ line.gsub(/\s*$/,"#{Mx[:br_nl]}")
+ else line
end
+ lines_new << line
end
- data
+ lines_new
end
end
class Structure # this must happen early
@@ -805,26 +805,26 @@ module SiSU_DAL_DocumentStructureExtract
end
def structure_markup_normalize #needs a bit of thinking
dob=if @md.markup_version.determined < 0.38 #%convert internal representation, consider making 0.38 structure default ([A-C1-6] instead of [1-9]), requires downstream changes
- @dob.gsub!(/^[456]~/,'!_')
- @dob.gsub!(/^3~(\S+)/,"#{Mx[:lv_o]}6:\\1#{Mx[:lv_c]}")
- @dob.gsub!(/^3~\s+/,"#{Mx[:lv_o]}6:#{Mx[:lv_c]}")
- @dob.gsub!(/^2~(\S+)/,"#{Mx[:lv_o]}5:\\1#{Mx[:lv_c]}")
- @dob.gsub!(/^2~\s+/,"#{Mx[:lv_o]}5:#{Mx[:lv_c]}")
- @dob.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:lv_o]}1:#{Mx[:lv_c]}")
@dob=if @dob =~/^@(?:level|markup):\s/
- @dob.gsub!(/3/,'6')
- @dob.gsub!(/2/,'5')
- @dob.gsub!(/1/,'4')
- @dob.gsub!(/:?C/,'3')
- @dob.gsub!(/:?B/,'2')
- @dob.gsub!(/:?A/,'1')
+ @dob=@dob.gsub(/3/,'6').
+ gsub(/2/,'5').
+ gsub(/1/,'4').
+ gsub(/:?C/,'3').
+ gsub(/:?B/,'2').
+ gsub(/:?A/,'1')
@dob
else @dob
end
@@ -833,19 +833,19 @@ module SiSU_DAL_DocumentStructureExtract
end
def structure_marks
t_o=if @md.markup_version.determined < 0.38
- @t_o.gsub!(/^1~(\S+)/,"#{Mx[:lv_o]}1:\\1#{Mx[:lv_c]}")
- @t_o.gsub!(/^1~\s+/,"#{Mx[:lv_o]}1:#{Mx[:lv_c]}")
- @t_o.gsub!(/^2~(\S+)/,"#{Mx[:lv_o]}2:\\1#{Mx[:lv_c]}")
- @t_o.gsub!(/^2~\s+/,"#{Mx[:lv_o]}2:#{Mx[:lv_c]}")
- @t_o.gsub!(/^3~(\S+)/,"#{Mx[:lv_o]}3:\\1#{Mx[:lv_c]}")
- @t_o.gsub!(/^3~\s+/,"#{Mx[:lv_o]}3:#{Mx[:lv_c]}")
- @t_o.gsub!(/^4~(\S+)/,"#{Mx[:lv_o]}4:\\1#{Mx[:lv_c]}")
- @t_o.gsub!(/^4~\s+/,"#{Mx[:lv_o]}4:#{Mx[:lv_c]}")
- @t_o.gsub!(/^5~(\S+)/,"#{Mx[:lv_o]}5:\\1#{Mx[:lv_c]}")
- @t_o.gsub!(/^5~\s+/,"#{Mx[:lv_o]}5:#{Mx[:lv_c]}")
- @t_o.gsub!(/^6~(\S+)/,"#{Mx[:lv_o]}6:\\1#{Mx[:lv_c]}")
- @t_o.gsub!(/^6~\s+/,"#{Mx[:lv_o]}6:#{Mx[:lv_c]}")
- @t_o.gsub!(/^[789]~/,'!_')
+ @t_o=@t_o.gsub(/^1~(\S+)/,"#{Mx[:lv_o]}1:\\1#{Mx[:lv_c]}").
+ gsub(/^1~\s+/,"#{Mx[:lv_o]}1:#{Mx[:lv_c]}").
+ gsub(/^2~(\S+)/,"#{Mx[:lv_o]}2:\\1#{Mx[:lv_c]}").
+ gsub(/^2~\s+/,"#{Mx[:lv_o]}2:#{Mx[:lv_c]}").
+ gsub(/^3~(\S+)/,"#{Mx[:lv_o]}3:\\1#{Mx[:lv_c]}").
+ gsub(/^3~\s+/,"#{Mx[:lv_o]}3:#{Mx[:lv_c]}").
+ gsub(/^4~(\S+)/,"#{Mx[:lv_o]}4:\\1#{Mx[:lv_c]}").
+ gsub(/^4~\s+/,"#{Mx[:lv_o]}4:#{Mx[:lv_c]}").
+ gsub(/^5~(\S+)/,"#{Mx[:lv_o]}5:\\1#{Mx[:lv_c]}").
+ gsub(/^5~\s+/,"#{Mx[:lv_o]}5:#{Mx[:lv_c]}").
+ gsub(/^6~(\S+)/,"#{Mx[:lv_o]}6:\\1#{Mx[:lv_c]}").
+ gsub(/^6~\s+/,"#{Mx[:lv_o]}6:#{Mx[:lv_c]}").
+ gsub(/^[789]~/,'!_')
@t_o
else @t_o
end
@@ -945,13 +945,13 @@ module SiSU_DAL_DocumentStructureExtract
end
end
else ocnu+=1
- dob.obj.gsub!(/#{Mx[:fa_o]}~##{Mx[:fa_c]}/,'') if dob.obj
+ dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}~##{Mx[:fa_c]}/,'') if dob.obj
ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}"
dob.ocn,dob.odv,dob.osp=ocn,ocn_dv,ocn_sp
end
h
elsif dob.obj=~/#{Mx[:pa_non_object_no_heading]}/
- dob.obj.gsub!(/#{Mx[:pa_non_object_no_heading]}/,'')
+ dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_no_heading]}/,'')
if dob.is=='para'
h={ obj: dob.obj, ocn_: false, ocn: nil }
dob=SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h,dob)
@@ -960,7 +960,7 @@ module SiSU_DAL_DocumentStructureExtract
dob=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,dob)
end
elsif dob.obj=~/#{Mx[:pa_non_object_dummy_heading]}/
- dob.obj.gsub!(/#{Mx[:pa_non_object_dummy_heading]}/,'')
+ dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_dummy_heading]}/,'')
if dob.is=='para'
h={ obj: dob.obj, ocn_: false, ocn: nil }
dob=SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h,dob)
@@ -970,7 +970,7 @@ module SiSU_DAL_DocumentStructureExtract
end
else dob
end
- dob.obj.gsub!(/\n\n/,"\n") if dob.is =~/(?:code|verse|alt|group|block)/ #newlines taken out
+ dob.obj=dob.obj.gsub(/\n\n/,"\n") if dob.is =~/(?:code|verse|alt|group|block)/ #newlines taken out
@o_array << dob
end
@o_array
@@ -1060,8 +1060,7 @@ module SiSU_DAL_DocumentStructureExtract
end
puts_tag_close(0,hs) if @md.opt.cmd =~/V/
tuned_file << tag_close(0,hs)
- tuned_file.flatten!
- tuned_file
+ tuned_file=tuned_file.flatten
end
def tags(o)
tag=if o[:status]=='open'