d: po4a, stub for auto-translate
[software/sisu] / lib / sisu / develop / po4a.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** pot file generation
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/po4a.rb;hb=HEAD>
55
56 =end
57 module SiSU_Po4a
58 require_relative 'ao' # ao.rb
59 require_relative 'se' # se.rb
60 include SiSU_Env
61 require_relative 'ao_composite' # ao_composite.rb
62 require_relative 'shared_metadata' # shared_metadata.rb
63 require_relative 'po4a_set' # po4a_set.rb
64 include SiSU_Param
65 class Source
66 @@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn=
67 nil,nil,nil,nil,nil,nil
68 @@auto_translation_ = :go
69 def initialize(opt,fn=nil)
70 @opt,@fn=opt,fn
71 #unless @opt.fns =~/(.+?\.(?:-|ssm\.)?sst)$/
72 # puts "#{@opt.fns} not a processed file type"
73 #end
74 file_arr=SiSU_Info_Env::InfoEnv.new.source_file_processing_array(@opt.fns)
75 SiSU_Param::Parameters::Instructions.new(file_arr,@opt).extract
76 r=Px[:lng_lst_rgx].gsub(/\|en\|/,'|')
77 @lang_regx=%r{(?:#{r})}
78 if opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \
79 and opt.f_pth[:lng]!=@opt.lng_base
80 @@opt_src_=false
81 @@opt_trn=opt
82 @@md_trn=SiSU_Param::Parameters.new(opt).get
83 else
84 @@opt_src_=true
85 @@opt_src=opt
86 @@md_src=SiSU_Param::Parameters.new(opt).get
87 end
88 end
89 def read
90 begin
91 src={}
92 src[:pth]=@opt.f_pth[:pth]
93 src[:files]=if @opt.fns =~ /\.(?:(?:-|ssm\.)sst|ssm)$/
94 @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm')
95 SiSU_Assemble::CompositeFileList.new(@opt).read
96 else
97 [@opt.fns]
98 end
99 md=SiSU_Param::Parameters.new(@opt).get
100 src[:files].each do |fn|
101 env=SiSU_Env::InfoEnv.new(@opt.fns)
102 file=SiSU_Env::FileOp.new(md)
103 m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss
104 @fnn,@fnb,@fnt=fn[m,1],fn[m,2],fn[m,3]
105 unless @opt.act[:quiet][:set]==:on
106 tool=(@opt.act[:verbose][:set]==:on \
107 || @opt.act[:verbose_plus][:set]==:on \
108 || @opt.act[:maintenance][:set]==:on) \
109 ? "#{env.program.text_editor} #{file.output_path.pot.dir}/"
110 : @opt.fns
111 (@opt.act[:verbose][:set]==:on \
112 || @opt.act[:verbose_plus][:set]==:on \
113 || @opt.act[:maintenance][:set]==:on) \
114 ? SiSU_Screen::Ansi.new(
115 @opt.act[:color_state][:set],
116 'Pot po4a',
117 tool
118 ).green_hi_blue
119 : SiSU_Screen::Ansi.new(
120 @opt.act[:color_state][:set],
121 'Pot po4a',
122 tool
123 ).green_title_hi
124 if (@opt.act[:verbose][:set]==:on \
125 || @opt.act[:verbose_plus][:set]==:on \
126 || @opt.act[:maintenance][:set]==:on)
127 SiSU_Screen::Ansi.new(
128 @opt.act[:color_state][:set],
129 @opt.fns,
130 file.output_path.pot.dir
131 ).flow
132 end
133 end
134 if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \
135 or @opt.f_pth[:lng] !=@opt.lng_base
136 opt_lang_trn_fn=fn
137 @ao_array_lang_translation=
138 SiSU_AO::Source.new(@opt,opt_lang_trn_fn,:po4a).get # ao file drawn here
139 opt_lang_src_fn=if fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/
140 fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2') #check i
141 else fn
142 end
143 transdir,srcdir=Dir.pwd,Dir.pwd
144 if Dir.pwd.to_s =~/\/#{@lang_regx}$/
145 transdir=Dir.pwd
146 srcdir=transdir.gsub(/\/#{@lang_regx}$/,"/#{@opt.lng_base}")
147 if FileTest.directory?(srcdir)
148 Dir.chdir(srcdir)
149 end
150 else nil
151 end
152 if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}")
153 @ao_array_lang_src=
154 SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn,:po4a).get # ao file drawn here
155 else
156 puts "no identified source document"
157 exit
158 end
159 Dir.chdir(transdir) if transdir
160 else
161 @ao_array_lang_src=
162 SiSU_AO::Source.new(@opt,fn,:po4a).get # ao file drawn here
163 @ao_array_lang_translation=nil
164 end
165 wrap_width=if defined? md.make.plaintext_wrap \
166 and md.make.plaintext_wrap
167 md.make.plaintext_wrap
168 elsif defined? env.plaintext_wrap \
169 and env.plaintext_wrap
170 env.plaintext_wrap
171 else 78
172 end
173 SiSU_Po4a::Source::Scroll.new(
174 fn,
175 @ao_array_lang_src,
176 @ao_array_lang_translation,
177 @@md_src,@@md_trn,
178 wrap_width
179 ).songsheet
180 end
181 rescue
182 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
183 __LINE__.to_s + ':' + __FILE__
184 end
185 ensure
186 end
187 end
188 private
189 class Scroll <Source
190 include SiSU_Po4aUtils
191 @@endnotes={ para: [], end: [] }
192 def initialize(fn,data_src,data_trn,md_src,md_trn,wrap_width)
193 @fn,@data_src,@data_trn,@md_src,@md_trn,@wrap_width=
194 fn, data_src, data_trn, md_src, md_trn, wrap_width
195 @md=(md_trn.nil?) \
196 ? md_src
197 : md_trn
198 @tab="\t"
199 @@endnotes_=(@md.opt.selections.str =~/--endnote/) ? true : false # --footnote
200 @pot={
201 body: [],
202 open: [],
203 close: [],
204 head: [],
205 metadata: [],
206 tail: []
207 }
208 end
209 def br
210 (@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix
211 end
212 def songsheet
213 ############## BUG @fn changes value
214 fn=@fn
215 pot=pot_markup(@data_src,@data_trn)
216 publish(fn,pot)
217 end
218 def extract_endnotes(dob='') #% used for extraction of endnotes from paragraphs
219 notes_a=dob.obj.scan(/#{Mx[:en_a_o]}([\d]+\s+.+?)#{Mx[:en_a_c]}/)
220 ##notes_a=dob.obj.scan(/#{Mx[:en_a_o]}([\d*+]+\s+.+?)#{Mx[:en_a_c]}/)
221 #notes_b=dob.obj.scan(/#{Mx[:en_b_o]}([\d*+]+\s+.+?)#{Mx[:en_b_c]}/)
222 @n=[]
223 notes_a.flatten.each do |n| #high cost to deal with <br> appropriately within plaintext, consider
224 n=n.dup.to_s
225 n=n.gsub(/^([\d]+)\s+/,'^~\1 ').
226 gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,
227 ' \\\\\\ ')
228 @n << n
229 end
230 notes_a=@n.flatten
231 end
232 def wrap_endnotes(orig_notes='',trn_notes='')
233 nt=@@endnotes_ ? 'endnote' : 'footnote'
234 @fn=0
235 a_l=orig_notes.length
236 0.upto(a_l-1) do |i|
237 @fn=if orig_notes[i].to_s =~/^\^~([\d*+]+)/ # provides endnote number within paragraph
238 @fn += 1
239 else @fn
240 end
241 d="#{nt} #{@fn}"
242 mark="^~ "
243 instruct=s_mark=''
244 if @md.opt.act[:maintenance][:set]==:on
245 instruct=%{\n# footnotes, the preferred sisu markup for a footnote is~{this is a footnote}~ } \
246 + %{however, for translation a footnote reference marker in the text~^ } \
247 + %{with a set of notes following the paragraph starting on a newline with "^~ this is a footnote", } \
248 + %{is easier to deal with, if possible these should be converted back to~{inline notes}~}
249 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
250 end
251 desc="#{d}#{s_mark}#{instruct}"
252 orig=(orig_notes[i].to_s =~/^\^~[\d*+]+/) \
253 ? (orig_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~'))
254 : orig_notes[i].to_s
255 trans=if trn_notes.is_a?(Array) \
256 and trn_notes.length==orig_notes.length
257 (trn_notes[i].to_s =~/^\^~[\d*+]+/) \
258 ? (trn_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~'))
259 : trn_notes[i].to_s
260 else ''
261 end
262 util=pot_structure(desc,orig,trans)
263 wrap=util.line_wrap
264 wrap=if wrap =~ /^\s*\^~[\d*+]+\s+.+?\s*\Z/m
265 wrap.gsub(/^\s*(\^~[\d*+]+)\s+(.+?)\s*\Z/m, <<GSUB
266 \\1 \\2
267 GSUB
268 )
269 else
270 wrap.gsub(/^(.+)\Z/m, <<GSUB
271 \\1
272 GSUB
273 )
274 end
275 @@endnotes[:para] << wrap
276 @@endnotes[:end] << '' << wrap
277 end
278 @@endnotes[:para].each {|e| @pot[:body] << e << br}
279 @@endnotes[:para]=[]
280 @@endnotes
281 end
282 def pot_metadata_src
283 @po4a_identify_type='type: SiSU doc' #'type: Plain text'
284 meta_src=SiSU_Metadata::Summary.new(@md_src)
285 w=[]
286 w << [
287 "#. #{@po4a_identify_type} - metadata: title",
288 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
289 'msgid ""',
290 meta_src.metadata_tags.title.main,
291 meta_src.metadata_tags.title.sub,
292 meta_src.metadata_tags.title.edition,
293 meta_src.metadata_tags.title.note,
294 meta_src.metadata_tags.title.short,
295 meta_src.metadata_tags.title.language,
296 meta_src.metadata_tags.title.language_char,
297 'msgstr ""',
298 ]
299 w << [
300 "#. #{@po4a_identify_type} - metadata: creator",
301 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
302 'msgid ""',
303 meta_src.metadata_tags.creator.head,
304 meta_src.metadata_tags.creator.author,
305 meta_src.metadata_tags.creator.contributor,
306 meta_src.metadata_tags.creator.illustrator,
307 meta_src.metadata_tags.creator.photographer,
308 meta_src.metadata_tags.creator.translator,
309 meta_src.metadata_tags.creator.audio,
310 meta_src.metadata_tags.creator.digitized_by,
311 meta_src.metadata_tags.creator.prepared_by,
312 'msgstr ""',
313 ]
314 w << [
315 "#. #{@po4a_identify_type} - metadata: rights",
316 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
317 'msgid ""',
318 meta_src.metadata_tags.rights.head,
319 meta_src.metadata_tags.rights.copyright.text,
320 meta_src.metadata_tags.rights.copyright.translation,
321 meta_src.metadata_tags.rights.copyright.illustrations,
322 meta_src.metadata_tags.rights.copyright.photographs,
323 meta_src.metadata_tags.rights.copyright.digitization,
324 meta_src.metadata_tags.rights.copyright.audio,
325 meta_src.metadata_tags.rights.license,
326 'msgstr ""',
327 ]
328 w << [
329 "#. #{@po4a_identify_type} - metadata: classify",
330 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
331 'msgid ""',
332 meta_src.metadata_tags.classify.head,
333 meta_src.metadata_tags.classify.subject,
334 meta_src.metadata_tags.classify.topic_register,
335 meta_src.metadata_tags.classify.loc,
336 meta_src.metadata_tags.classify.dewey,
337 #meta_src.metadata_tags.notes.relation,
338 #meta_src.metadata_tags.notes.type,
339 #meta_src.metadata_tags.identifier.oclc,
340 #meta_src.metadata_tags.identifier.isbn,
341 'msgstr ""',
342 ]
343 w << [
344 "#. #{@po4a_identify_type} - metadata: date",
345 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
346 'msgid ""',
347 meta_src.metadata_tags.date.head,
348 meta_src.metadata_tags.date.added_to_site,
349 meta_src.metadata_tags.date.available,
350 meta_src.metadata_tags.date.created,
351 meta_src.metadata_tags.date.issued,
352 meta_src.metadata_tags.date.modified,
353 meta_src.metadata_tags.date.published,
354 meta_src.metadata_tags.date.valid,
355 'msgstr ""',
356 ]
357 w << [
358 "#. #{@po4a_identify_type} - processing, make instruction",
359 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
360 'msgid ""',
361 meta_src.processing_tags.make.language,
362 meta_src.processing_tags.make.headings,
363 meta_src.processing_tags.make.num_top,
364 meta_src.processing_tags.make.breaks,
365 meta_src.processing_tags.make.emphasis,
366 meta_src.processing_tags.make.bold,
367 meta_src.processing_tags.make.italics,
368 meta_src.processing_tags.make.texpdf_font,
369 'msgstr ""',
370 ]
371 w.each do |y|
372 z=''
373 y.each do |x|
374 if x
375 z += x + "\n" if x =~/^#|^msg(?:id|str)/
376 z += %{"#{x}"\n} if x =~/^@\S+?:(?: |$)/
377 z += %{"#{x}"\n} if x =~/^\s+:\S+?: /
378 end
379 end
380 @pot[:metadata] << z << br
381 #puts z unless z.empty?
382 end
383 end
384 def pot_metadata_src_trn
385 @po4a_identify_type='type: SiSU doc'
386 #@po4a_identify_type='type: Plain text'
387 meta_src=SiSU_Metadata::Summary.new(@md_src)
388 meta_trn=SiSU_Metadata::Summary.new(@md_trn)
389 w=[]
390 w << [
391 "#. #{@po4a_identify_type} - metadata: title",
392 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
393 'msgid ""',
394 meta_src.metadata_tags.title.main,
395 meta_src.metadata_tags.title.sub,
396 meta_src.metadata_tags.title.edition,
397 meta_src.metadata_tags.title.note,
398 meta_src.metadata_tags.title.short,
399 meta_src.metadata_tags.title.language,
400 meta_src.metadata_tags.title.language_char,
401 'msgstr ""',
402 meta_trn.metadata_tags.title.main,
403 meta_trn.metadata_tags.title.sub,
404 meta_trn.metadata_tags.title.edition,
405 meta_trn.metadata_tags.title.note,
406 meta_trn.metadata_tags.title.short,
407 meta_trn.metadata_tags.title.language,
408 meta_trn.metadata_tags.title.language_char,
409 ]
410 w << [
411 "#. #{@po4a_identify_type} - metadata: creator",
412 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
413 'msgid ""',
414 meta_src.metadata_tags.creator.head,
415 meta_src.metadata_tags.creator.author,
416 meta_src.metadata_tags.creator.contributor,
417 meta_src.metadata_tags.creator.illustrator,
418 meta_src.metadata_tags.creator.photographer,
419 meta_src.metadata_tags.creator.translator,
420 meta_src.metadata_tags.creator.audio,
421 meta_src.metadata_tags.creator.digitized_by,
422 meta_src.metadata_tags.creator.prepared_by,
423 'msgstr ""',
424 meta_trn.metadata_tags.creator.head,
425 meta_trn.metadata_tags.creator.author,
426 meta_trn.metadata_tags.creator.contributor,
427 meta_trn.metadata_tags.creator.illustrator,
428 meta_trn.metadata_tags.creator.photographer,
429 meta_trn.metadata_tags.creator.translator,
430 meta_trn.metadata_tags.creator.audio,
431 meta_trn.metadata_tags.creator.digitized_by,
432 meta_trn.metadata_tags.creator.prepared_by,
433 ]
434 w << [
435 "#. #{@po4a_identify_type} - metadata: rights",
436 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
437 'msgid ""',
438 meta_src.metadata_tags.rights.head,
439 meta_src.metadata_tags.rights.copyright.text,
440 meta_src.metadata_tags.rights.copyright.translation,
441 meta_src.metadata_tags.rights.copyright.illustrations,
442 meta_src.metadata_tags.rights.copyright.photographs,
443 meta_src.metadata_tags.rights.copyright.digitization,
444 meta_src.metadata_tags.rights.copyright.audio,
445 meta_src.metadata_tags.rights.license,
446 'msgstr ""',
447 meta_trn.metadata_tags.rights.head,
448 meta_trn.metadata_tags.rights.copyright.text,
449 meta_trn.metadata_tags.rights.copyright.translation,
450 meta_trn.metadata_tags.rights.copyright.illustrations,
451 meta_trn.metadata_tags.rights.copyright.photographs,
452 meta_trn.metadata_tags.rights.copyright.digitization,
453 meta_trn.metadata_tags.rights.copyright.audio,
454 meta_trn.metadata_tags.rights.license,
455 ]
456 w << [
457 "#. #{@po4a_identify_type} - metadata: classify",
458 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
459 'msgid ""',
460 meta_src.metadata_tags.classify.head,
461 meta_src.metadata_tags.classify.subject,
462 meta_src.metadata_tags.classify.topic_register,
463 meta_src.metadata_tags.classify.loc,
464 meta_src.metadata_tags.classify.dewey,
465 #meta_src.metadata_tags.notes.relation,
466 #meta_src.metadata_tags.notes.type,
467 #meta_src.metadata_tags.identifier.oclc,
468 #meta_src.metadata_tags.identifier.isbn,
469 'msgstr ""',
470 meta_trn.metadata_tags.classify.head,
471 meta_trn.metadata_tags.classify.subject,
472 meta_trn.metadata_tags.classify.topic_register,
473 meta_trn.metadata_tags.classify.loc,
474 meta_trn.metadata_tags.classify.dewey,
475 #meta_trn.metadata_tags.notes.relation,
476 #meta_trn.metadata_tags.notes.type,
477 #meta_trn.metadata_tags.identifier.oclc,
478 #meta_trn.metadata_tags.identifier.isbn,
479 ]
480 w << [
481 "#. #{@po4a_identify_type} - metadata: date",
482 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
483 'msgid ""',
484 meta_src.metadata_tags.date.head,
485 meta_src.metadata_tags.date.added_to_site,
486 meta_src.metadata_tags.date.available,
487 meta_src.metadata_tags.date.created,
488 meta_src.metadata_tags.date.issued,
489 meta_src.metadata_tags.date.modified,
490 meta_src.metadata_tags.date.published,
491 meta_src.metadata_tags.date.valid,
492 'msgstr ""',
493 meta_trn.metadata_tags.date.head,
494 meta_trn.metadata_tags.date.added_to_site,
495 meta_trn.metadata_tags.date.available,
496 meta_trn.metadata_tags.date.created,
497 meta_trn.metadata_tags.date.issued,
498 meta_trn.metadata_tags.date.modified,
499 meta_trn.metadata_tags.date.published,
500 meta_trn.metadata_tags.date.valid,
501 ]
502 w << [
503 "#. #{@po4a_identify_type} - processing, make instruction",
504 "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
505 'msgid ""',
506 meta_src.processing_tags.make.language,
507 meta_src.processing_tags.make.headings,
508 meta_src.processing_tags.make.num_top,
509 meta_src.processing_tags.make.breaks,
510 meta_src.processing_tags.make.emphasis,
511 meta_src.processing_tags.make.bold,
512 meta_src.processing_tags.make.italics,
513 meta_src.processing_tags.make.texpdf_font,
514 'msgstr ""',
515 meta_trn.processing_tags.make.language,
516 meta_trn.processing_tags.make.headings,
517 meta_trn.processing_tags.make.num_top,
518 meta_trn.processing_tags.make.breaks,
519 meta_trn.processing_tags.make.emphasis,
520 meta_trn.processing_tags.make.bold,
521 meta_trn.processing_tags.make.italics,
522 meta_trn.processing_tags.make.texpdf_font,
523 ]
524 w.each do |y|
525 z=''
526 y.each do |x|
527 if x
528 z += x + "\n" if x =~/^#|^msg(?:id|str)/
529 z += %{"#{x}"\n} if x =~/^@\S+?:(?: |$)/
530 z += %{"#{x}"\n} if x =~/^\s+:\S+?: /
531 end
532 end
533 @pot[:metadata] << z << br
534 #puts z unless z.empty?
535 end
536 end
537 def pot_structure(desc,orig,trans,indent=0,hang=0)
538 SiSU_Po4aUtils::Wrap.new(
539 @md,
540 orig,
541 trans,
542 desc,
543 @wrap_width,
544 indent,
545 hang
546 )
547 end
548 def auto_translate?(set=nil)
549 @@auto_translation_=set \
550 ? set
551 : @@auto_translation_
552 end
553 def auto_translation(src_txt) # check for an appropriate request flag
554 begin
555 trans=''
556 unless auto_translate? == :skip
557 require 'timeout'
558 Timeout::timeout(5) {
559 #trans=`trans en:#{@md.opt.f_pth[:lng]} #{src_txt}` #+ ' ,{[G.Tr]},'
560 }
561 end
562 trans
563 rescue
564 auto_translate?(:skip)
565 p 'timeout issues with translation, skip remaining'
566 end
567 end
568 def pot_structure_heading(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
569 lv=n=n3=nil
570 lv=dob_src.ln
571 n=lv - 1
572 n3=lv + 2
573 util=nil
574 fn=(dob_src.name=~/[a-z\d]/i) ? dob_src.name : ''
575 mark="#{dob_src.lv}~#{fn} "
576 d="#{dob_src.is.to_s} (level #{dob_src.lv})"
577 instruct=s_mark=''
578 if @md.opt.act[:maintenance][:set]==:on
579 instruct=%{\n# markup for headings is marker at the start of the line/object, } \
580 + %{indicating the heading level, and if provided an associated name tag, } \
581 + %{this heading is "#{mark}"}
582 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
583 end
584 desc="#{d}#{s_mark}#{instruct}"
585 orig="#{s_mark}#{dob_src.obj}"
586 trans=((dob_trn=='') \
587 || (dob_src.obj == dob_trn.obj)) \
588 ? ''
589 : "#{s_mark}#{dob_trn.obj}"
590 if trans.empty? # and --auto-trans
591 trans=auto_translation(dob_src.obj)
592 end
593 util=pot_structure(desc,orig,trans)
594 wrapped=util.line_wrap
595 @pot[:body] << wrapped << br # main text, contents, body KEEP
596 if @@endnotes[:para] \
597 and notes_s.length > 0 \
598 and not @@endnotes_
599 @pot[:body] << br
600 wrap_endnotes(notes_s,notes_t)
601 elsif @@endnotes[:para] \
602 and @@endnotes_
603 @pot[:body] << br*2
604 end
605 end
606 def pot_structure_para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
607 util=nil
608 wrapped=if dob_src.indent =~/[1-9]/ \
609 and dob_src.indent == dob_src.hang
610 s_mark=desc=orig=trans=''
611 if dob_src.bullet_
612 mark="_#{dob_src.indent}* "
613 d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet"
614 instruct=s_mark=''
615 if @md.opt.act[:maintenance][:set]==:on
616 instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \
617 + %{an underscore followed by the indent level and an asterisk "#{mark}"}
618 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
619 end
620 desc="#{d}#{s_mark}#{instruct}"
621 else
622 mark="_#{dob_src.indent} "
623 d="#{dob_src.is.to_s}: indent #{dob_src.indent}"
624 instruct=s_mark=''
625 if @md.opt.act[:maintenance][:set]==:on
626 instruct=%{\n# markup for indented text is at the start of the line/object, } \
627 + %{an underscore followed by the indent level "#{mark}"}
628 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
629 end
630 desc="#{d}#{s_mark}#{instruct}"
631 end
632 orig="#{s_mark}#{dob_src.obj}"
633 trans=((dob_trn=='') \
634 || (dob_src.obj == dob_trn.obj)) \
635 ? ''
636 : "#{s_mark}#{dob_trn.obj}"
637 if trans.empty? # and --auto-trans
638 trans=auto_translation(dob_src.obj)
639 end
640 util=pot_structure(desc,orig,trans)
641 elsif dob_src.hang =~/[0-9]/ \
642 and dob_src.indent != dob_src.hang
643 s_mark=desc=orig=trans=''
644 mark="_#{dob_src.hang}_#{dob_src.indent} "
645 d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}"
646 instruct=s_mark=''
647 if @md.opt.act[:maintenance][:set]==:on
648 instruct=%{\n# markup for indented text with a first line indented } \
649 + %{to a different level from the rest of the paragraph, } \
650 + %{is at the start of the line/object, } \
651 + %{an underscore and the first indent level } \
652 + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"}
653 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
654 end
655 desc="#{d}#{s_mark}#{instruct}"
656 orig="#{s_mark}#{dob_src.obj}"
657 trans=((dob_trn=='') \
658 || (dob_src.obj == dob_trn.obj)) \
659 ? ''
660 : "#{s_mark}#{dob_trn.obj}"
661 if trans.empty? # and --auto-trans
662 trans=auto_translation(dob_src.obj)
663 end
664 util=pot_structure(desc,orig,trans)
665 else
666 s_mark=desc=orig=trans=''
667 if dob_src.bullet_
668 mark='_* '
669 d="#{dob_src.is.to_s}: bullet"
670 instruct=s_mark=''
671 if @md.opt.act[:maintenance][:set]==:on
672 instruct=%{\n# markup for indented text is at the start of the line/object, } \
673 + %{an underscore followed by an asterisk "#{mark}"}
674 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
675 end
676 desc="#{d}#{s_mark}#{instruct}"
677 orig="#{s_mark}#{dob_src.obj}"
678 trans=((dob_trn=='') \
679 || (dob_src.obj == dob_trn.obj)) \
680 ? ''
681 : "#{s_mark}#{dob_trn.obj}"
682 if trans.empty? # and --auto-trans
683 trans=auto_translation(dob_src.obj)
684 end
685 else
686 mark=''
687 d=dob_src.is.to_s
688 instruct=%{\n# regular paragraph, no special markup}
689 if @md.opt.act[:maintenance][:set]==:on
690 instruct="\n# "
691 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
692 end
693 desc="#{d}#{s_mark}#{instruct}"
694 orig=dob_src.obj
695 trans=((dob_trn=='') \
696 || (dob_src.obj == dob_trn.obj)) \
697 ? ''
698 : "#{s_mark}#{dob_trn.obj}"
699 if trans.empty? # and --auto-trans
700 trans=auto_translation(dob_src.obj)
701 end
702 end
703 util=pot_structure(desc,orig,trans)
704 end
705 wrapped=util.line_wrap
706 @pot[:body] << wrapped << br # main text, contents, body KEEP
707 if @@endnotes[:para] \
708 and notes_s.length > 0 \
709 and not @@endnotes_
710 @pot[:body] << br
711 wrap_endnotes(notes_s,notes_t)
712 elsif @@endnotes[:para] \
713 and @@endnotes_
714 @pot[:body] << br*2
715 end
716 end
717 def pot_structure_block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
718 mark="block{\\n\\n...\\n\\n}block"
719 d=dob_src.is.to_s
720 instruct=s_mark=''
721 if @md.opt.act[:maintenance][:set]==:on
722 instruct=%{\n# block text is a text block with an opening and closing marker, } \
723 + %{the content of which may be wrapped}
724 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
725 end
726 desc="#{d}#{s_mark}#{instruct}"
727 orig=dob_src.obj
728 trans=((dob_trn=='') \
729 || (dob_src.obj == dob_trn.obj)) \
730 ? ''
731 : "#{s_mark}#{dob_trn.obj}"
732 if trans.empty? # and --auto-trans
733 trans=auto_translation(dob_src.obj)
734 end
735 util=pot_structure(desc,orig,trans)
736 unwrapped=util.no_line_wrap_block
737 @pot[:body] << unwrapped << br
738 end
739 def pot_structure_group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
740 mark="group{\\n\\n...\\n\\n}group"
741 d=dob_src.is.to_s
742 instruct=s_mark=''
743 if @md.opt.act[:maintenance][:set]==:on
744 instruct=%{\n# group text is a text block with an opening and closing marker, } \
745 + %{the content of which may be wrapped}
746 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
747 end
748 desc="#{d}#{s_mark}#{instruct}"
749 orig=dob_src.obj
750 trans=((dob_trn=='') \
751 || (dob_src.obj == dob_trn.obj)) \
752 ? ''
753 : "#{s_mark}#{dob_trn.obj}"
754 if trans.empty? # and --auto-trans
755 trans=auto_translation(dob_src.obj)
756 end
757 util=pot_structure(desc,orig,trans)
758 unwrapped=util.no_line_wrap_block
759 @pot[:body] << unwrapped << br
760 end
761 def pot_structure_verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
762 mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem"
763 d=dob_src.is.to_s
764 instruct=s_mark=''
765 if @md.opt.act[:maintenance][:set]==:on
766 instruct=%{\n# verse are part of the text block described as a poem, } \
767 + %{the first verse is preceeded by an opening marker, } \
768 + %{and the last verse by a closing marker, } \
769 + %{the content of which should remain unwrapped}
770 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
771 end
772 desc="#{d}#{s_mark}#{instruct}"
773 orig=dob_src.obj
774 trans=(dob_trn=='') ? '' : dob_trn.obj
775 util=pot_structure(desc,orig,trans)
776 unwrapped=util.no_line_wrap_block
777 @pot[:body] << unwrapped << br
778 end
779 def pot_structure_code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
780 mark="code{\\n\\n...\\n\\n}code"
781 d=dob_src.is.to_s
782 instruct=s_mark=''
783 if @md.opt.act[:maintenance][:set]==:on
784 instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \
785 + %{the content of which should remain unwrapped}
786 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
787 end
788 desc="#{d}#{s_mark}#{instruct}"
789 orig=dob_src.obj
790 trans=(dob_trn=='') ? '' : dob_trn.obj
791 util=pot_structure(desc,orig,trans)
792 unwrapped=util.no_line_wrap_block
793 @pot[:body] << unwrapped << br
794 end
795 def pot_structure_table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
796 mark="table{\\n\\n...\\n\\n}table"
797 d=dob_src.is.to_s
798 instruct=s_mark=''
799 if @md.opt.act[:maintenance][:set]==:on
800 instruct=%{\n# tables are a text block with an opening and closing marker, } \
801 + %{the content of which should remain unwrapped}
802 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
803 end
804 desc="#{d}#{s_mark}#{instruct}"
805 orig=dob_src.obj
806 orig=orig.gsub(/#{Mx[:tc_c]}/,"\n")
807 trans=(dob_trn=='') ? '' : dob_trn.obj
808 trans=trans.gsub(/#{Mx[:tc_c]}/,"\n")
809 util=pot_structure(desc,orig,trans)
810 unwrapped=util.no_line_wrap_block
811 @pot[:body] << unwrapped << br
812 end
813 def pot_structure_idx_markup(idx)
814 struct=['={']
815 idx.sort.each do |x|
816 x.each_with_index do |y,i0|
817 case y
818 when String
819 struct << ';' unless struct[-1] =~/=\{/
820 struct << y
821 if x[i0+1].class == Hash \
822 and x[i0+1][:sub].length > 0
823 struct << ':'
824 end
825 when Hash
826 if y[:plus].to_i > 0
827 struct << '+' + y[:plus].to_s
828 end
829 if y[:sub].length > 0
830 y[:sub].each_with_index do |z,i1|
831 z.each_with_index do |a,i2|
832 #p a
833 if z.length > 0
834 struct << a[0]
835 if a[1][:plus].to_i > 0
836 struct << '+' + a[1][:plus].to_s
837 end
838 if (i1 + 1) < y[:sub].length
839 struct << '|'
840 end
841 end
842 end
843 end
844 end
845 end
846 end
847 end
848 struct << '}'
849 #puts struct.join
850 struct.join
851 end
852 def pot_structure_idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix
853 mark="={ ... }"
854 instruct=s_mark=''
855 if @md.opt.act[:maintenance][:set]==:on
856 instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
857 + %{(there should be a new line, but no empty line)}
858 s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
859 end
860 d='book-idx'
861 desc="#{d}#{s_mark}#{instruct}"
862 orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
863 trans=if defined? dob_trn.idx \
864 and not dob_trn.idx.nil? \
865 and not dob_trn.idx.empty?
866 pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
867 else ''
868 end
869 util=pot_structure(desc,orig,trans)
870 unwrapped=util.no_line_wrap_block
871 @pot[:body] << unwrapped << br
872 end
873 def pot_markup(data_src,data_trn)
874 #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
875 a_l=if data_trn
876 a_l=(data_src.length >= data_trn.length) \
877 ? data_src.length
878 : data_trn.length
879 else
880 data_src.length
881 end
882 s,t=0,0
883 if @md.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/
884 (data_trn.nil?) \
885 ? pot_metadata_src
886 : pot_metadata_src_trn
887 end
888 0.upto(a_l-1) do |i|
889 if data_trn
890 unless data_src[s] \
891 and data_trn[t]
892 break
893 end
894 if data_src[s].of == :comment \
895 and data_trn[t].of == :comment \
896 and (data_src[s].is == data_trn[t].is)
897 s+=1;t+=1
898 next
899 end
900 if ((data_src[s].is == :comment) \
901 || (data_trn[t].is == :comment)) \
902 and (data_src[s].is != data_trn[t].is)
903 if data_src[s].is == :comment
904 if @md.opt.act[:maintenance][:set]==:on
905 puts "src (comment):\n\t" \
906 + data_src[s].obj
907 end
908 s+=1
909 #next if data_src[s].is == :comment
910 elsif data_trn[t].is == :comment
911 if @md.opt.act[:maintenance][:set]==:on
912 puts "trans (comment):\n\t" \
913 + data_trn[t].obj
914 end
915 t+=1
916 #next if data_trn[t].is == :comment
917 end
918 end
919 if ((defined? data_src[s].ocn) \
920 && (data_src[s].ocn.is_a?(Fixnum))) \
921 and ((defined? data_trn[t].ocn) \
922 && (data_trn[t].ocn.is_a?(Fixnum))) \
923 and (data_src[s].ocn == data_trn[t].ocn)
924 @m_s,@m_t=s,t
925 elsif ((defined? data_src[s].ocn) \
926 && (data_src[s].ocn.is_a?(Fixnum))) \
927 and ((defined? data_trn[t].ocn) \
928 && (data_trn[t].ocn.is_a?(Fixnum))) \
929 and (data_src[s].ocn != data_trn[t].ocn)
930 p '--- OCN ---'
931 p 'mis-match'
932 p data_src[s].ocn
933 p data_src[s].obj
934 p data_trn[t].ocn
935 p data_trn[t].obj
936 p '---'
937 p 'previous match'
938 p data_src[@m_s].ocn
939 p data_src[@m_s].obj
940 p data_trn[@m_t].ocn
941 p data_trn[@m_t].obj
942 exit
943 elsif (((defined? data_src[s].ocn) \
944 && (defined? data_trn[t].ocn)) \
945 and data_src[s].ocn.class != data_trn[t].ocn.class)
946 p '--- OCN class ---'
947 p 'mis-match'
948 p data_src[s].ocn if defined? data_src[s].ocn
949 p data_src[s].obj
950 p data_trn[t].ocn if defined? data_trn[t].ocn
951 p data_trn[t].obj
952 #p '---'
953 #p 'previous match'
954 #p data_src[@m_s].ocn
955 #p data_src[@m_s].obj
956 #p data_trn[@m_t].ocn
957 #p data_trn[@m_t].obj
958 #elsif (defined? data_src[s].ocn != defined? data_trn[t].ocn) \
959 #and (data_src[s].ocn.nil? != data_trn[t].ocn.nil?)
960 # p '--- missing OCN? ---'
961 # p 'mis-match'
962 # p data_src[s].ocn if defined? data_src[s].ocn
963 # p data_src[s].obj
964 # p data_trn[t].ocn if defined? data_trn[t].ocn
965 # p data_trn[t].obj
966 else
967 end
968 end
969 notes_s,notes_t='',''
970 data_src[s],notes_s=markup(data_src[s])
971 if data_trn
972 data_trn[t],notes_t=markup(data_trn[t])
973 #data_src[s],data_trn[t]=pot_data(data_src[s],notes_s,data_trn[t],notes_t)
974 pot_data(data_src[s],notes_s,data_trn[t],notes_t)
975 else
976 #data_src[s],nul=pot_data(data_src[s],notes_s)
977 pot_data(data_src[s],notes_s)
978 end
979 s+=1;t+=1
980 end
981 @pot #watch
982 end
983 def pot_data(dob_src='',notes_s='',dob_trn='',notes_t='')
984 if dob_src.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/
985 if defined? dob_src.ocn \
986 and dob_src.ocn.to_s =~/\d+/
987 paranum=dob_src.ocn.to_s
988 @p_num=SiSU_Po4aUtils::ParagraphNumber.new(paranum)
989 end
990 case dob_src.is
991 when :heading
992 pot_structure_heading(dob_src,notes_s,dob_trn,notes_t)
993 when :para
994 pot_structure_para(dob_src,notes_s,dob_trn,notes_t)
995 when :group
996 pot_structure_group(dob_src,notes_s,dob_trn,notes_t)
997 when :block
998 pot_structure_block(dob_src,notes_s,dob_trn,notes_t)
999 when :verse
1000 pot_structure_verse(dob_src,notes_s,dob_trn,notes_t)
1001 when :code
1002 pot_structure_code(dob_src,notes_s,dob_trn,notes_t)
1003 when :table
1004 pot_structure_table(dob_src,notes_s,dob_trn,notes_t)
1005 end
1006 if defined? dob_src.idx \
1007 and not dob_src.idx.nil? \
1008 and not dob_src.idx.empty?
1009 pot_structure_idx(dob_src,dob_trn)
1010 end
1011 dob_src='' if (dob_src.obj =~/<a name="n\d+">/ \
1012 and dob_src.obj =~/^(-\{{2}~\d+|<!e[:_]\d+!>)/) # -endnote
1013 if dob_src ## Clean Prepared Text
1014 dob_src.obj=dob_src.obj.gsub(/<!.+!>/,' ').
1015 gsub(/<:\S+>/,' ') if dob_src ## Clean Prepared Text
1016 end
1017 end
1018 #[dob_src,dob_trn]
1019 end
1020 def markup(dob) # used for major markup instructions
1021 SiSU_Env::InfoEnv.new(@md.fns)
1022 dob.obj=dob.obj.
1023 gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,
1024 "#{Px[:po_bold_o]}\\1#{Px[:po_bold_c]}").
1025 gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,
1026 "#{Px[:po_italics_o]}\\1#{Px[:po_italics_c]}").
1027 gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,
1028 "#{Px[:po_underscore_o]}\\1#{Px[:po_underscore_c]}").
1029 gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,
1030 "#{Px[:po_subscript_o]}\\1#{Px[:po_subscript_c]}").
1031 gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,
1032 "#{Px[:po_superscript_o]}\\1#{Px[:po_superscript_c]}").
1033 gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,
1034 "#{Px[:po_insert_o]}\\1#{Px[:po_insert_c]}").
1035 gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,
1036 "#{Px[:po_cite_o]}\\1#{Px[:po_cite_c]}").
1037 gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,
1038 "#{Px[:po_strike_o]}\\1#{Px[:po_strike_c]}").
1039 gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,
1040 "#{Px[:po_monospace_o]}\\1#{Px[:po_monospace_c]}")
1041 notes=''
1042 unless dob.is==:code
1043 dob.obj=dob.obj.
1044 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1').
1045 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
1046 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
1047 '\1 [link: <\2>]').
1048 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,
1049 '\1 [link: local image]').
1050 gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1')
1051 notes=extract_endnotes(dob)
1052 #% ### footnotes current state - extracted
1053 dob.obj=dob.obj.
1054 gsub(/#{Mx[:en_a_o]}([\d]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'~^'). # endnote marker marked up
1055 #% ### footnotes current state - keep inline
1056 #dob.obj.gsub!(/#{Mx[:en_a_o]}[\d]+\s+(.+?)#{Mx[:en_a_c]}/,'~{ \1 }~') # inline endnote with marker marked up
1057 gsub(/#{Mx[:en_b_o]}[\d]+\s+(.+?)#{Mx[:en_b_c]}/,
1058 '~[ \1 ]~'). # inline endnote with marker marked up
1059 gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/,
1060 '~{\1 \2 }~'). # inline endnote with marker marked up
1061 gsub(/#{Mx[:en_b_o]}([*+]+)\s+(.+?)#{Mx[:en_b_c]}/,
1062 '~[\1 \2 ]~'). # inline endnote with marker marked up
1063 gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<').
1064 gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>').
1065 gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&').
1066 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').
1067 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').
1068 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').
1069 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').
1070 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').
1071 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').
1072 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').
1073 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').
1074 gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~').
1075 gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©')
1076 end
1077 dob.obj=if dob.of==:block # watch
1078 dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/,"* ").
1079 gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n")
1080 else dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n\n")
1081 end
1082 if dob.is==:code
1083 dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _<
1084 gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_<
1085 end
1086 dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}/,''). # remove page breaks
1087 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
1088 gsub(/<a href=".+?">(.+?)<\/a>/m,'\1').
1089 gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links
1090 gsub(/&nbsp;|#{Mx[:nbsp]}/,' '). # decide on
1091 gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,
1092 ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
1093 gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,
1094 ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
1095 gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,
1096 '[image: "\1"]')
1097 [dob,notes]
1098 end
1099 def publish(fn,pot)
1100 content=[]
1101 content << pot[:open]
1102 content << pot[:head]
1103 content << pot[:metadata]
1104 content << pot[:body]
1105 content << @@endnotes[:end] if @@endnotes_
1106 Output.new(fn,content,@md,@process).po4a
1107 @@endnotes={ para: [], end: [] }
1108 end
1109 end
1110 class Output <Source
1111 include SiSU_Param
1112 include SiSU_Env
1113 def initialize(fn,content,md,process=:complete)
1114 @fn,@content,@md,@process=fn,content,md,process
1115 @file=SiSU_Env::FileOp.new(md,fn)
1116 end
1117 def po4a #%pot output
1118 file_pot=(@md.opt.f_pth[:lng] ==@md.opt.lng_base) \
1119 ? @file.write_file.pot
1120 : @file.write_file.po
1121 @sisu=[]
1122 emptyline=0
1123 @content.each do |para| # this is a hack
1124 if para.is_a?(Array) \
1125 and para.length > 0
1126 para.each do |line|
1127 if line
1128 line=line.gsub(/\s+$/m,'').
1129 gsub(/^\A[ ]*\Z/m,'')
1130 if line=~/^\A[ ]*\Z/m
1131 emptyline+=1
1132 else emptyline=0
1133 end
1134 file_pot.puts line if emptyline < 2 #remove extra line spaces (fix upstream)
1135 end
1136 end
1137 else file_pot.puts para #unix plaintext # /^([*=-]|\.){5}/
1138 end
1139 end
1140 file_pot.close
1141 SiSU_Po4aUtils::PotNumber.new.reset
1142 po4a_git
1143 end
1144 def po4a_git
1145 unless @md.opt.act[:maintenance][:set]==:on
1146 require_relative 'git' # git.rb
1147 git=SiSU_Git::Source.new(@md.opt,@process)
1148 unless FileTest.directory?(@file.output_path.pot_git.dir)
1149 git.create_file_structure_git
1150 end
1151 if @md.opt.f_pth[:lng] ==@md.opt.lng_base
1152 FileUtils::cp(
1153 @file.place_file.pot.dir,
1154 @file.output_path.pot_git.dir
1155 )
1156 else # naive, work on -->
1157 FileUtils::cp(
1158 @file.place_file.po.dir,
1159 @file.output_path.po_git.dir
1160 ) #unless FileTest.file?(@file.place_file.po_git.dir)
1161 end
1162 git.read
1163 end
1164 end
1165 end
1166 end
1167 end
1168 __END__
1169 &#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#
1170
1171 tables are problematic, difficult to reconstitute instruction, check
1172
1173 metadata, move to top? and work on
1174
1175 footnotes, different types, asterisk, also do you want to have separate
1176 paragraphs, or breaks within one block?
1177
1178 where no ocn appropriately use ~# or -# or indeed 1~name-
1179
1180 comments in document, what to do about them, not sure they are currently
1181 retained in dal, could be quite valuable to keep