d: po4a, init, if lang src == translation, empty translation field
[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 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=='') \
566 || (dob_src.obj == dob_trn.obj)) \
567 ? ''
568 : "#{s_mark}#{dob_trn.obj}"
569 util=pot_structure(desc,orig,trans)
570 wrapped=util.line_wrap
571 @pot[:body] << wrapped << br # main text, contents, body KEEP
572 if @@endnotes[:para] \
573 and notes_s.length > 0 \
574 and not @@endnotes_
575 @pot[:body] << br
576 wrap_endnotes(notes_s,notes_t)
577 elsif @@endnotes[:para] \
578 and @@endnotes_
579 @pot[:body] << br*2
580 end
581 end
582 def pot_structure_para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
583 util=nil
584 wrapped=if dob_src.indent =~/[1-9]/ \
585 and dob_src.indent == dob_src.hang
586 s_mark=desc=orig=trans=''
587 if dob_src.bullet_
588 mark="_#{dob_src.indent}* "
589 d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet"
590 instruct=s_mark=''
591 if @md.opt.act[:maintenance][:set]==:on
592 instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \
593 + %{an underscore followed by the indent level and an asterisk "#{mark}"}
594 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
595 end
596 desc="#{d}#{s_mark}#{instruct}"
597 else
598 mark="_#{dob_src.indent} "
599 d="#{dob_src.is.to_s}: indent #{dob_src.indent}"
600 instruct=s_mark=''
601 if @md.opt.act[:maintenance][:set]==:on
602 instruct=%{\n# markup for indented text is at the start of the line/object, } \
603 + %{an underscore followed by the indent level "#{mark}"}
604 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
605 end
606 desc="#{d}#{s_mark}#{instruct}"
607 end
608 orig="#{s_mark}#{dob_src.obj}"
609 trans=((dob_trn=='') \
610 || (dob_src.obj == dob_trn.obj)) \
611 ? ''
612 : "#{s_mark}#{dob_trn.obj}"
613 util=pot_structure(desc,orig,trans)
614 elsif dob_src.hang =~/[0-9]/ \
615 and dob_src.indent != dob_src.hang
616 s_mark=desc=orig=trans=''
617 mark="_#{dob_src.hang}_#{dob_src.indent} "
618 d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}"
619 instruct=s_mark=''
620 if @md.opt.act[:maintenance][:set]==:on
621 instruct=%{\n# markup for indented text with a first line indented } \
622 + %{to a different level from the rest of the paragraph, } \
623 + %{is at the start of the line/object, } \
624 + %{an underscore and the first indent level } \
625 + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"}
626 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
627 end
628 desc="#{d}#{s_mark}#{instruct}"
629 orig="#{s_mark}#{dob_src.obj}"
630 trans=((dob_trn=='') \
631 || (dob_src.obj == dob_trn.obj)) \
632 ? ''
633 : "#{s_mark}#{dob_trn.obj}"
634 util=pot_structure(desc,orig,trans)
635 else
636 s_mark=desc=orig=trans=''
637 if dob_src.bullet_
638 mark='_* '
639 d="#{dob_src.is.to_s}: bullet"
640 instruct=s_mark=''
641 if @md.opt.act[:maintenance][:set]==:on
642 instruct=%{\n# markup for indented text is at the start of the line/object, } \
643 + %{an underscore followed by an asterisk "#{mark}"}
644 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
645 end
646 desc="#{d}#{s_mark}#{instruct}"
647 orig="#{s_mark}#{dob_src.obj}"
648 trans=((dob_trn=='') \
649 || (dob_src.obj == dob_trn.obj)) \
650 ? ''
651 : "#{s_mark}#{dob_trn.obj}"
652 else
653 mark=''
654 d=dob_src.is.to_s
655 instruct=%{\n# regular paragraph, no special markup}
656 if @md.opt.act[:maintenance][:set]==:on
657 instruct="\n# "
658 s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
659 end
660 desc="#{d}#{s_mark}#{instruct}"
661 orig=dob_src.obj
662 trans=((dob_trn=='') \
663 || (dob_src.obj == dob_trn.obj)) \
664 ? ''
665 : "#{s_mark}#{dob_trn.obj}"
666 end
667 util=pot_structure(desc,orig,trans)
668 end
669 wrapped=util.line_wrap
670 @pot[:body] << wrapped << br # main text, contents, body KEEP
671 if @@endnotes[:para] \
672 and notes_s.length > 0 \
673 and not @@endnotes_
674 @pot[:body] << br
675 wrap_endnotes(notes_s,notes_t)
676 elsif @@endnotes[:para] \
677 and @@endnotes_
678 @pot[:body] << br*2
679 end
680 end
681 def pot_structure_block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
682 mark="block{\\n\\n...\\n\\n}block"
683 d=dob_src.is.to_s
684 instruct=s_mark=''
685 if @md.opt.act[:maintenance][:set]==:on
686 instruct=%{\n# block text is a text block with an opening and closing marker, } \
687 + %{the content of which may be wrapped}
688 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
689 end
690 desc="#{d}#{s_mark}#{instruct}"
691 orig=dob_src.obj
692 trans=((dob_trn=='') \
693 || (dob_src.obj == dob_trn.obj)) \
694 ? ''
695 : "#{s_mark}#{dob_trn.obj}"
696 util=pot_structure(desc,orig,trans)
697 unwrapped=util.no_line_wrap_block
698 @pot[:body] << unwrapped << br
699 end
700 def pot_structure_group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
701 mark="group{\\n\\n...\\n\\n}group"
702 d=dob_src.is.to_s
703 instruct=s_mark=''
704 if @md.opt.act[:maintenance][:set]==:on
705 instruct=%{\n# group text is a text block with an opening and closing marker, } \
706 + %{the content of which may be wrapped}
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=='') \
712 || (dob_src.obj == dob_trn.obj)) \
713 ? ''
714 : "#{s_mark}#{dob_trn.obj}"
715 util=pot_structure(desc,orig,trans)
716 unwrapped=util.no_line_wrap_block
717 @pot[:body] << unwrapped << br
718 end
719 def pot_structure_verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
720 mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem"
721 d=dob_src.is.to_s
722 instruct=s_mark=''
723 if @md.opt.act[:maintenance][:set]==:on
724 instruct=%{\n# verse are part of the text block described as a poem, } \
725 + %{the first verse is preceeded by an opening marker, } \
726 + %{and the last verse by a closing marker, } \
727 + %{the content of which should remain unwrapped}
728 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
729 end
730 desc="#{d}#{s_mark}#{instruct}"
731 orig=dob_src.obj
732 trans=(dob_trn=='') ? '' : dob_trn.obj
733 util=pot_structure(desc,orig,trans)
734 unwrapped=util.no_line_wrap_block
735 @pot[:body] << unwrapped << br
736 end
737 def pot_structure_code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
738 mark="code{\\n\\n...\\n\\n}code"
739 d=dob_src.is.to_s
740 instruct=s_mark=''
741 if @md.opt.act[:maintenance][:set]==:on
742 instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \
743 + %{the content of which should remain unwrapped}
744 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
745 end
746 desc="#{d}#{s_mark}#{instruct}"
747 orig=dob_src.obj
748 trans=(dob_trn=='') ? '' : dob_trn.obj
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_table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
754 mark="table{\\n\\n...\\n\\n}table"
755 d=dob_src.is.to_s
756 instruct=s_mark=''
757 if @md.opt.act[:maintenance][:set]==:on
758 instruct=%{\n# tables are a text block with an opening and closing marker, } \
759 + %{the content of which should remain unwrapped}
760 s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
761 end
762 desc="#{d}#{s_mark}#{instruct}"
763 orig=dob_src.obj
764 orig=orig.gsub(/#{Mx[:tc_c]}/,"\n")
765 trans=(dob_trn=='') ? '' : dob_trn.obj
766 trans=trans.gsub(/#{Mx[:tc_c]}/,"\n")
767 util=pot_structure(desc,orig,trans)
768 unwrapped=util.no_line_wrap_block
769 @pot[:body] << unwrapped << br
770 end
771 def pot_structure_idx_markup(idx)
772 struct=['={']
773 idx.sort.each do |x|
774 x.each_with_index do |y,i0|
775 case y
776 when String
777 struct << ';' unless struct[-1] =~/=\{/
778 struct << y
779 if x[i0+1].class == Hash \
780 and x[i0+1][:sub].length > 0
781 struct << ':'
782 end
783 when Hash
784 if y[:plus].to_i > 0
785 struct << '+' + y[:plus].to_s
786 end
787 if y[:sub].length > 0
788 y[:sub].each_with_index do |z,i1|
789 z.each_with_index do |a,i2|
790 #p a
791 if z.length > 0
792 struct << a[0]
793 if a[1][:plus].to_i > 0
794 struct << '+' + a[1][:plus].to_s
795 end
796 if (i1 + 1) < y[:sub].length
797 struct << '|'
798 end
799 end
800 end
801 end
802 end
803 end
804 end
805 end
806 struct << '}'
807 #puts struct.join
808 struct.join
809 end
810 def pot_structure_idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix
811 mark="={ ... }"
812 instruct=s_mark=''
813 if @md.opt.act[:maintenance][:set]==:on
814 instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
815 + %{(there should be a new line, but no empty line)}
816 s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
817 end
818 d='book-idx'
819 desc="#{d}#{s_mark}#{instruct}"
820 orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
821 trans=if defined? dob_trn.idx \
822 and not dob_trn.idx.nil? \
823 and not dob_trn.idx.empty?
824 pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
825 else ''
826 end
827 util=pot_structure(desc,orig,trans)
828 unwrapped=util.no_line_wrap_block
829 @pot[:body] << unwrapped << br
830 end
831 def pot_markup(data_src,data_trn)
832 #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
833 a_l=if data_trn
834 a_l=(data_src.length >= data_trn.length) \
835 ? data_src.length
836 : data_trn.length
837 else
838 data_src.length
839 end
840 s,t=0,0
841 if @md.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/
842 (data_trn.nil?) \
843 ? pot_metadata_src
844 : pot_metadata_src_trn
845 end
846 0.upto(a_l-1) do |i|
847 if data_trn
848 unless data_src[s] \
849 and data_trn[t]
850 break
851 end
852 if data_src[s].of == :comment \
853 and data_trn[t].of == :comment \
854 and (data_src[s].is == data_trn[t].is)
855 s+=1;t+=1
856 next
857 end
858 if ((data_src[s].is == :comment) \
859 || (data_trn[t].is == :comment)) \
860 and (data_src[s].is != data_trn[t].is)
861 if data_src[s].is == :comment
862 if @md.opt.act[:maintenance][:set]==:on
863 puts "src (comment):\n\t" \
864 + data_src[s].obj
865 end
866 s+=1
867 #next if data_src[s].is == :comment
868 elsif data_trn[t].is == :comment
869 if @md.opt.act[:maintenance][:set]==:on
870 puts "trans (comment):\n\t" \
871 + data_trn[t].obj
872 end
873 t+=1
874 #next if data_trn[t].is == :comment
875 end
876 end
877 if ((defined? data_src[s].ocn) \
878 && (data_src[s].ocn.is_a?(Fixnum))) \
879 and ((defined? data_trn[t].ocn) \
880 && (data_trn[t].ocn.is_a?(Fixnum))) \
881 and (data_src[s].ocn == data_trn[t].ocn)
882 @m_s,@m_t=s,t
883 elsif ((defined? data_src[s].ocn) \
884 && (data_src[s].ocn.is_a?(Fixnum))) \
885 and ((defined? data_trn[t].ocn) \
886 && (data_trn[t].ocn.is_a?(Fixnum))) \
887 and (data_src[s].ocn != data_trn[t].ocn)
888 p '--- OCN ---'
889 p 'mis-match'
890 p data_src[s].ocn
891 p data_src[s].obj
892 p data_trn[t].ocn
893 p data_trn[t].obj
894 p '---'
895 p 'previous match'
896 p data_src[@m_s].ocn
897 p data_src[@m_s].obj
898 p data_trn[@m_t].ocn
899 p data_trn[@m_t].obj
900 exit
901 elsif (((defined? data_src[s].ocn) \
902 && (defined? data_trn[t].ocn)) \
903 and data_src[s].ocn.class != data_trn[t].ocn.class)
904 p '--- OCN class ---'
905 p 'mis-match'
906 p data_src[s].ocn if defined? data_src[s].ocn
907 p data_src[s].obj
908 p data_trn[t].ocn if defined? data_trn[t].ocn
909 p data_trn[t].obj
910 #p '---'
911 #p 'previous match'
912 #p data_src[@m_s].ocn
913 #p data_src[@m_s].obj
914 #p data_trn[@m_t].ocn
915 #p data_trn[@m_t].obj
916 #elsif (defined? data_src[s].ocn != defined? data_trn[t].ocn) \
917 #and (data_src[s].ocn.nil? != data_trn[t].ocn.nil?)
918 # p '--- missing OCN? ---'
919 # p 'mis-match'
920 # p data_src[s].ocn if defined? data_src[s].ocn
921 # p data_src[s].obj
922 # p data_trn[t].ocn if defined? data_trn[t].ocn
923 # p data_trn[t].obj
924 else
925 end
926 end
927 notes_s,notes_t='',''
928 data_src[s],notes_s=markup(data_src[s])
929 if data_trn
930 data_trn[t],notes_t=markup(data_trn[t])
931 #data_src[s],data_trn[t]=pot_data(data_src[s],notes_s,data_trn[t],notes_t)
932 pot_data(data_src[s],notes_s,data_trn[t],notes_t)
933 else
934 #data_src[s],nul=pot_data(data_src[s],notes_s)
935 pot_data(data_src[s],notes_s)
936 end
937 s+=1;t+=1
938 end
939 @pot #watch
940 end
941 def pot_data(dob_src='',notes_s='',dob_trn='',notes_t='')
942 if dob_src.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/
943 if defined? dob_src.ocn \
944 and dob_src.ocn.to_s =~/\d+/
945 paranum=dob_src.ocn.to_s
946 @p_num=SiSU_Po4aUtils::ParagraphNumber.new(paranum)
947 end
948 case dob_src.is
949 when :heading
950 pot_structure_heading(dob_src,notes_s,dob_trn,notes_t)
951 when :para
952 pot_structure_para(dob_src,notes_s,dob_trn,notes_t)
953 when :group
954 pot_structure_group(dob_src,notes_s,dob_trn,notes_t)
955 when :block
956 pot_structure_block(dob_src,notes_s,dob_trn,notes_t)
957 when :verse
958 pot_structure_verse(dob_src,notes_s,dob_trn,notes_t)
959 when :code
960 pot_structure_code(dob_src,notes_s,dob_trn,notes_t)
961 when :table
962 pot_structure_table(dob_src,notes_s,dob_trn,notes_t)
963 end
964 if defined? dob_src.idx \
965 and not dob_src.idx.nil? \
966 and not dob_src.idx.empty?
967 pot_structure_idx(dob_src,dob_trn)
968 end
969 dob_src='' if (dob_src.obj =~/<a name="n\d+">/ \
970 and dob_src.obj =~/^(-\{{2}~\d+|<!e[:_]\d+!>)/) # -endnote
971 if dob_src ## Clean Prepared Text
972 dob_src.obj=dob_src.obj.gsub(/<!.+!>/,' ').
973 gsub(/<:\S+>/,' ') if dob_src ## Clean Prepared Text
974 end
975 end
976 #[dob_src,dob_trn]
977 end
978 def markup(dob) # used for major markup instructions
979 SiSU_Env::InfoEnv.new(@md.fns)
980 dob.obj=dob.obj.
981 gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,
982 "#{Px[:po_bold_o]}\\1#{Px[:po_bold_c]}").
983 gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,
984 "#{Px[:po_italics_o]}\\1#{Px[:po_italics_c]}").
985 gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,
986 "#{Px[:po_underscore_o]}\\1#{Px[:po_underscore_c]}").
987 gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,
988 "#{Px[:po_subscript_o]}\\1#{Px[:po_subscript_c]}").
989 gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,
990 "#{Px[:po_superscript_o]}\\1#{Px[:po_superscript_c]}").
991 gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,
992 "#{Px[:po_insert_o]}\\1#{Px[:po_insert_c]}").
993 gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,
994 "#{Px[:po_cite_o]}\\1#{Px[:po_cite_c]}").
995 gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,
996 "#{Px[:po_strike_o]}\\1#{Px[:po_strike_c]}").
997 gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,
998 "#{Px[:po_monospace_o]}\\1#{Px[:po_monospace_c]}")
999 notes=''
1000 unless dob.is==:code
1001 dob.obj=dob.obj.
1002 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1').
1003 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
1004 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
1005 '\1 [link: <\2>]').
1006 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,
1007 '\1 [link: local image]').
1008 gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1')
1009 notes=extract_endnotes(dob)
1010 #% ### footnotes current state - extracted
1011 dob.obj=dob.obj.
1012 gsub(/#{Mx[:en_a_o]}([\d]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'~^'). # endnote marker marked up
1013 #% ### footnotes current state - keep inline
1014 #dob.obj.gsub!(/#{Mx[:en_a_o]}[\d]+\s+(.+?)#{Mx[:en_a_c]}/,'~{ \1 }~') # inline endnote with marker marked up
1015 gsub(/#{Mx[:en_b_o]}[\d]+\s+(.+?)#{Mx[:en_b_c]}/,
1016 '~[ \1 ]~'). # inline endnote with marker marked up
1017 gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/,
1018 '~{\1 \2 }~'). # inline endnote with marker marked up
1019 gsub(/#{Mx[:en_b_o]}([*+]+)\s+(.+?)#{Mx[:en_b_c]}/,
1020 '~[\1 \2 ]~'). # inline endnote with marker marked up
1021 gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<').
1022 gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>').
1023 gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&').
1024 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').
1025 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').
1026 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').
1027 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').
1028 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').
1029 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').
1030 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').
1031 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').
1032 gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~').
1033 gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©')
1034 end
1035 dob.obj=if dob.of==:block # watch
1036 dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/,"* ").
1037 gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n")
1038 else dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n\n")
1039 end
1040 if dob.is==:code
1041 dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _<
1042 gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_<
1043 end
1044 dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}/,''). # remove page breaks
1045 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
1046 gsub(/<a href=".+?">(.+?)<\/a>/m,'\1').
1047 gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links
1048 gsub(/&nbsp;|#{Mx[:nbsp]}/,' '). # decide on
1049 gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,
1050 ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
1051 gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,
1052 ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
1053 gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,
1054 '[image: "\1"]')
1055 [dob,notes]
1056 end
1057 def publish(fn,pot)
1058 content=[]
1059 content << pot[:open]
1060 content << pot[:head]
1061 content << pot[:metadata]
1062 content << pot[:body]
1063 content << @@endnotes[:end] if @@endnotes_
1064 Output.new(fn,content,@md,@process).po4a
1065 @@endnotes={ para: [], end: [] }
1066 end
1067 end
1068 class Output <Source
1069 include SiSU_Param
1070 include SiSU_Env
1071 def initialize(fn,content,md,process=:complete)
1072 @fn,@content,@md,@process=fn,content,md,process
1073 @file=SiSU_Env::FileOp.new(md,fn)
1074 end
1075 def po4a #%pot output
1076 file_pot=(@md.opt.f_pth[:lng] ==@md.opt.lng_base) \
1077 ? @file.write_file.pot
1078 : @file.write_file.po
1079 @sisu=[]
1080 emptyline=0
1081 @content.each do |para| # this is a hack
1082 if para.is_a?(Array) \
1083 and para.length > 0
1084 para.each do |line|
1085 if line
1086 line=line.gsub(/\s+$/m,'').
1087 gsub(/^\A[ ]*\Z/m,'')
1088 if line=~/^\A[ ]*\Z/m
1089 emptyline+=1
1090 else emptyline=0
1091 end
1092 file_pot.puts line if emptyline < 2 #remove extra line spaces (fix upstream)
1093 end
1094 end
1095 else file_pot.puts para #unix plaintext # /^([*=-]|\.){5}/
1096 end
1097 end
1098 file_pot.close
1099 SiSU_Po4aUtils::PotNumber.new.reset
1100 po4a_git
1101 end
1102 def po4a_git
1103 unless @md.opt.act[:maintenance][:set]==:on
1104 require_relative 'git' # git.rb
1105 git=SiSU_Git::Source.new(@md.opt,@process)
1106 unless FileTest.directory?(@file.output_path.pot_git.dir)
1107 git.create_file_structure_git
1108 end
1109 if @md.opt.f_pth[:lng] ==@md.opt.lng_base
1110 FileUtils::cp(
1111 @file.place_file.pot.dir,
1112 @file.output_path.pot_git.dir
1113 )
1114 else # naive, work on -->
1115 FileUtils::cp(
1116 @file.place_file.po.dir,
1117 @file.output_path.po_git.dir
1118 ) #unless FileTest.file?(@file.place_file.po_git.dir)
1119 end
1120 git.read
1121 end
1122 end
1123 end
1124 end
1125 end
1126 __END__
1127 &#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#
1128
1129 tables are problematic, difficult to reconstitute instruction, check
1130
1131 metadata, move to top? and work on
1132
1133 footnotes, different types, asterisk, also do you want to have separate
1134 paragraphs, or breaks within one block?
1135
1136 where no ocn appropriately use ~# or -# or indeed 1~name-
1137
1138 comments in document, what to do about them, not sure they are currently
1139 retained in dal, could be quite valuable to keep