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