61bed7bfd2151d4b07a05fd9aee039a296d5b935
[software/sisu] / lib / sisu / develop / html_segments.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html segment generation, processing
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/html_segments.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML_Seg
58 require_relative 'html_shared' # html_shared.rb
59 require_relative 'html' # html.rb
60 require_relative 'html_promo' # html_promo.rb
61 require_relative 'shared_metadata' # shared_metadata.rb
62 class Output
63 def initialize(md,outputfile,seg,minitoc,type='')
64 @md, @output_seg_file,@seg,@minitoc,@type=
65 md,outputfile, seg,minitoc, type
66 @title_banner_=SiSU_Env::CreateSite.new(@md.opt).html_seg_title_banner?
67 @file=SiSU_Env::FileOp.new(@md)
68 @make=SiSU_Env::ProcessingSettings.new(@md)
69 @cl=(@make.build.html_minitoc?) \
70 ? 'content'
71 : 'content0'
72 end
73 def output
74 if @seg[:title] =~/\S/
75 filename_seg=[]
76 if @make.build.html_top_band?
77 filename_seg \
78 << @seg[:title] \
79 << @seg[:tocband_banner]
80 else
81 filename_seg \
82 << @seg[:title]
83 end
84 if @type=='endnotes'
85 @seg[:headings]=[]
86 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
87 if @title_banner_
88 @seg[:headings] \
89 << format_head_seg.
90 title_banner(@md.title.main,@md.title.sub,@author)
91 end
92 txt_obj={ txt: 'Endnotes', ocn_display: '' }
93 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
94 @seg[:headings] \
95 << format_seg.title_heading1
96 filename_seg \
97 << @seg[:heading_endnotes] \
98 << @minitoc << @seg[:headings] \
99 << %{\n<div class="#{@cl}">\n} \
100 << @seg[:endnote_all] \
101 << '</div>' # << '</div>'
102 elsif @type=='idx'
103 @seg[:headings]=[]
104 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
105 if @title_banner_
106 @seg[:headings] \
107 << format_head_seg.
108 title_banner(@md.title.main,@md.title.sub,@author)
109 end
110 txt_obj={ txt: 'Index', ocn_display: '' }
111 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
112 @seg[:headings] << format_seg.title_heading1
113 filename_seg \
114 << @seg[:heading_idx] \
115 << @minitoc << @seg[:headings] \
116 << %{\n<div class="#{@cl}">\n} \
117 << @seg[:idx] \
118 << '</div>' # << '</div>'
119 elsif @type=='metadata'
120 metadata=SiSU_Metadata::Summary.new(@md).html_display.metadata
121 @seg[:headings]=[]
122 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
123 if @title_banner_
124 @seg[:headings] \
125 << format_head_seg.
126 title_banner(@md.title.main,@md.title.sub,@author)
127 end
128 txt_obj={ txt: 'Metadata', ocn_display: '' }
129 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
130 @seg[:headings] << format_seg.title_heading1
131 filename_seg \
132 << @seg[:heading_idx] \
133 << @minitoc \
134 << @seg[:headings] \
135 << %{\n<div class="#{@cl}">\n} \
136 << metadata \
137 << '</div>' # << '</div>'
138 else
139 if @make.build.html_top_band?
140 filename_seg \
141 << @minitoc \
142 << @seg[:headings] \
143 << @seg[:main] \
144 << "\n</div>\n"
145 else
146 filename_seg \
147 << @minitoc \
148 << @seg[:main] \
149 << "\n</div>\n"
150 end
151 end
152 filename_seg <<=if @make.build.html_top_band?
153 @seg[:tail] \
154 << @seg[:tocband_bannerless] \
155 << @seg[:credits]
156 else
157 @seg[:tail] \
158 << @seg[:credits]
159 end
160 filename_seg=filename_seg.flatten.compact #watch
161 filename_seg.each do |str|
162 unless str =~/\A\s*\Z/
163 str=str.strip.
164 gsub(Xx[:html_relative2],
165 @file.path_rel_links.html_seg_2).
166 gsub(Xx[:html_relative1],
167 @file.path_rel_links.html_seg_1)
168 @output_seg_file << str
169 end
170 end
171 @output_seg_file.close
172 end
173 end
174 end
175 class Seg
176 @@seg,@@seg_subtoc,@@seg_endnotes,@@seg_ad={},{},{},{}
177 @@seg_name,@@seg_name_html=[],[]
178 @@seg_url=@@fn=@@get_hash_to=@@get_hash_fn=''
179 @@loop_count=@@seg_total=@@tracker=0
180 @@is4=@@is3=@@is2=@@is1=@@is0=0
181 @@heading0=@@heading1=@@heading2=@@heading3=@@heading4=0
182 @@seg[:tocband_banner],
183 @@seg[:tocband_bannerless],
184 @@seg[:title],@@seg[:headings],
185 @@seg[:main],
186 @@seg[:idx],
187 @@seg[:tail],
188 @@seg[:credits],
189 @@seg_subtoc_array,
190 @@seg_endnotes_array,
191 @@seg[:endnote_all]=
192 Array.new(11){[]}
193 @@seg[:heading_endnotes]=''
194 @@tablehead,@@number_of_cols=0,0
195 @@dp,@@segtocband=nil,nil
196 @@fns_previous=''
197 attr_reader :seg_name_html,:seg_name_html_tracker
198 def initialize(md=nil,data='')
199 @md,@data=md,data
200 @seg_name_html=@@seg_name_html || nil
201 @seg_name_html_tracker=@@tracker || nil
202 @env=SiSU_Env::InfoEnv.new(@md.fns) if @md
203 if @md
204 @make=SiSU_Env::ProcessingSettings.new(@md)
205 @cl=(@make.build.html_minitoc?) \
206 ? 'content'
207 : 'content0'
208 else @cl='content'
209 end
210 if @md
211 @title_banner_=SiSU_Env::CreateSite.new(@md.opt).html_seg_title_banner?
212 end
213 end
214 def songsheet
215 begin
216 @minitoc=SiSU_HTML::Source::Toc.new(@md,@data).minitoc
217 data=get_subtoc_endnotes(@data)
218 data=articles(data)
219 SiSU_HTML_Seg::Seg.new.cleanup # (((( added ))))
220 #### (((( END )))) ####
221 rescue
222 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
223 __LINE__.to_s + ':' + __FILE__
224 end
225 ensure
226 @@seg_name=[]
227 end
228 end
229 protected
230 def articles(data)
231 tracking,newfile=0,0
232 @@is4=@@is3=@@is2=@@is1=@@is0=0
233 printed_endnote_seg='n'
234 idx_html=nil
235 if @md.book_idx
236 #my_make_source_file=SiSU_Env::CreateFile.new(@md.fns)
237 idx_html=SiSU_Particulars::CombinedSingleton.
238 instance.get_idx_html(@md.opt).html_idx
239 idx_html.each do |x|
240 @@seg[:idx] << x
241 end
242 @@seg[:heading_idx]=''
243 end
244 data.each do |dob|
245 if (dob.is == :heading \
246 || dob.is == :heading_insert) \
247 && dob.ln == 4
248 @@seg_name << dob.name
249 dob.name
250 end
251 end
252 @@seg_name_html=@@seg_name
253 @@seg_total=@@seg_name.length
254 testforartnum=@@seg_name_html
255 if (@md.opt.act[:verbose][:set]==:on \
256 || @md.opt.act[:verbose_plus][:set]==:on \
257 || @md.opt.act[:maintenance][:set]==:on)
258 SiSU_Screen::Ansi.new(
259 @md.opt.act[:color_state][:set],
260 @@seg_name.length
261 ).segmented
262 end
263 map_nametags=SiSU_Particulars::CombinedSingleton.
264 instance.get_map_nametags(@md).nametags_map #p map_nametags
265 data.each do |dob|
266 if defined? dob.obj \
267 and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/
268 while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/
269 m=$1
270 if map_nametags[m] \
271 and map_nametags[m][:segname]
272 inf=SiSU_Env::FileOp.new(@md) if @md
273 lng=(inf.output_dir_structure.by_language_code?) \
274 ? ''
275 : '.' + @md.opt.lng
276 dob.obj.sub!(/href="#{Xx[:segment]}#+(\S+?)"/,
277 %{href="#{map_nametags[m][:segname]}#{lng}#{Sfx[:html]}#\\1"})
278 else
279 p "NOT FOUND name_tags: #{m}"
280 dob.obj.sub!(/href="#{Xx[:segment]}#+(\S+?)"/,
281 %{href="#\\1"}) # not satisfactory
282 end
283 end
284 end
285 if (dob.is==:heading \
286 || dob.is==:heading_insert) \
287 && dob.ln==4
288 @@heading4=dob.obj
289 @@is4=newfile=1
290 end
291 if (dob.is==:heading \
292 || dob.is==:heading_insert) \
293 && dob.ln==3
294 @@heading3=dob.obj
295 @@is4,@@is3=0,1
296 end
297 if (dob.is==:heading \
298 || dob.is==:heading_insert) \
299 && dob.ln==2
300 @@heading2=dob.obj
301 @@is4,@@is3,@@is2=0,0,1
302 end
303 if (dob.is==:heading \
304 || dob.is==:heading_insert) \
305 && dob.ln==1
306 @@heading1=dob.obj
307 @@is4,@@is3,@@is2,@@is1=0,0,0,1
308 end
309 if (dob.is==:heading \
310 || dob.is==:heading_insert) \
311 && dob.ln==0
312 @@heading0=dob.obj
313 @@is4,@@is3,@@is2,@@is1,@@is0=0,0,0,0,1
314 end
315 if (@@is1 && !@@is2 && !@@is3 && !@@is4)
316 if not (dob.is==:heading \
317 || dob.is==:heading_insert) \
318 && dob.ln==0
319 $_ #; check
320 end
321 end
322 if @@is4==1
323 if newfile==1 \
324 or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/
325 newfile=0
326 if (dob.is==:heading \
327 || dob.is==:heading_insert) \
328 && dob.ln==4
329 if tracking != 0
330 @file=SiSU_Env::FileOp.new(@md)
331 unless FileTest.directory?(@file.output_path.html_seg.dir)
332 FileUtils::mkdir_p(@file.output_path.html_seg.dir) \
333 if File.writable?("#{@file.output_path.base.dir}/.")
334 end
335 SiSU_HTML_Seg::Seg.new(@md).tail
336 fnh={
337 fn: @@seg_name_html[tracking-1],
338 }
339 fn=@md.file.base_filename.html_seg(fnh)
340 segfilename="#{@file.output_path.html_seg.dir}/#{fn}"
341 output_seg_file=File.new(segfilename,'w') if @@seg_name_html[tracking-1]
342 minitoc=(@make.build.html_minitoc?) ? @minitoc : ''
343 if dob.is==:heading \
344 || (@@seg_name_html[tracking-1] !~/endnotes|book_index|metadata/)
345 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@@seg,minitoc).output
346 elsif dob.is==:heading_insert
347 if @@seg_name_html[tracking-1]=='endnotes'
348 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@@seg,minitoc,'endnotes').output
349 elsif @@seg_name_html[tracking-1]=='book_index'
350 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@@seg,minitoc,'idx').output
351 @@seg[:idx]=[]
352 elsif @@seg_name_html[tracking-1]=='metadata'
353 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@@seg,minitoc,'metadata').output
354 else puts "#{__FILE__}::#{__LINE__}"
355 end
356 else puts "#{__FILE__}::#{__LINE__}"
357 end
358 SiSU_HTML_Seg::Seg.new.reinitialise
359 heading_art(dob)
360 head(dob)
361 #keep use for last segment, eg if metadata is last segment
362 if @@seg_name_html[tracking] =='metadata' # this is for metadata
363 fnh={
364 fn: @@seg_name_html[tracking],
365 }
366 fn=@md.file.base_filename.html_seg(fnh)
367 segfilename="#{@file.output_path.html_seg.dir}/#{fn}"
368 output_seg_file=File.new(segfilename,'w')
369 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@@seg,minitoc,'metadata').output
370 Seg.new.reinitialise
371 end
372 end
373 if tracking==0
374 heading_art(dob)
375 head(dob)
376 end
377 end
378 tracking=tracking+1
379 end
380 if (dob.is==:heading \
381 || dob.is==:heading_insert) \
382 && dob.ln==4 \
383 && dob.name
384 @@get_hash_to=dob.name
385 @@get_hash_fn=dob.name
386 end
387 if dob.obj.is_a?(String)
388 markup(dob)
389 elsif dob.obj.is_a?(Array)
390 dob.obj.each do |pg|
391 markup(pg)
392 end
393 end
394 if testforartnum[tracking-1] =~/endnote/
395 if printed_endnote_seg=='n'
396 printed_endnote_seg='y'
397 end
398 end
399 end
400 end
401 data
402 end
403 def heading_art(dob)
404 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
405 @@seg[:dot_nav]=if (@make.build.html_navigation?) \
406 && (@make.build.html_navigation_bar?)
407 x=if (dob.is==:heading \
408 || dob.is==:heading_insert) \
409 && (dob.ln.to_s =~/^[0-7]/)
410 x=if @@tracker < @@seg_total-1
411 format_head_seg.dot_control_pre_next
412 else
413 format_head_seg.dot_control_pre
414 end
415 else @@seg[:dot_nav]
416 end
417 else @@seg[:dot_nav]=''
418 end
419 ads=SiSU_HTML_Promo::Ad.new(@md)
420 @@seg[:title]=format_head_seg.head_seg << ads.div.major
421 end
422 def head(dob)
423 clean=/<!.*?!>|<:.*?>/
424 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
425 if @make.build.html_navigation?
426 if @@tracker < @@seg_total-1
427 @@segtocband=if @@tracker==0
428 format_head_seg.toc_next2
429 else
430 format_head_seg.toc_pre_next2
431 end
432 else @@segtocband=format_head_seg.toc_pre2
433 end
434 else @@segtocband=''
435 end
436 @p_num ||= ''
437 if @@is0==1
438 @author=%{<b>#{@md.author}</b>\n} if @md.author.to_s =~/\S/
439 @@seg[:tocband_banner] \
440 << format_head_seg.navigation_band(@@segtocband,@@seg[:dot_nav])
441 @@seg[:tocband_bannerless] \
442 << '<br>' \
443 << format_head_seg.navigation_band_bottom(@@segtocband,@@seg[:dot_nav])
444 if @title_banner_
445 @@seg[:headings] \
446 << format_head_seg.title_banner(@md.title.main,@md.title.sub,@author).gsub(clean,'')
447 end
448 ocn=(@@heading0[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
449 ? $1
450 : ''
451 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
452 txt_obj={ txt: @@heading0, ocn_display: @p_num.ocn_display }
453 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
454 @@seg[:headings] \
455 << format_seg.title_heading0.gsub(clean,'')
456 @@heading0=@@heading0.
457 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
458 end
459 if @@is1==1
460 heading1=@@heading1
461 ocn=(heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
462 ? $1
463 : ''
464 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
465 txt_obj={ txt: heading1, ocn_display: @p_num.ocn_display }
466 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
467 @@seg[:headings] \
468 << format_seg.title_heading1.gsub(clean,'')
469 @@heading1=@@heading1.
470 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
471 end
472 if @@is2==1
473 heading2=@@heading2
474 ocn=(heading2[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
475 ? $1
476 : ''
477 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
478 txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display }
479 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
480 @@seg[:headings] \
481 << format_seg.title_heading2.gsub(clean,'')
482 @@heading2=@@heading2.
483 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
484 end
485 if @@is3==1
486 heading3=@@heading3
487 ocn=(heading3[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
488 ? $1
489 : ''
490 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
491 txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display }
492 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
493 @@seg[:headings] \
494 << format_seg.title_heading3.gsub(clean,'')
495 @@heading3=@@heading3.
496 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
497 end
498 if @@is4==1
499 heading4=@@heading4
500 ocn=(heading4[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
501 ? $1
502 : ''
503 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
504 txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display }
505 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
506 @@seg[:headings] \
507 << format_seg.title_heading4.gsub(clean,'')
508 end
509 @@tracker=@@tracker+1
510 end
511 def markup(dob)
512 @debug=[]
513 SiSU_HTML_Format::HeadSeg.new(@md)
514 if dob.is !=:meta
515 if dob.is==:heading \
516 || dob.is==:heading_insert \
517 || dob.is == :para
518 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,dob.ocn)
519 end
520 sto=SiSU_HTML_Format::FormatTextObject.new(@md,dob)
521 dob_html=if dob.is == :heading \
522 || dob.is==:heading_insert \
523 || dob.is==:para
524 dob_html=if dob.is==:heading \
525 || dob.is==:heading_insert
526 if dob.ln==4
527 sto.seg_heading4
528 elsif dob.ln==5
529 sto.seg_heading5
530 elsif dob.ln==6
531 sto.seg_heading6
532 elsif dob.ln==7
533 sto.seg_heading6
534 end
535 elsif dob.is==:para
536 if dob.indent \
537 and dob.hang \
538 and dob.indent =~/[0-9]/ \
539 and dob.hang =~/[0-9]/
540 if dob.bullet_
541 if dob.indent =~/[1-9]/
542 sto.format('li',"i#{dob.indent}")
543 else
544 sto.format('li','bullet')
545 end
546 elsif dob.indent == dob.hang
547 sto.format('p',"i#{dob.indent}")
548 elsif dob.indent != dob.hang
549 sto.format('p',"h#{dob.hang}i#{dob.indent}")
550 else sto.para
551 end
552 else sto.para
553 end
554 end
555 elsif dob.is==:block
556 sto.block
557 elsif dob.is==:group
558 sto.group
559 elsif dob.is==:alt
560 sto.alt
561 elsif dob.is==:verse
562 sto.verse
563 elsif dob.is==:code
564 sto.code
565 elsif dob.is==:table
566 sto.table
567 elsif dob.is==:break \
568 and dob.from==:markup
569 '<br><hr width=90% /><br>'
570 end
571 if @md.flag_separate_endnotes
572 dob.obj=dob.obj.gsub(/"\s+href="#(#{Mx[:note]}\d+)">/,%{" href=\"endnotes#{Sfx[:html]}#\\1">}) #endnote- twice #removed file type
573 end
574 if (dob.is==:heading \
575 || dob.is==:heading_insert \
576 || dob.is==:para) \
577 && (not dob.ocn \
578 || (dob.ocn.to_s.empty?))
579 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,dob)
580 end
581 dob.obj=dob.obj.gsub(/\s*(-\{{2}~\d+|<:e[:_]\d+>).*/,'') #potentially dagerous - removes all paragraphs with <!e_!> #?? workpoint
582 if dob.obj =~/<a name="_\d+" href="#-\d+">&nbsp;<sup>/ #endnote- note-
583 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,dob)
584 dob=format_seg.no_paranum
585 end
586 if (dob.is==:heading \
587 || dob.is==:heading_insert) \
588 && dob.ln==4
589 @@seg[:main] << %{\n<div class="#{@cl}">\n}
590 @@seg[:main] << dob_html
591 if @make.build.segsubtoc?
592 @@seg[:main] << @@seg_subtoc[@@get_hash_fn] #% insertion of sub-toc
593 end
594 else
595 @@seg[:main] << dob_html #unless @@flag_alt==true
596 end
597 end
598 end
599 def tail
600 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
601 if @md.flag_auto_endnotes and @@seg_endnotes[@@get_hash_fn]
602 @@seg[:tail] << %{\n<div class="#{@cl}">\n<div class="endnote">\n}
603 if @@seg_endnotes[@@get_hash_fn].flatten.length > 0
604 @@seg[:tail] << format_head_seg.endnote_mark
605 @@seg[:tail] << @@seg_endnotes[@@get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES|
606 end
607 @@seg[:tail] << '</div>'
608 @@seg[:tail] << '</div>' #this div closes div class content
609 end
610 ads=SiSU_HTML_Promo::Ad.new(@md)
611 @@seg[:credits] << format_head_seg.credit << ads.div.close << ads.display << format_head_seg.html_close
612 end
613 def reinitialise
614 @@seg[:title],@@seg[:dot_nav],@@seg[:tocband_banner],@@seg[:tocband_bannerless],@@seg[:headings],@@seg[:main],@@seg[:tail],@@seg[:credits]=Array.new(8){[]}
615 @@segtocband=nil
616 end
617 def cleanup
618 reinitialise
619 @@seg_total,@@tracker=0,0
620 @@seg_endnotes,@@seg_subtoc={},{}
621 @@seg_endnotes_array,@@seg_subtoc_array=[],[]
622 @@seg[:endnote_all]=[]
623 end
624 def get_subtoc_endnotes(data) #get endnotes & sub-table of contents subtoc
625 data.each do |dob|
626 dob.obj=dob.obj.gsub(/<a name=\"h\d.*?\">(.+?)<\/a>/mi,'\1')
627 if @md.flag_auto_endnotes
628 if (dob.is==:heading \
629 || dob.is==:heading_insert) \
630 && (dob.ln.to_s =~/^[0-4]/) \
631 and not @@fn.to_s.empty?
632 @@seg_endnotes[@@fn]=[]
633 @@seg_endnotes[@@fn] << @@seg_endnotes_array
634 @@seg_endnotes_array=[] if dob.ln==4
635 @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/
636 end
637 if (dob.is==:heading \
638 || dob.is==:heading_insert) \
639 && dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs
640 @@seg_subtoc[@@fn]=@@seg_subtoc_array
641 @@seg_subtoc_array=[]
642 if dob.name \
643 and dob.obj
644 @@fn=dob.name
645 else
646 if dob.name =~/\S+/
647 @@fn=dob.name
648 else @@fn=''
649 end
650 end
651 end
652 end
653 if dob.is==:heading \
654 && (dob.ln.to_s =~/^[5-7]/)
655 case dob.ln
656 when 5
657 txt_obj={ txt: dob.obj.strip, ocn: dob.ocn }
658 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
659 subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc
660 when 6
661 txt_obj={ txt: dob.obj.strip, ocn: dob.ocn }
662 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
663 subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc
664 when 7
665 txt_obj={ txt: dob.obj.strip, ocn: dob.ocn }
666 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
667 subtoc=format_seg.subtoc_lev7 #keep and make available, this is the subtoc
668 end
669 @@seg_subtoc_array << subtoc
670 end
671 if @md.flag_auto_endnotes
672 if (dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+\s*<a href="##{Mx[:note_ref]}[\d*+]+"/) \
673 && dob.is !=:code # endnote-
674 endnote_array=[]
675 if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m
676 endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m)
677 end
678 if dob.obj=~/#{Mx[:en_b_o]}[*]\d+\s.+?#{Mx[:en_b_c]}/m
679 endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}[*]\d+\s.+?#{Mx[:en_b_c]}/m)
680 end
681 if dob.obj=~/#{Mx[:en_b_o]}[+]\d+\s.+?#{Mx[:en_b_c]}/m
682 endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}[+]\d+\s.+?#{Mx[:en_b_c]}/m)
683 end
684 endnote_array=endnote_array.flatten.compact #watch, check compacting
685 endnote_array.each do |note|
686 note_match=note.dup
687 note_match_seg=note.dup
688 e_n=note_match_seg[/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1]
689 try=e_n.split(/<br(?: \/)?>/)
690 try.each do |e|
691 txt_obj={ txt: e }
692 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
693 note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/
694 format_seg.endnote_body_indent
695 else format_seg.endnote_body
696 end
697 @@seg_endnotes_array << note_match
698 end
699 try.join('<br>')
700 #% creation of separate end segment/page of all endnotes referenced back to reference segment
701 m=/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?href=")(##{Mx[:note_ref]}[\d*+]+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi
702 endnote_part_a=note_match_seg[m,1]
703 endnote_part_b=note_match_seg[m,2]
704 txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b }
705 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
706 note_match_all_seg=format_seg.endnote_seg_body(@@fn) #BUG WATCH 200408
707 @@seg[:endnote_all] << note_match_all_seg
708 end
709 dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
710 end
711 end
712 end
713 end
714 end
715 end
716 __END__