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