c&d: po4a, book index, reinstate
[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_markup(idx)
751 struct=['={']
752 idx.sort.each do |x|
753 x.each_with_index do |y,i0|
754 case y
755 when String
756 struct << ';' unless struct[-1] =~/=\{/
757 struct << y
758 if x[i0+1].class == Hash \
759 and x[i0+1][:sub].length > 0
760 struct << ':'
761 end
762 when Hash
763 if y[:plus].to_i > 0
764 struct << '+' + y[:plus].to_s
765 end
766 if y[:sub].length > 0
767 y[:sub].each_with_index do |z,i1|
768 z.each_with_index do |a,i2|
769 #p a
770 if z.length > 0
771 struct << a[0]
772 if a[1][:plus].to_i > 0
773 struct << '+' + a[1][:plus].to_s
774 end
775 if (i1 + 1) < y[:sub].length
776 struct << '|'
777 end
778 end
779 end
780 end
781 end
782 end
783 end
784 end
785 struct << '}'
786 #puts struct.join
787 struct.join
788 end
789 def pot_structure_idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix
790 mark="={ ... }"
791 instruct=s_mark=''
792 if @md.opt.act[:maintenance][:set]==:on
793 instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
794 + %{(there should be a new line, but no empty line)}
795 s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
796 end
797 d='book-idx'
798 desc="#{d}#{s_mark}#{instruct}"
799 orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
800 trans=if defined? dob_trn.idx \
801 and not dob_trn.idx.nil? \
802 and not dob_trn.idx.empty?
803 pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
804 else ''
805 end
806 util=pot_structure(desc,orig,trans)
807 unwrapped=util.no_line_wrap_block
808 @pot[:body] << unwrapped << br
809 end
810 def pot_markup(data_src,data_trn)
811 #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
812 a_l=if data_trn
813 a_l=(data_src.length >= data_trn.length) \
814 ? data_src.length
815 : data_trn.length
816 else
817 data_src.length
818 end
819 s,t=0,0
820 if @md.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/
821 (data_trn.nil?) \
822 ? pot_metadata_src
823 : pot_metadata_src_trn
824 end
825 0.upto(a_l-1) do |i|
826 if data_trn
827 unless data_src[s] \
828 and data_trn[t]
829 break
830 end
831 if data_src[s].of == :comment \
832 and data_trn[t].of == :comment \
833 and (data_src[s].is == data_trn[t].is)
834 s+=1;t+=1
835 next
836 end
837 if ((data_src[s].is == :comment) \
838 || (data_trn[t].is == :comment)) \
839 and (data_src[s].is != data_trn[t].is)
840 if data_src[s].is == :comment
841 if @md.opt.act[:maintenance][:set]==:on
842 puts "src (comment):\n\t" \
843 + data_src[s].obj
844 end
845 s+=1
846 #next if data_src[s].is == :comment
847 elsif data_trn[t].is == :comment
848 if @md.opt.act[:maintenance][:set]==:on
849 puts "trans (comment):\n\t" \
850 + data_trn[t].obj
851 end
852 t+=1
853 #next if data_trn[t].is == :comment
854 end
855 end
856 if ((defined? data_src[s].ocn) \
857 && (data_src[s].ocn.is_a?(Fixnum))) \
858 and ((defined? data_trn[t].ocn) \
859 && (data_trn[t].ocn.is_a?(Fixnum))) \
860 and (data_src[s].ocn == data_trn[t].ocn)
861 @m_s,@m_t=s,t
862 elsif ((defined? data_src[s].ocn) \
863 && (data_src[s].ocn.is_a?(Fixnum))) \
864 and ((defined? data_trn[t].ocn) \
865 && (data_trn[t].ocn.is_a?(Fixnum))) \
866 and (data_src[s].ocn != data_trn[t].ocn)
867 p '--- OCN ---'
868 p 'mis-match'
869 p data_src[s].ocn
870 p data_src[s].obj
871 p data_trn[t].ocn
872 p data_trn[t].obj
873 p '---'
874 p 'previous match'
875 p data_src[@m_s].ocn
876 p data_src[@m_s].obj
877 p data_trn[@m_t].ocn
878 p data_trn[@m_t].obj
879 exit
880 elsif (((defined? data_src[s].ocn) \
881 && (defined? data_trn[t].ocn)) \
882 and data_src[s].ocn.class != data_trn[t].ocn.class)
883 p '--- OCN class ---'
884 p 'mis-match'
885 p data_src[s].ocn if defined? data_src[s].ocn
886 p data_src[s].obj
887 p data_trn[t].ocn if defined? data_trn[t].ocn
888 p data_trn[t].obj
889 #p '---'
890 #p 'previous match'
891 #p data_src[@m_s].ocn
892 #p data_src[@m_s].obj
893 #p data_trn[@m_t].ocn
894 #p data_trn[@m_t].obj
895 #elsif (defined? data_src[s].ocn != defined? data_trn[t].ocn) \
896 #and (data_src[s].ocn.nil? != data_trn[t].ocn.nil?)
897 # p '--- missing OCN? ---'
898 # p 'mis-match'
899 # p data_src[s].ocn if defined? data_src[s].ocn
900 # p data_src[s].obj
901 # p data_trn[t].ocn if defined? data_trn[t].ocn
902 # p data_trn[t].obj
903 else
904 end
905 end
906 notes_s,notes_t='',''
907 data_src[s],notes_s=markup(data_src[s])
908 if data_trn
909 data_trn[t],notes_t=markup(data_trn[t])
910 #data_src[s],data_trn[t]=pot_data(data_src[s],notes_s,data_trn[t],notes_t)
911 pot_data(data_src[s],notes_s,data_trn[t],notes_t)
912 else
913 #data_src[s],nul=pot_data(data_src[s],notes_s)
914 pot_data(data_src[s],notes_s)
915 end
916 s+=1;t+=1
917 end
918 @pot #watch
919 end
920 def pot_data(dob_src='',notes_s='',dob_trn='',notes_t='')
921 if dob_src.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/
922 if defined? dob_src.ocn \
923 and dob_src.ocn.to_s =~/\d+/
924 paranum=dob_src.ocn.to_s
925 @p_num=SiSU_Po4aUtils::ParagraphNumber.new(paranum)
926 end
927 case dob_src.is
928 when :heading
929 pot_structure_heading(dob_src,notes_s,dob_trn,notes_t)
930 when :para
931 pot_structure_para(dob_src,notes_s,dob_trn,notes_t)
932 when :group
933 pot_structure_group(dob_src,notes_s,dob_trn,notes_t)
934 when :block
935 pot_structure_block(dob_src,notes_s,dob_trn,notes_t)
936 when :verse
937 pot_structure_verse(dob_src,notes_s,dob_trn,notes_t)
938 when :code
939 pot_structure_code(dob_src,notes_s,dob_trn,notes_t)
940 when :table
941 pot_structure_table(dob_src,notes_s,dob_trn,notes_t)
942 end
943 if defined? dob_src.idx \
944 and not dob_src.idx.nil? \
945 and not dob_src.idx.empty?
946 pot_structure_idx(dob_src,dob_trn)
947 end
948 dob_src='' if (dob_src.obj =~/<a name="n\d+">/ \
949 and dob_src.obj =~/^(-\{{2}~\d+|<!e[:_]\d+!>)/) # -endnote
950 if dob_src ## Clean Prepared Text
951 dob_src.obj=dob_src.obj.gsub(/<!.+!>/,' ').
952 gsub(/<:\S+>/,' ') if dob_src ## Clean Prepared Text
953 end
954 end
955 #[dob_src,dob_trn]
956 end
957 def markup(dob) # used for major markup instructions
958 SiSU_Env::InfoEnv.new(@md.fns)
959 dob.obj=dob.obj.
960 gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,
961 "#{Px[:po_bold_o]}\\1#{Px[:po_bold_c]}").
962 gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,
963 "#{Px[:po_italics_o]}\\1#{Px[:po_italics_c]}").
964 gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,
965 "#{Px[:po_underscore_o]}\\1#{Px[:po_underscore_c]}").
966 gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,
967 "#{Px[:po_subscript_o]}\\1#{Px[:po_subscript_c]}").
968 gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,
969 "#{Px[:po_superscript_o]}\\1#{Px[:po_superscript_c]}").
970 gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,
971 "#{Px[:po_insert_o]}\\1#{Px[:po_insert_c]}").
972 gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,
973 "#{Px[:po_cite_o]}\\1#{Px[:po_cite_c]}").
974 gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,
975 "#{Px[:po_strike_o]}\\1#{Px[:po_strike_c]}").
976 gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,
977 "#{Px[:po_monospace_o]}\\1#{Px[:po_monospace_c]}")
978 notes=''
979 unless dob.is==:code
980 dob.obj=dob.obj.
981 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1').
982 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
983 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
984 '\1 [link: <\2>]').
985 gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,
986 '\1 [link: local image]').
987 gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1')
988 notes=extract_endnotes(dob)
989 #% ### footnotes current state - extracted
990 dob.obj=dob.obj.
991 gsub(/#{Mx[:en_a_o]}([\d]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'~^'). # endnote marker marked up
992 #% ### footnotes current state - keep inline
993 #dob.obj.gsub!(/#{Mx[:en_a_o]}[\d]+\s+(.+?)#{Mx[:en_a_c]}/,'~{ \1 }~') # inline endnote with marker marked up
994 gsub(/#{Mx[:en_b_o]}[\d]+\s+(.+?)#{Mx[:en_b_c]}/,
995 '~[ \1 ]~'). # inline endnote with marker marked up
996 gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/,
997 '~{\1 \2 }~'). # inline endnote with marker marked up
998 gsub(/#{Mx[:en_b_o]}([*+]+)\s+(.+?)#{Mx[:en_b_c]}/,
999 '~[\1 \2 ]~'). # inline endnote with marker marked up
1000 gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<').
1001 gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>').
1002 gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&').
1003 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').
1004 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').
1005 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').
1006 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').
1007 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').
1008 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').
1009 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').
1010 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').
1011 gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~').
1012 gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©')
1013 end
1014 dob.obj=if dob.of==:block # watch
1015 dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/,"* ").
1016 gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n")
1017 else dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n\n")
1018 end
1019 if dob.is==:code
1020 dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _<
1021 gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_<
1022 end
1023 dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}/,''). # remove page breaks
1024 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
1025 gsub(/<a href=".+?">(.+?)<\/a>/m,'\1').
1026 gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links
1027 gsub(/&nbsp;|#{Mx[:nbsp]}/,' '). # decide on
1028 gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,
1029 ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
1030 gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,
1031 ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
1032 gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,
1033 '[image: "\1"]')
1034 [dob,notes]
1035 end
1036 def publish(fn,pot)
1037 content=[]
1038 content << pot[:open]
1039 content << pot[:head]
1040 content << pot[:metadata]
1041 content << pot[:body]
1042 content << @@endnotes[:end] if @@endnotes_
1043 Output.new(fn,content,@md,@process).po4a
1044 @@endnotes={ para: [], end: [] }
1045 end
1046 end
1047 class Output <Source
1048 include SiSU_Param
1049 include SiSU_Env
1050 def initialize(fn,content,md,process=:complete)
1051 @fn,@content,@md,@process=fn,content,md,process
1052 @file=SiSU_Env::FileOp.new(md,fn)
1053 end
1054 def po4a #%pot output
1055 file_pot=(@md.opt.f_pth[:lng] ==@md.opt.lng_base) \
1056 ? @file.write_file.pot
1057 : @file.write_file.po
1058 @sisu=[]
1059 emptyline=0
1060 @content.each do |para| # this is a hack
1061 if para.is_a?(Array) \
1062 and para.length > 0
1063 para.each do |line|
1064 if line
1065 line=line.gsub(/\s+$/m,'').
1066 gsub(/^\A[ ]*\Z/m,'')
1067 if line=~/^\A[ ]*\Z/m
1068 emptyline+=1
1069 else emptyline=0
1070 end
1071 file_pot.puts line if emptyline < 2 #remove extra line spaces (fix upstream)
1072 end
1073 end
1074 else file_pot.puts para #unix plaintext # /^([*=-]|\.){5}/
1075 end
1076 end
1077 file_pot.close
1078 SiSU_Po4aUtils::PotNumber.new.reset
1079 po4a_git
1080 end
1081 def po4a_git
1082 unless @md.opt.act[:maintenance][:set]==:on
1083 require_relative 'git' # git.rb
1084 git=SiSU_Git::Source.new(@md.opt,@process)
1085 unless FileTest.directory?(@file.output_path.pot_git.dir)
1086 git.create_file_structure_git
1087 end
1088 if @md.opt.f_pth[:lng] ==@md.opt.lng_base
1089 FileUtils::cp(
1090 @file.place_file.pot.dir,
1091 @file.output_path.pot_git.dir
1092 )
1093 else # naive, work on -->
1094 FileUtils::cp(
1095 @file.place_file.po.dir,
1096 @file.output_path.po_git.dir
1097 ) #unless FileTest.file?(@file.place_file.po_git.dir)
1098 end
1099 git.read
1100 end
1101 end
1102 end
1103 end
1104 end
1105 __END__
1106 &#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#
1107
1108 tables are problematic, difficult to reconstitute instruction, check
1109
1110 metadata, move to top? and work on
1111
1112 footnotes, different types, asterisk, also do you want to have separate
1113 paragraphs, or breaks within one block?
1114
1115 where no ocn appropriately use ~# or -# or indeed 1~name-
1116
1117 comments in document, what to do about them, not sure they are currently
1118 retained in dal, could be quite valuable to keep