diff options
author | Ralph Amissah <ralph@amissah.com> | 2014-12-25 00:45:15 -0500 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2015-01-07 22:42:40 -0500 |
commit | 059e31210711c0b51b2ae1ea9e4c82ec75ad5b89 (patch) | |
tree | 750356ec3c642cf3e97a87a503aca8d1cd7659ab /lib/sisu/current/po4a.rb | |
parent | c&d: html, ocn link back to self reinstated (diff) |
c&d: po4a (& git) revisited, revisit
Diffstat (limited to 'lib/sisu/current/po4a.rb')
-rw-r--r-- | lib/sisu/current/po4a.rb | 334 |
1 files changed, 216 insertions, 118 deletions
diff --git a/lib/sisu/current/po4a.rb b/lib/sisu/current/po4a.rb index 7d602f7c..097fb2c6 100644 --- a/lib/sisu/current/po4a.rb +++ b/lib/sisu/current/po4a.rb @@ -63,12 +63,15 @@ module SiSU_Po4a require_relative 'po4a_set' # po4a_set.rb include SiSU_Param class Source - @@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn=nil,nil,nil,nil,nil,nil + @@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn= + nil,nil,nil,nil,nil,nil def initialize(opt,fn=nil) @opt,@fn=opt,fn #unless @opt.fns =~/(.+?\.(?:-|ssm\.)?sst)$/ # puts "#{@opt.fns} not a processed file type" #end + file_arr=SiSU_Info_Env::InfoEnv.new.source_file_processing_array(@opt.fns) + SiSU_Param::Parameters::Instructions.new(file_arr,@opt).extract r=Px[:lng_lst_rgx].gsub(/\|en\|/,'|') @lang_regx=%r{(?:#{r})} if opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ @@ -94,36 +97,44 @@ module SiSU_Po4a end md=SiSU_Param::Parameters.new(@opt).get src[:files].each do |fn| - SiSU_AO::Source.new(@opt,fn).read # -m env=SiSU_Env::InfoEnv.new(@opt.fns) + file=SiSU_Env::FileOp.new(md) m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss @fnn,@fnb,@fnt=fn[m,1],fn[m,2],fn[m,3] unless @opt.act[:quiet][:set]==:on - path=env.path.output_tell tool=(@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) \ - ? "#{env.program.text_editor} #{path}/#{md.fnb}/#{md.fn[:plain]}" + ? "#{env.program.text_editor} #{file.output_path.pot.dir}/" : @opt.fns (@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Pot po4a',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Pot po4a',tool).green_title_hi + ? SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Pot po4a', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Pot po4a', + tool + ).green_title_hi if (@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], @opt.fns, - "#{path}/#{md.fnb}/#{md.fn[:plain]}" + file.output_path.pot.dir ).flow end end if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ or @opt.f_pth[:lng] !=@opt.lng_base opt_lang_trn_fn=fn - @ao_array_lang_translation=SiSU_AO::Source.new(@opt,opt_lang_trn_fn).get # ao file drawn here + @ao_array_lang_translation= + SiSU_AO::Source.new(@opt,opt_lang_trn_fn,:po4a).get # ao file drawn here opt_lang_src_fn=if fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/ fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2') #check i else fn @@ -138,14 +149,16 @@ module SiSU_Po4a else nil end if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}") - @ao_array_lang_src=SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn).get # ao file drawn here + @ao_array_lang_src= + SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn,:po4a).get # ao file drawn here else puts "no identified source document" exit end Dir.chdir(transdir) if transdir else - @ao_array_lang_src=SiSU_AO::Source.new(@opt,fn).get # ao file drawn here + @ao_array_lang_src= + SiSU_AO::Source.new(@opt,fn,:po4a).get # ao file drawn here @ao_array_lang_translation=nil end wrap_width=if defined? md.make.plaintext_wrap \ @@ -156,7 +169,13 @@ module SiSU_Po4a env.plaintext_wrap else 78 end - SiSU_Po4a::Source::Scroll.new(fn,@ao_array_lang_src,@ao_array_lang_translation,@@md_src,@@md_trn,wrap_width).songsheet + SiSU_Po4a::Source::Scroll.new( + fn, + @ao_array_lang_src, + @ao_array_lang_translation, + @@md_src,@@md_trn, + wrap_width + ).songsheet end rescue SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do @@ -170,14 +189,24 @@ module SiSU_Po4a include SiSU_Po4aUtils @@endnotes={ para: [], end: [] } def initialize(fn,data_src,data_trn,md_src,md_trn,wrap_width) - @fn,@data_src,@data_trn,@md_src,@md_trn,@wrap_width=fn,data_src,data_trn,md_src,md_trn,wrap_width + @fn,@data_src,@data_trn,@md_src,@md_trn,@wrap_width= + fn, data_src, data_trn, md_src, md_trn, wrap_width @md=(md_trn.nil?) \ ? md_src : md_trn @tab="\t" @@endnotes_=(@md.opt.selections.str =~/--endnote/) ? true : false # --footnote - @br=(@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix - @pot={ body: [], open: [], close: [], head: [], metadata: [], tail: [] } + @pot={ + body: [], + open: [], + close: [], + head: [], + metadata: [], + tail: [] + } + end + def br + (@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix end def songsheet ############## BUG @fn changes value @@ -185,7 +214,7 @@ module SiSU_Po4a pot=pot_markup(@data_src,@data_trn) publish(fn,pot) end - def extract_endnotes(dob='') #% Used for extraction of endnotes from paragraphs + def extract_endnotes(dob='') #% used for extraction of endnotes from paragraphs notes_a=dob.obj.scan(/#{Mx[:en_a_o]}([\d]+\s+.+?)#{Mx[:en_a_c]}/) ##notes_a=dob.obj.scan(/#{Mx[:en_a_o]}([\d*+]+\s+.+?)#{Mx[:en_a_c]}/) #notes_b=dob.obj.scan(/#{Mx[:en_b_o]}([\d*+]+\s+.+?)#{Mx[:en_b_c]}/) @@ -193,8 +222,8 @@ module SiSU_Po4a notes_a.flatten.each do |n| #high cost to deal with <br> appropriately within plaintext, consider n=n.dup.to_s n=n.gsub(/^([\d]+)\s+/,'^~\1 '). - #gsub(/^([\d*+]+)\s+/,'^~\1 '). - gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'<br>') + gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/, + ' \\\\\\ ') @n << n end notes_a=@n.flatten @@ -212,14 +241,21 @@ module SiSU_Po4a mark="^~ " instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# footnotes, the preferred sisu markup for a footnote is~{this is a footnote}~ however, for translation a footnote reference marker in the text~^ with a set of notes following the paragraph starting on a newline with "^~ this is a footnote", is easier to deal with, if possible these should be converted back to~{inline notes}~} + instruct=%{\n# footnotes, the preferred sisu markup for a footnote is~{this is a footnote}~ } \ + + %{however, for translation a footnote reference marker in the text~^ } \ + + %{with a set of notes following the paragraph starting on a newline with "^~ this is a footnote", } \ + + %{is easier to deal with, if possible these should be converted back to~{inline notes}~} s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" - orig=(orig_notes[i].to_s =~/^\^~[\d*+]+/) ? (orig_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~')) : orig_notes[i].to_s + orig=(orig_notes[i].to_s =~/^\^~[\d*+]+/) \ + ? (orig_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~')) + : orig_notes[i].to_s trans=if trn_notes.is_a?(Array) \ and trn_notes.length==orig_notes.length - (trn_notes[i].to_s =~/^\^~[\d*+]+/) ? (trn_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~')) : trn_notes[i].to_s + (trn_notes[i].to_s =~/^\^~[\d*+]+/) \ + ? (trn_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~')) + : trn_notes[i].to_s else '' end util=pot_structure(desc,orig,trans) @@ -238,7 +274,7 @@ GSUB @@endnotes[:para] << wrap @@endnotes[:end] << '' << wrap end - @@endnotes[:para].each {|e| @pot[:body] << e << @br} + @@endnotes[:para].each {|e| @pot[:body] << e << br} @@endnotes[:para]=[] @@endnotes end @@ -297,10 +333,10 @@ GSUB meta_src.metadata_tags.classify.topic_register, meta_src.metadata_tags.classify.loc, meta_src.metadata_tags.classify.dewey, - meta_src.metadata_tags.notes.relation, - meta_src.metadata_tags.notes.type, - meta_src.metadata_tags.identifier.oclc, - meta_src.metadata_tags.identifier.isbn, + #meta_src.metadata_tags.notes.relation, + #meta_src.metadata_tags.notes.type, + #meta_src.metadata_tags.identifier.oclc, + #meta_src.metadata_tags.identifier.isbn, 'msgstr ""', ] w << [ @@ -340,7 +376,7 @@ GSUB z += %{"#{x}"\n} if x =~/^\s+:\S+?: / end end - @pot[:metadata] << z << @br + @pot[:metadata] << z << br #puts z unless z.empty? end end @@ -425,20 +461,20 @@ GSUB meta_src.metadata_tags.classify.topic_register, meta_src.metadata_tags.classify.loc, meta_src.metadata_tags.classify.dewey, - meta_src.metadata_tags.notes.relation, - meta_src.metadata_tags.notes.type, - meta_src.metadata_tags.identifier.oclc, - meta_src.metadata_tags.identifier.isbn, + #meta_src.metadata_tags.notes.relation, + #meta_src.metadata_tags.notes.type, + #meta_src.metadata_tags.identifier.oclc, + #meta_src.metadata_tags.identifier.isbn, 'msgstr ""', meta_trn.metadata_tags.classify.head, meta_trn.metadata_tags.classify.subject, meta_trn.metadata_tags.classify.topic_register, meta_trn.metadata_tags.classify.loc, meta_trn.metadata_tags.classify.dewey, - meta_trn.metadata_tags.notes.relation, - meta_trn.metadata_tags.notes.type, - meta_trn.metadata_tags.identifier.oclc, - meta_trn.metadata_tags.identifier.isbn, + #meta_trn.metadata_tags.notes.relation, + #meta_trn.metadata_tags.notes.type, + #meta_trn.metadata_tags.identifier.oclc, + #meta_trn.metadata_tags.identifier.isbn, ] w << [ "#. #{@po4a_identify_type} - metadata: date", @@ -493,14 +529,22 @@ GSUB z += %{"#{x}"\n} if x =~/^\s+:\S+?: / end end - @pot[:metadata] << z << @br + @pot[:metadata] << z << br #puts z unless z.empty? end end def pot_structure(desc,orig,trans,indent=0,hang=0) - SiSU_Po4aUtils::Wrap.new(@md,orig,trans,desc,@wrap_width,indent,hang) + SiSU_Po4aUtils::Wrap.new( + @md, + orig, + trans, + desc, + @wrap_width, + indent, + hang + ) end - def pot_structure_heading(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_heading(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document lv=n=n3=nil lv=dob_src.ln n=lv - 1 @@ -511,7 +555,9 @@ GSUB d="#{dob_src.is.to_s} (level #{dob_src.lv})" instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for headings is marker at the start of the line/object, indicating the heading level, and if provided an associated name tag, this heading is "#{mark}"} + instruct=%{\n# markup for headings is marker at the start of the line/object, } \ + + %{indicating the heading level, and if provided an associated name tag, } \ + + %{this heading is "#{mark}"} s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -519,18 +565,18 @@ GSUB trans=(dob_trn=='') ? '' : "#{s_mark}#{dob_trn.obj}" util=pot_structure(desc,orig,trans) wrapped=util.line_wrap - @pot[:body] << wrapped << @br # main text, contents, body KEEP + @pot[:body] << wrapped << br # main text, contents, body KEEP if @@endnotes[:para] \ and notes_s.length > 0 \ and not @@endnotes_ - @pot[:body] << @br + @pot[:body] << br wrap_endnotes(notes_s,notes_t) elsif @@endnotes[:para] \ and @@endnotes_ - @pot[:body] << @br*2 + @pot[:body] << br*2 end end - def pot_structure_para(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document util=nil wrapped=if dob_src.indent =~/[1-9]/ \ and dob_src.indent == dob_src.hang @@ -540,7 +586,8 @@ GSUB d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet" instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented bullet text is at the start of the line/object, an underscore followed by the indent level and an asterisk "#{mark}"} + instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \ + + %{an underscore followed by the indent level and an asterisk "#{mark}"} s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -549,7 +596,8 @@ GSUB d="#{dob_src.is.to_s}: indent #{dob_src.indent}" instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented text is at the start of the line/object, an underscore followed by the indent level "#{mark}"} + instruct=%{\n# markup for indented text is at the start of the line/object, } \ + + %{an underscore followed by the indent level "#{mark}"} s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -564,7 +612,11 @@ GSUB d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}" instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented text with a first line indented to a different level from the rest of the paragraph, is at the start of the line/object, an underscore and the first indent level a second underscore and the indent level for the rest of the paragraph, "#{mark1}"} + instruct=%{\n# markup for indented text with a first line indented } \ + + %{to a different level from the rest of the paragraph, } \ + + %{is at the start of the line/object, } \ + + %{an underscore and the first indent level } \ + + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"} s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -578,7 +630,8 @@ GSUB d="#{dob_src.is.to_s}: bullet" instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented text is at the start of the line/object, an underscore followed by an asterisk "#{mark}"} + instruct=%{\n# markup for indented text is at the start of the line/object, } \ + + %{an underscore followed by an asterisk "#{mark}"} s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -599,23 +652,24 @@ GSUB util=pot_structure(desc,orig,trans) end wrapped=util.line_wrap - @pot[:body] << wrapped << @br # main text, contents, body KEEP + @pot[:body] << wrapped << br # main text, contents, body KEEP if @@endnotes[:para] \ and notes_s.length > 0 \ and not @@endnotes_ - @pot[:body] << @br + @pot[:body] << br wrap_endnotes(notes_s,notes_t) elsif @@endnotes[:para] \ and @@endnotes_ - @pot[:body] << @br*2 + @pot[:body] << br*2 end end - def pot_structure_block(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document mark="block{\\n\\n...\\n\\n}block" d=dob_src.is.to_s instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct="\n# block text is a text block with an opening and closing marker, the content of which may be wrapped" + instruct=%{\n# block text is a text block with an opening and closing marker, } \ + + %{the content of which may be wrapped} s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -623,14 +677,15 @@ GSUB trans=(dob_trn=='') ? '' : dob_trn.obj util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << @br + @pot[:body] << unwrapped << br end - def pot_structure_group(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document mark="group{\\n\\n...\\n\\n}group" d=dob_src.is.to_s instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct="\n# group text is a text block with an opening and closing marker, the content of which may be wrapped" + instruct=%{\n# group text is a text block with an opening and closing marker, } \ + + %{the content of which may be wrapped} s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -638,14 +693,17 @@ GSUB trans=(dob_trn=='') ? '' : dob_trn.obj util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << @br + @pot[:body] << unwrapped << br end - def pot_structure_verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem" d=dob_src.is.to_s instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct="\n# verse are part of the text block described as a poem, the first verse is preceeded by an opening marker, and the last verse by a closing marker, the content of which should remain unwrapped" + instruct=%{\n# verse are part of the text block described as a poem, } \ + + %{the first verse is preceeded by an opening marker, } \ + + %{and the last verse by a closing marker, } \ + + %{the content of which should remain unwrapped} s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -653,14 +711,15 @@ GSUB trans=(dob_trn=='') ? '' : dob_trn.obj util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << @br + @pot[:body] << unwrapped << br end - def pot_structure_code(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document mark="code{\\n\\n...\\n\\n}code" d=dob_src.is.to_s instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct="\n# codeblocks are a text block with an opening and closing marker, the content of which should remain unwrapped" + instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \ + + %{the content of which should remain unwrapped} s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -668,14 +727,15 @@ GSUB trans=(dob_trn=='') ? '' : dob_trn.obj util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << @br + @pot[:body] << unwrapped << br end - def pot_structure_table(dob_src='',notes_s='',dob_trn='',notes_t='') #% Used to extract the structure of a document + def pot_structure_table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document mark="table{\\n\\n...\\n\\n}table" d=dob_src.is.to_s instruct=s_mark='' if @md.opt.act[:maintenance][:set]==:on - instruct="\n# tables are a text block with an opening and closing marker, the content of which should remain unwrapped" + instruct=%{\n# tables are a text block with an opening and closing marker, } \ + + %{the content of which should remain unwrapped} s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} end desc="#{d}#{s_mark}#{instruct}" @@ -685,27 +745,27 @@ GSUB trans=trans.gsub(/#{Mx[:tc_c]}/,"\n") util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << @br + @pot[:body] << unwrapped << br end - def pot_structure_idx(dob_src='',dob_trn='') #% Used to extract the structure of a document - mark="={ ... }" - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct="\n# the book index should be attached unwrapped to the preceding text block (there should be a new line, but no empty line)" - s_mark="\n# " + %{"\\n#{mark}\\n\\n"} - end - d='book-idx' - desc="#{d}#{s_mark}#{instruct}" - orig='={' + dob_src.idx + '}' - trans=if defined? dob_trn.idx \ - and not dob_trn.idx.nil? \ - and not dob_trn.idx.empty? - '={' + dob_trn.idx + '}' - else '' - end - util=pot_structure(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << @br + def pot_structure_idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix + #mark="={ ... }" + #instruct=s_mark='' + #if @md.opt.act[:maintenance][:set]==:on + # instruct="\n# the book index should be attached unwrapped to the preceding text block (there should be a new line, but no empty line)" + # s_mark="\n# " + %{"\\n#{mark}\\n\\n"} + #end + #d='book-idx' + #desc="#{d}#{s_mark}#{instruct}" + #orig='={' + dob_src.idx + '}' + #trans=if defined? dob_trn.idx \ + #and not dob_trn.idx.nil? \ + #and not dob_trn.idx.empty? + # '={' + dob_trn.idx + '}' + #else '' + #end + #util=pot_structure(desc,orig,trans) + #unwrapped=util.no_line_wrap_block + #@pot[:body] << unwrapped << br end def pot_markup(data_src,data_trn) #@endnotes,@copen,@pot_contents_close=Array.new(3){[]} @@ -734,24 +794,35 @@ GSUB s+=1;t+=1 next end - if (data_src[s].is == :comment or data_trn[t].is == :comment) \ + if ((data_src[s].is == :comment) \ + || (data_trn[t].is == :comment)) \ and (data_src[s].is != data_trn[t].is) if data_src[s].is == :comment - puts "src (comment):\n\t" + data_src[s].obj if @md.opt.act[:maintenance][:set]==:on + if @md.opt.act[:maintenance][:set]==:on + puts "src (comment):\n\t" \ + + data_src[s].obj + end s+=1 #next if data_src[s].is == :comment elsif data_trn[t].is == :comment - puts "trans (comment):\n\t" + data_trn[t].obj if @md.opt.act[:maintenance][:set]==:on + if @md.opt.act[:maintenance][:set]==:on + puts "trans (comment):\n\t" \ + + data_trn[t].obj + end t+=1 #next if data_trn[t].is == :comment end end - if (defined? data_src[s].ocn and data_src[s].ocn.is_a?(Fixnum)) \ - and (defined? data_trn[t].ocn and data_trn[t].ocn.is_a?(Fixnum)) \ + if ((defined? data_src[s].ocn) \ + && (data_src[s].ocn.is_a?(Fixnum))) \ + and ((defined? data_trn[t].ocn) \ + && (data_trn[t].ocn.is_a?(Fixnum))) \ and (data_src[s].ocn == data_trn[t].ocn) @m_s,@m_t=s,t - elsif (defined? data_src[s].ocn and data_src[s].ocn.is_a?(Fixnum)) \ - and (defined? data_trn[t].ocn and data_trn[t].ocn.is_a?(Fixnum)) \ + elsif ((defined? data_src[s].ocn) \ + && (data_src[s].ocn.is_a?(Fixnum))) \ + and ((defined? data_trn[t].ocn) \ + && (data_trn[t].ocn.is_a?(Fixnum))) \ and (data_src[s].ocn != data_trn[t].ocn) p '--- OCN ---' p 'mis-match' @@ -766,7 +837,8 @@ GSUB p data_trn[@m_t].ocn p data_trn[@m_t].obj exit - elsif (defined? data_src[s].ocn and defined? data_trn[t].ocn \ + elsif (((defined? data_src[s].ocn) \ + && (defined? data_trn[t].ocn)) \ and data_src[s].ocn.class != data_trn[t].ocn.class) p '--- OCN class ---' p 'mis-match' @@ -813,13 +885,20 @@ GSUB @p_num=SiSU_Po4aUtils::ParagraphNumber.new(paranum) end case dob_src.is - when :heading then pot_structure_heading(dob_src,notes_s,dob_trn,notes_t) - when :para then pot_structure_para(dob_src,notes_s,dob_trn,notes_t) - when :group then pot_structure_group(dob_src,notes_s,dob_trn,notes_t) - when :block then pot_structure_block(dob_src,notes_s,dob_trn,notes_t) - when :verse then pot_structure_verse(dob_src,notes_s,dob_trn,notes_t) - when :code then pot_structure_code(dob_src,notes_s,dob_trn,notes_t) - when :table then pot_structure_table(dob_src,notes_s,dob_trn,notes_t) + when :heading + pot_structure_heading(dob_src,notes_s,dob_trn,notes_t) + when :para + pot_structure_para(dob_src,notes_s,dob_trn,notes_t) + when :group + pot_structure_group(dob_src,notes_s,dob_trn,notes_t) + when :block + pot_structure_block(dob_src,notes_s,dob_trn,notes_t) + when :verse + pot_structure_verse(dob_src,notes_s,dob_trn,notes_t) + when :code + pot_structure_code(dob_src,notes_s,dob_trn,notes_t) + when :table + pot_structure_table(dob_src,notes_s,dob_trn,notes_t) end if defined? dob_src.idx \ and not dob_src.idx.nil? \ @@ -835,9 +914,10 @@ GSUB end #[dob_src,dob_trn] end - def markup(dob) # Used for major markup instructions + def markup(dob) # used for major markup instructions SiSU_Env::InfoEnv.new(@md.fns) - dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + dob.obj=dob.obj. + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, "#{Px[:po_bold_o]}\\1#{Px[:po_bold_c]}"). gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, "#{Px[:po_italics_o]}\\1#{Px[:po_italics_c]}"). @@ -857,19 +937,26 @@ GSUB "#{Px[:po_monospace_o]}\\1#{Px[:po_monospace_c]}") notes='' unless dob.is==:code - dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). + dob.obj=dob.obj. + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + '\1 [link: <\2>]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/, + '\1 [link: local image]'). gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1') notes=extract_endnotes(dob) #% ### footnotes current state - extracted - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'~^'). # endnote marker marked up + dob.obj=dob.obj. + gsub(/#{Mx[:en_a_o]}([\d]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'~^'). # endnote marker marked up #% ### footnotes current state - keep inline #dob.obj.gsub!(/#{Mx[:en_a_o]}[\d]+\s+(.+?)#{Mx[:en_a_c]}/,'~{ \1 }~') # inline endnote with marker marked up - gsub(/#{Mx[:en_b_o]}[\d]+\s+(.+?)#{Mx[:en_b_c]}/,'~[ \1 ]~'). # inline endnote with marker marked up - gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/,'~{\1 \2 }~'). # inline endnote with marker marked up - gsub(/#{Mx[:en_b_o]}([*+]+)\s+(.+?)#{Mx[:en_b_c]}/,'~[\1 \2 ]~'). # inline endnote with marker marked up + gsub(/#{Mx[:en_b_o]}[\d]+\s+(.+?)#{Mx[:en_b_c]}/, + '~[ \1 ]~'). # inline endnote with marker marked up + gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/, + '~{\1 \2 }~'). # inline endnote with marker marked up + gsub(/#{Mx[:en_b_o]}([*+]+)\s+(.+?)#{Mx[:en_b_c]}/, + '~[\1 \2 ]~'). # inline endnote with marker marked up gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). @@ -898,9 +985,12 @@ GSUB gsub(/<a href=".+?">(.+?)<\/a>/m,'\1'). gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links gsub(/ |#{Mx[:nbsp]}/,' '). # decide on - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") - gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/, + ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/, + ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/, + '[image: "\1"]') [dob,notes] end def publish(fn,pot) @@ -910,18 +1000,18 @@ GSUB content << pot[:metadata] content << pot[:body] content << @@endnotes[:end] if @@endnotes_ - Output.new(fn,content,@md).po4a + Output.new(fn,content,@md,@process).po4a @@endnotes={ para: [], end: [] } end end class Output <Source include SiSU_Param include SiSU_Env - def initialize(fn,content,md) - @fn,@content,@md=fn,content,md + def initialize(fn,content,md,process=:complete) + @fn,@content,@md,@process=fn,content,md,process @file=SiSU_Env::FileOp.new(md,fn) end - def po4a #%pot output + def po4a #%pot output file_pot=(@md.opt.f_pth[:lng] ==@md.opt.lng_base) \ ? @file.write_file.pot : @file.write_file.po @@ -951,12 +1041,20 @@ GSUB def po4a_git unless @md.opt.act[:maintenance][:set]==:on require_relative 'git' # git.rb - git=SiSU_Git::Source.new(@md.opt) - git.create_file_structure_git unless FileTest.directory?(@file.output_path.pot_git.dir) + git=SiSU_Git::Source.new(@md.opt,@process) + unless FileTest.directory?(@file.output_path.pot_git.dir) + git.create_file_structure_git + end if @md.opt.f_pth[:lng] ==@md.opt.lng_base - FileUtils::cp(@file.place_file.pot.dir, @file.output_path.pot_git.dir) + FileUtils::cp( + @file.place_file.pot.dir, + @file.output_path.pot_git.dir + ) else # naive, work on --> - FileUtils::cp(@file.place_file.po.dir, @file.output_path.po_git.dir) #unless FileTest.file?(@file.place_file.po_git.dir) + FileUtils::cp( + @file.place_file.po.dir, + @file.output_path.po_git.dir + ) #unless FileTest.file?(@file.place_file.po_git.dir) end git.read end |