c&d: html, ocn link back to self reinstated
[software/sisu] / lib / sisu / develop / html_format.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html formating, css template
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_format.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML_Format
58 require_relative 'html_parts' # html_parts.rb
59 class ParagraphNumber
60 def initialize(md,ocn)
61 @md,@ocn=md,ocn.to_s
62 @ocn ||=''
63 @make=SiSU_Env::ProcessingSettings.new(@md)
64 end
65 def ocn_display
66 if @make.build.ocn?
67 if @ocn.to_i==0 \
68 or @ocn.empty?
69 ''
70 else
71 %{<label class="ocn"><a href="##{@ocn}" class="lnkocn">#{@ocn}</a></label>}
72 end
73 else
74 ''
75 end
76 end
77 def name
78 if @make.build.html_strict? \
79 or @ocn==(nil || @ocn.empty?)
80 ''
81 else
82 %{<a name="#{@ocn}"></a>}
83 end
84 end
85 def id #w3c? "tidy" complains about numbers as identifiers ! annoying
86 (@ocn==nil || @ocn.empty?) \
87 ? '' : %{id="#{Mx[:ocn_id_char]}#{@ocn}"}
88 end
89 def goto
90 (@ocn==nil || @ocn.empty?) \
91 ? '' : %{<a href="##{@ocn}">}
92 end
93 end
94 class HeadInformation
95 require_relative 'css' # css.rb
96 include SiSU_Parts_HTML
97 require_relative 'xml_shared' # xml_shared.rb
98 attr_reader :md,:rdf
99 def initialize(md)
100 @md=md
101 # DublinCore 1 - title
102 @bits=SiSU_Proj_HTML::Bits.new
103 @per=SiSU_HTML_Persist::Persist.new
104 @per.seg_name_x=SiSU_HTML::Seg.new.seg_name_x
105 @per.seg_name_x_tracker=SiSU_HTML::Seg.new.seg_name_x_tracker
106 @tocband_scroll,@tocband_segtoc=nil,nil
107 @stylesheet=SiSU_Style::CSS_HeadInfo.new(md).stylesheet
108 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
109 @index,@metalink='index','#metadata'
110 @toc=@md.file.base_filename.html_segtoc
111 end
112 def url_path_image_sys
113 (@o_str.dump_or_redirect?) \
114 ? './image'
115 : "#{Xx[:html_relative2]}_sisu/image_sys"
116 end
117 def icon
118 def up
119 'arrow_up_red.png'
120 end
121 def next
122 'arrow_next_red.png'
123 end
124 def previous
125 'arrow_prev_red.png'
126 end
127 def dot_clear
128 'dot_clear.png'
129 end
130 def dot_white
131 'dot_white.png'
132 end
133 def dot
134 dot_white
135 end
136 self
137 end
138 def png_nav
139 def toc
140 %{<img border="0" width="22" height="22" src="#{url_path_image_sys}/#{icon.up}" alt="toc" />}
141 end
142 def pre
143 %{<img border="0" width="22" height="22" src="#{url_path_image_sys}/#{icon.previous}" alt="&lt;&lt;&nbsp;previous" />}
144 end
145 def nxt
146 %{<img border="0" width="22" height="22" src="#{url_path_image_sys}/#{icon.next}" alt="next&nbsp;&gt;&gt;" />}
147 end
148 def dot_toc
149 %{<img border="0" width="100%" height="20" src="#{url_path_image_sys}/#{icon.dot}" alt="&#094;" />}
150 end
151 def dot_pre
152 %{<img border="0" width="100%" height="20" src="#{url_path_image_sys}/#{icon.dot}" alt="&lt;" />}
153 end
154 def dot_nxt
155 %{<img border="0" width="100%" height="20" src="#{url_path_image_sys}/#{icon.dot}" alt="&gt;" />}
156 end
157 self
158 end
159 def doc_types(page=:seg) #used in toc & seg_nav_band
160 wgt=SiSU_HTML_Format::Widget.new(@md)
161 %{
162 <table summary="segment navigation available documents types: toc,doc,pdf,concordance" border="0" cellpadding="3" cellspacing="0">
163 <tr>
164 <td align="center" bgcolor=#{the_color.band2}>
165 #{wgt.manifest(page)}
166 #{wgt.search}
167 </tr></table>}
168 end
169 def rdf
170 SiSU_XML_Tags::RDF.new(md)
171 end
172 def button_home(page=:seg)
173 button=%{ <table summary="home button / home information" border="0" cellpadding="3" cellspacing="0">\n <tr><td align="left" bgcolor="#ffffff">\n}
174 if @md.make.home_button_image.is_a?(Hash)
175 image_path=if page==:manifest
176 @md.file.output_path.manifest.rel_image
177 elsif page==:scroll
178 @md.file.output_path.html_scroll.rel_image
179 else
180 @md.file.output_path.html_seg.rel_image
181 end
182 SiSU_Env::FileOp.new(@md)
183 button +=%{ <p class="tiny_left"><a href="#{@md.make.home_button_image[:link]}" target="_top"><img border="0" src="#{image_path}/#{@md.make.home_button_image[:home_button]}" width="#{@md.make.home_button_image[:w]}" height="#{@md.make.home_button_image[:h]}" alt="home icon --&gt;" /></a></p>\n}
184 elsif @md.home_button_links.is_a?(Array)
185 @md.home_button_links.each do |links|
186 button +=%{ <p class="tiny_left"><a href="#{links[:url]}" target="_top">\n #{links[:say]}\n </a></p>\n}
187 end
188 end
189 button +=%{ </td></tr>\n </table>}
190 button
191 end
192 def html_close #moved
193 %{</body>
194 </html>}
195 end
196 end
197 class Widget < HeadInformation
198 include SiSU_Parts_HTML
199 def initialize(md)
200 super(md)
201 @md=md
202 @cf_defaults=SiSU_Env::InfoProcessingFlag.new
203 @env=SiSU_Env::InfoEnv.new(md.fns)
204 @file=SiSU_Env::FileOp.new(md)
205 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
206 @make=SiSU_Env::ProcessingSettings.new(md)
207 end
208 def home
209 %{<td align="center" bgcolor=#{the_color.band2}>
210 <a href="../index.html" target="_top">
211 #{the_nav.txt_homepage}</a>
212 </td>
213 }
214 end
215 def scroll(text)
216 if @md.fns =~ /\.(?:-|ssm\.)?sst$/
217 %{<td align="center" bgcolor=#{the_color.band2}>
218 <a href="#{Xx[:html_relative1]}html/#{@file.base_filename.html_scroll}" target="_top">
219 #{text}
220 </a>
221 </td>
222 }
223 end
224 end
225 def seg(text)
226 %{<td align="center" bgcolor="#99CC66">
227 <a href="#{@md.file.base_filename.html_segtoc}" target="_top">
228 #{text}
229 </a>
230 </td>
231 }
232 end
233 def search
234 if @make.build.html_search_form?
235 env=SiSU_Env::InfoEnv.new(@md.fns,@md)
236 env.widget.search_form('sisusearch',nil,nil,true)
237 else ''
238 end
239 end
240 def manifest(page=:seg)
241 if @make.build.links_to_manifest? \
242 and not @o_str.dump_or_redirect?
243 manifest_lnk=if @file.output_dir_structure.by_language_code? \
244 or @file.output_dir_structure.by_filetype?
245 "#{Xx[:html_relative1]}manifest/#{@file.base_filename.manifest}"
246 else @file.base_filename.manifest
247 end
248 if page==:manifest
249 manifest_lnk="#{@md.file.output_path.manifest.url}/#{@file.base_filename.manifest}"
250 %{<td align="center" bgcolor=#{the_color.band2}>
251 <font face="#{the_font.set_fonts}" size="2">
252 #{the_url_decoration.xml_open}<a href="#{manifest_lnk}" target="_top">#{@md.file.output_path.manifest.url}/#{@file.base_filename.manifest}</a>#{the_url_decoration.xml_close}
253 </font>
254 </td>}
255 else
256 %{<td align="center" bgcolor=#{the_color.band2}>
257 <a href="#{manifest_lnk}" target="_top">
258 #{the_nav.txt_manifest}
259 </a>
260 </td>}
261 end
262 else ''
263 end
264 end
265 end
266 class XML
267 end
268 class HeadToc < HeadInformation
269 def initialize(md)
270 super(md)
271 @md=md
272 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
273 @make=SiSU_Env::ProcessingSettings.new(@md)
274 @file=SiSU_Env::FileOp.new(@md)
275 end
276 def scroll_head_navigation_band
277 if @make.build.html_top_band?
278 <<WOK
279 <td align="center" width="60%">
280 #{make_scroll_search_form_and_manifest_link}
281 </td>
282 WOK
283 %{<table summary="table of contents scroll navigation band" id="toc" width="100%" bgcolor=#{the_color.band1}>
284 <tr><td width="20%">
285 #{button_home(:scroll)}
286 </td>
287 <td width="75%" align="center">
288 #{doc_types}
289 </td>
290 <td width="20%">
291 &nbsp;
292 #{the_table_close}
293 <p>}
294 else ''
295 end
296 end
297 def concordance_navigation_band
298 up_button=if @make.build.html_navigation?
299 %{</td>
300 <td width="5%" align="right">
301 &nbsp;<a href="toc.html" target="_top" alt="-&gt;">
302 #{png_nav.toc}
303 </a>&nbsp;
304 }
305 else ''
306 end
307 if @make.build.html_top_band?
308 %{<table summary="concordance navigation band" id="toc" width="100%" bgcolor=#{the_color.band1}>
309 <tr><td width="20%">
310 #{button_home}
311 </td>
312 <td width="75%" align="center">
313 #{doc_types}
314 #{up_button}
315 #{the_table_close}
316 <p>}
317 else ''
318 end
319 end
320 def seg_head_navigation_band(page=:seg)
321 if @make.build.html_navigation?
322 if page==:manifest
323 nxt=(@file.output_dir_structure.by_language_code? \
324 || @file.output_dir_structure.by_filetype?) \
325 ? "../html/#{@md.fnb}/toc#{@md.lang_code_insert}#{Sfx[:html]}"
326 : "toc#{@md.lang_code_insert}#{Sfx[:html]}"
327 firstseg=%{<a href="#{nxt}" target="_top" alt="-&gt;">
328 #{png_nav.nxt}</a>}
329 elsif @md.firstseg =~/\S+/
330 firstseg=%{<a href="#{@md.firstseg}#{@md.lang_code_insert}#{Sfx[:html]}" target="_top" alt="-&gt;">
331 #{png_nav.nxt}</a>}
332 end
333 else ''
334 end
335 if @make.build.html_top_band?
336 %{<table summary="table of contents segment navigation band" id="toc" width="100%" bgcolor=#{the_color.band1}>
337 <tr><td width="20%">
338 #{button_home(page)}
339 </td>
340 <td width="75%" align="center">
341 #{doc_types(page)}
342 </td>
343 <td width="5%" align="right">
344 &nbsp;#{firstseg}&nbsp;
345 #{the_table_close}
346 <p>}
347 else ''
348 end
349 end
350 def manifest_link(text)
351 # @file=SiSU_Env::FileOp.new(@md) if @md
352 %{<font size=2>
353 <a href="#{@md.file.base_filename.manifest}" target="_top">#{text}</a>
354 </font>}
355 end
356 def concordance_link(text)
357 if @md.concord_make
358 %{<font size=2>
359 <a href="#{@md.file.base_filename.html_concordance}" target="_top">
360 #{text}
361 </a>
362 </font>}
363 else ''
364 end
365 end
366 def make_scroll_search_form_and_manifest_link
367 wgt=SiSU_HTML_Format::Widget.new(@md)
368 %{<td align="center" bgcolor=#{the_color.band2}>
369 #{the_nav.txt_doc_link}
370 </td>
371 }
372 %{<table summary="toc segment and scroll with pdf" border="0" cellpadding="3" cellspacing="0">
373 <tr>
374 #{wgt.manifest}
375 #{wgt.search}
376 </tr></table>}
377 end
378 def make_scroll_seg_pdf
379 seg=''
380 wgt=SiSU_HTML_Format::Widget.new(@md)
381 seg=%{<td align="center" bgcolor=#{the_color.band2}>
382 #{the_nav.txt_toc_link}
383 </td>
384 }
385 %{<table summary="toc scroll and segment with pdf" border="0" cellpadding="3" cellspacing="0">
386 <tr>
387 <td align="center" bgcolor=#{the_color.band2}>
388 #{wgt.manifest}
389 #{wgt.search}
390 </tr></table>}
391 end
392 def make_concordance
393 wgt=SiSU_HTML_Format::Widget.new(@md)
394 %{<table summary="toc scroll and segment with pdf" border="0" cellpadding="3" cellspacing="0">
395 <tr>
396 <td align="center" bgcolor=#{the_color.band2}>
397 #{wgt.manifest}
398 #{wgt.search}
399 </tr></table>}
400 end
401 def head
402 rdf=SiSU_XML_Tags::RDF.new(@md)
403 %{<!DOCTYPE html>
404 <html>
405 <head>
406 <meta charset="utf-8">
407 <title>
408 #{@md.title.full}
409 </title>
410 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
411 #{rdf.metatag_html}
412 #{@stylesheet.css_head}
413 </head>
414 <body lang="#{@md.opt.lng}">
415 <a name="top" id="top"></a>}
416 end
417 def concordance
418 if @md.concord_make
419 %{#{the_margin.css}
420 <h4 class="toc">
421 <a href="./#{@md.file.base_filename.html_concordance}">
422 <i>Concordance</i>
423 </a>
424 </h4>
425 #{table_close}}
426 else
427 %{#{the_margin.css}
428 #{table_close}}
429 end
430 end
431 def links_guide_vertical_open
432 # @file=SiSU_Env::FileOp.new(@md) if @md
433 %{
434 <div id="vertical_links">
435 <ul id="vertical">
436 <li class="refbold">
437 <a href="#{the_url.home}">
438 #{the_text.txt_hp}
439 </a>
440 </li>
441 <li class="ref">
442 Quick Ref.:
443 </li>
444 <li class="ref">
445 <a href="#{@md.file.base_filename.manifest}" alt="Document Manifest" target="_top">
446 Manifest
447 </a>
448 </li>
449 <!- quick ref -!>}
450 end
451 def links_guide_horizontal_open
452 # @file=SiSU_Env::FileOp.new(@md) if @md
453 %{
454 <div id="horizontal_links">
455 <ul id="horizontal">
456 <li class="refbold">
457 <a href="#{the_url.home}">
458 #{the_text.txt_hp}
459 </a>
460 </li>
461 <li class="ref">
462 Quick Ref.:
463 </li>
464 <li class="ref">
465 <a href="#{@md.file.base_filename.manifest}" alt="Document Manifest" target="_top">
466 Manifest
467 </a>
468 </li>
469 <!- quick ref -!>}
470 end
471 def links_guide_open(type='horizontal')
472 (type=='vertical') \
473 ? links_guide_vertical_open
474 : links_guide_horizontal_open
475 end
476 def links_guide_close
477 insert=''
478 insert=if @md.sfx_src =~/s?/
479 link='http://sisudoc.org' #get from defaults
480 url='sisudoc.org'
481 name='SiSU electronic documents' #get from defaults
482 insert= %{
483 <li class="ref">
484 <a href="#{link}" alt="#{name}" target="_top">
485 #{url}
486 </a>
487 </li>
488 </ul>
489 </div>
490 }
491 end
492 %{ #{insert}
493 <!- quick ref -!>}
494 end
495 def prefix_a
496 end
497 def rights
498 def all
499 rights=SiSU_HTML_Tune::CleanHTML.new(@md.rights.all).clean_for_html
500 rights=rights.gsub(/^\s*Copyright\s+\(C\)/,'Copyright <sup>&copy;</sup>&nbsp;')
501 %{<p class="small_left">Rights: #{rights}</p>
502 <p>}
503 end
504 self
505 end
506 def prefix_b
507 %{<p class="small_left">Prefix: #{@md.prefix_b}<p />}
508 end
509 def scroll_head_title_banner_open
510 icon=@md.icon ? %{<center>\n#{@md.icon}\n</center>} : ''
511 %{#{icon}
512 #{the_banner.instrument_cover_band_scr}}
513 end
514 def seg_head_title_banner_open
515 icon=@md.icon ? %{<center>\n#{@md.icon}\n</center>} : ''
516 %{#{icon}
517 #{the_banner.instrument_cover_band_seg}}
518 end
519 def make_scroll
520 concord=concordance_link(the_nav.txt_concordance)
521 %{<table summary="toc scroll" border="0" cellpadding="3" cellspacing="0">
522 <tr><td align="center" bgcolor="white" border="0">
523 #{the_nav.txt_doc_link}
524 </td>
525 <td align="center" bgcolor="white">
526 #{concord}
527 #{the_table_close}}
528 end
529 def make_seg
530 concord=concordance_link(the_nav.txt_concordance)
531 %{<table summary="toc segment" border="0" cellpadding="3" cellspacing="0">
532 <tr><td align="center" bgcolor="white">
533 #{the_nav.txt_toc_link}
534 </td>
535 <td align="center" bgcolor="white">
536 <font size=2>
537 #{concord}
538 #{the_table_close}}
539 end
540 def manifest #check structure
541 if not @o_str.dump_or_redirect?
542 manifest=manifest_link(the_nav.txt_manifest)
543 %{#{the_margin.txt_3}
544 #{the_font.paragraph_font_small}
545 #{manifest}
546 </font>
547 #{the_table_close}}
548 else ''
549 end
550 end
551 def concordance #check structure
552 concord=concordance_link(the_nav.txt_concordance)
553 %{#{the_margin.txt_3}
554 #{the_font.paragraph_font_small}
555 #{concord}
556 </font>
557 #{the_table_close}}
558 end
559 def metadata
560 %{#{the_margin.css}
561 <h4 class="toc">
562 <a href="#{@metalink}">
563 <i>MetaData</i>
564 </a>
565 </h4>
566 #{the_table_close}}
567 end
568 def seg_tail
569 %{
570 <div class="main_column">
571 <p>&nbsp;<p>
572 <table summary="toc segment tail" bgcolor=#{the_color.band1}>
573 <tr><td width="20%">
574 #{the_banner.banner_band}
575 </td>
576 <td width="60%">
577 <center>
578 #{@tocband_segtoc}
579 </center>
580 </td></tr>
581 </table>
582 <p>&nbsp;</p>
583 #{@bits.credits_sisu}
584 <a name="bottom" id="bottom"></a>
585 <a name="end" id="end"></a>
586 </div>
587 </div>
588 </div>
589 }
590 end
591 def scroll_tail #debug
592 nav=scroll_head_navigation_band
593 %{
594 <div class="main_column">
595 #{nav}
596 #{@bits.credits_sisu}
597 <a name="bottom" id="bottom"></a>
598 <a name="end" id="end"></a>
599 </div>
600 }
601 end
602 def seg_navigation_tail #this is a bug area, look up and "tidy"
603 %{
604 <div class="main_column">
605 <p>&nbsp;</p>
606 #{@bits.credits_sisu}
607 <a name="bottom" id="bottom"></a>
608 <a name="end" id="end"></a>
609 </div>
610 </div>
611 </div>
612 }
613 end
614 end
615 class HeadSeg < HeadInformation
616 def initialize(md)
617 super(md)
618 end
619 def dot_control_pre_next
620 pre="#{@per.seg_name_x[@per.seg_name_x_tracker-1]}#{@md.lang_code_insert}#{Sfx[:html]}"
621 up=@toc
622 nxt="#{@per.seg_name_x[@per.seg_name_x_tracker+1]}#{@md.lang_code_insert}#{Sfx[:html]}"
623 if nxt=~/sisu_manifest\.html/
624 @file=SiSU_Env::FileOp.new(@md) if @md
625 if @file.output_dir_structure.by_language_code? \
626 or @file.output_dir_structure.by_filetype?
627 nxt=nxt.gsub(/sisu_manifest\.html/,"../../manifest/#{@file.base_filename.manifest}")
628 end
629 end
630 %{<table summary="segment hidden control pre and next" width="100%" border="0" cellpadding="0" bgcolor=#{the_color.grey_pale} align="center">
631 <tr><td align="left">
632 <a href="#{pre}" target="_top">
633 #{png_nav.dot_pre}
634 </a>
635 </td>
636 <td align="center">
637 <a href="#{up}" target="_top">
638 #{png_nav.dot_toc}
639 </a>
640 </td>
641 <td align="right">
642 <a href="#{nxt}" target="_top">
643 #{png_nav.dot_nxt}
644 </a>
645 #{the_table_close}}
646 end
647 def dot_control_pre
648 pre="#{@per.seg_name_x[@per.seg_name_x_tracker-2]}#{@md.lang_code_insert}#{Sfx[:html]}"
649 up=@toc
650 nxt="#{@md.file.base_filename.html_segtoc}"
651 %{<table summary="segment hidden control pre" width="100%" border="0" cellpadding="0" bgcolor=#{the_color.grey_pale} align="center">
652 <tr><td align="left">
653 <a href="#{pre}" target="_top">
654 #{png_nav.dot_pre}
655 </a>
656 </td>
657 <td align="center">
658 <a href="#{up}" target="_top">
659 #{png_nav.dot_toc}
660 </a>
661 </td>
662 <td align="right">
663 <a href="#{nxt}" target="_top">
664 #{png_nav.dot_nxt}
665 </a>
666 #{the_table_close}}
667 end
668 def toc_nav(f_pre=false,f_nxt=false,use=1)
669 pre=nxt=''
670 toc=%{<td align="center" bgcolor=#{the_color.band1}>
671 <a href="#{@toc}" target="_top">
672 #{png_nav.toc}
673 </a>
674 </td>}
675 pre=%{<td align="center" bgcolor=#{the_color.band1}>
676 <a href="#{@per.seg_name_x[@per.seg_name_x_tracker-use]}#{@md.lang_code_insert}#{Sfx[:html]}" target="_top">
677 #{png_nav.pre}
678 </a>
679 </td>} if f_pre==true
680 nxt=%{<td align="center" bgcolor=#{the_color.band1}>
681 <a href="#{@per.seg_name_x[@per.seg_name_x_tracker+1]}#{@md.lang_code_insert}#{Sfx[:html]}" target="_top">
682 #{png_nav.nxt}
683 </a>
684 </td>} if f_nxt==true
685 if nxt =~/sisu_manifest.html/
686 @file=SiSU_Env::FileOp.new(@md) if @md
687 if @file.output_dir_structure.by_language_code? \
688 or @file.output_dir_structure.by_filetype?
689 nxt=nxt.gsub(/sisu_manifest\.html/,"../../manifest/#{@file.base_filename.manifest}")
690 end
691 end
692 %{<table summary="segment navigation pre/next" border="0" cellpadding="3" cellspacing="0">
693 <tr>
694 #{pre}
695 #{toc}
696 #{nxt}
697 <td>
698 #{the_table_close}}
699 end
700 def toc_next2
701 toc_nav(false,true).dup
702 end
703 def toc_pre_next2
704 toc_nav(true,true).dup
705 end
706 def toc_pre2
707 toc_nav(true,false,2).dup
708 end
709 def manifest_link(text)
710 %{<font size=2>
711 <a href="#{@md.file.base_filename.manifest}" target="_top">
712 #{text}
713 </a>
714 </font>}
715 end
716 def concordance_link(text)
717 if @md.concord_make
718 %{<font size=2>
719 <a href="#{@md.file.base_filename.html_concordance}" target="_top">
720 #{text}
721 </a>
722 </font>}
723 else ''
724 end
725 end
726 def credit
727 %{
728 <div class="main_column">
729 #{@bits.credits_sisu}
730 <a name="bottom" id="bottom"></a>
731 <a name="end" id="end"></a>
732 </div></div>
733 }
734 end
735 def navigation_band(segtocband,seg_table_top_control) #change name to navigation_band_banner
736 %{<table summary="segment navigation band with banner" bgcolor=#{the_color.band1} width="100%"><tr>
737 <td width="20%" align="left">
738 #{button_home}
739 </td>
740 <td width="75%" align="center">
741 #{doc_types}
742 </td>
743 <td width="5%" align="right">
744 #{segtocband}
745 </td></tr>
746 </table>
747 #{seg_table_top_control}}
748 end
749 def navigation_band_bottom(segtocband,seg_table_top_control) #change name to navigation_band_bannerless
750 %{
751 <div class="main_column">
752 <table summary="segment navigation band" bgcolor=#{the_color.band1} width="100%"><tr>
753 <td width="70%" align="center">
754 #{doc_types}
755 </td>
756 <td width="5%" align="right">
757 #{segtocband}
758 </td></tr>
759 </table>
760 #{seg_table_top_control}
761 </div>
762 }
763 end
764 def endnote_mark
765 %{
766 <p class="center" id="endnotes">
767 <hr class="endnote" />
768 </p>}
769 end
770 def endnote_section_open
771 %{
772 <div class="endnote">
773 }
774 end
775 def endnote_section_close
776 %{
777 </div>
778 } #revisit
779 end
780 def head_seg
781 rdf=SiSU_XML_Tags::RDF.new(@md)
782 %{<!DOCTYPE html>
783 <html>
784 <head>
785 <meta charset="utf-8">
786 <title>
787 #{@per.seg_name_x[@per.seg_name_x_tracker]} -
788 #{@md.title.main}
789 </title>
790 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
791 #{rdf.metatag_html}
792 #{@stylesheet.css_head_seg}
793 </head>
794 <body lang="#{@md.opt.lng}">
795 <a name="top" id="top"></a>}
796 end
797 def title_banner(title,subtitle,creator)
798 %{
799 <div class="summary">
800 <p class="tiny">
801 #{title}
802 </p>
803 <p class="tiny">
804 #{subtitle}
805 </p>
806 <p class="tiny">
807 #{creator}
808 </p>
809 <p class="tiny">
810 copy @
811 <a href="#{the_url.home}">
812 #{the_text.txt_home}
813 </a>
814 </p>
815 </div>
816 }
817 end
818 end
819 class HeadScroll < HeadToc
820 def initialize(md)
821 super(md)
822 end
823 def toc_owner_details
824 %{#{the_margin.txt_3}
825 #{the_font.paragraph_font_small}
826 <a href="#owner.details">
827 Owner Details
828 <font size="1" color="#777777">
829 &nbsp;&nbsp;&nbsp;
830 </font>
831 </a>
832 </font>
833 #{the_table_close}}
834 end
835 end
836 class FormatTextObject
837 include SiSU_Parts_HTML
838 attr_accessor :md,:t_o,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url
839 def initialize(md,t_o)
840 @md,@t_o=md,t_o
841 @make=SiSU_Env::ProcessingSettings.new(@md)
842 if t_o.is_a?(Hash)
843 @txt =t_o[:txt] || nil
844 @ocn =t_o[:ocn] || nil
845 @ocn_display =t_o[:ocn_display] || nil
846 @headname =t_o[:headname] || nil
847 @trailer =t_o[:trailer] || nil
848 @endnote_part_a =t_o[:endnote_part_a] || nil
849 @endnote_part_b =t_o[:endnote_part_b] || nil
850 @lnk_url =t_o[:lnk_url] || nil
851 @lnk_txt =t_o[:lnk_txt] || nil
852 @format =t_o[:format] || nil
853 elsif t_o.class.inspect =~/^(?:#<)?SiSU_AO_DocumentStructure/
854 @dob=t_o if defined? t_o.is
855 @named=nametags_seg(@dob)
856 @txt=((defined? t_o.obj) ? t_o.obj : nil)
857 @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil)
858 @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil)
859 else
860 if @md.opt.act[:maintenance][:set]==:on
861 p t_o.class
862 p caller
863 end
864 end
865 @headnamed=(@headname ? %{<a id="h#{@headname}"></a>} : nil)
866 if @txt and not @txt.empty?
867 @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'')
868 end
869 @p_num=ParagraphNumber.new(@md,@ocn)
870 end
871 def nametags_scroll(dob)
872 tags=''
873 if defined? dob.tags \
874 and dob.tags.length > 0 # insert tags "hypertargets"
875 dob.tags.each do |t|
876 t=t.gsub(/[^a-z0-9._-]/,'') #use for all html tags? consider limiting to strict? or implementing earlier
877 tags=tags << %{<named id="#{t}" />}
878 end
879 end
880 tags
881 end
882 def nametags_seg(dob) #FIX
883 tags=''
884 if defined? dob.tags \
885 and dob.tags.length > 0 # insert tags "hypertargets"
886 dob.tags.each do |t|
887 t=t.gsub(/[^a-z0-9._-]/,'') #use for all html tags? consider limiting to strict? or implementing earlier
888 tags=(t =~/^[0-9.]+$/) \
889 ? tags #check what can be sorted in ao
890 : (tags << %{<a name="#{t}" ></a>})
891 end
892 end
893 tags
894 end
895 def headname #check whether used
896 hn=if @t_o.is ==:heading \
897 and not @t_o.name.empty? #determine use
898 hn=(@t_o.is ==:heading) \
899 ? (%{<a id="h#{@t_o.name}"></a>})
900 : (%{<a id="#{@t_o.name}"></a>})
901 else nil
902 end
903 hn
904 end
905 def endnote_body
906 %{
907 <p class="endnote">
908 #{@txt}
909 </p>
910 }
911 end
912 def endnote_body_indent
913 %{
914 <p class="endnote_indent">
915 #{@txt}
916 </p>
917 }
918 end
919 def no_paranum
920 %{
921 <div class="substance">
922 <label class="ocn">&nbsp;</label>
923 <p class="norm">
924 #{@txt}
925 </p>
926 </div>
927 }
928 end
929 def para_form_css(tag,attrib) # regular paragraphs shaped here
930 ul=ulc=''
931 if tag =~/li/
932 ul,ulc="<ul>\n ","\n </ul>"
933 end
934 %{
935 <div class="substance">
936 #{@p_num.ocn_display}
937 #{ul}<#{tag} class="#{attrib}" #{@p_num.id}>
938 #{@named}#{@txt}
939 </#{tag}>#{ulc}
940 </div>
941 }
942 end
943 def para
944 para_form_css('p','norm')
945 end
946 def block
947 para_form_css('p','block')
948 end
949 def group
950 para_form_css('p','group')
951 end
952 def alt
953 para_form_css('p','alt')
954 end
955 def verse
956 para_form_css('p','verse')
957 end
958 def code
959 para_form_css('p','code')
960 end
961 def center
962 para_form_css('p','center')
963 end
964 def bold
965 para_form_css('p','bold')
966 end
967 def bullet
968 para_form_css('li','bullet')
969 end
970 def table
971 @txt=if @t_o.obj !~/^<table\s/
972 table=SiSU_HTML_Shared::TableHTML.new(@t_o) #move, make happen earlier
973 @txt=table.table.obj
974 else @txt
975 end
976 para_form_css('p','norm')
977 end
978 def format(tag,attrib)
979 para_form_css(tag,attrib)
980 end
981 def heading_normal(tag,attrib)
982 section_break=(tag=~/h[1-5]/) \
983 ? '<br><hr width=90% /><br>'
984 : ''
985 %{#{section_break}
986 <div class="substance">
987 #{@p_num.ocn_display}
988 <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name}
989 #{@named}#{@txt}
990 </#{tag}>
991 </div>
992 }
993 end
994 def heading_body
995 heading_normal('p','norm')
996 end
997 def heading_body0
998 heading_normal('h1','norm')
999 end
1000 def heading_body1
1001 heading_normal('h1','norm')
1002 end
1003 def heading_body2
1004 heading_normal('h2','norm')
1005 end
1006 def heading_body3
1007 heading_normal('h3','norm')
1008 end
1009 def heading_body4
1010 heading_normal('h4','norm')
1011 end
1012 def heading_body5
1013 heading_normal('h5','norm')
1014 end
1015 def heading_body6
1016 heading_normal('h6','norm')
1017 end
1018 def heading_body7
1019 heading_normal('h7','norm')
1020 end
1021 def title_heading(tag,attrib)
1022 cl=(@make.build.html_minitoc?) \
1023 ? 'content'
1024 : 'content0'
1025 %{
1026 <div class="#{cl}">
1027 <#{tag} class="#{attrib}">
1028 #{@named}#{@txt}
1029 </#{tag}>
1030 </div>
1031 }
1032 end
1033 def title_heading0
1034 title_heading('h1','tiny')
1035 end
1036 def title_heading1
1037 title_heading('h1','tiny')
1038 end
1039 def title_heading2
1040 title_heading('h2','tiny')
1041 end
1042 def title_heading3
1043 title_heading('h3','tiny')
1044 end
1045 def title_heading4
1046 ''
1047 end
1048 def seg_heading_sub(tag,attrib)
1049 @txt=@txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
1050 %{
1051 <div class="substance">
1052 #{@p_num.ocn_display}
1053 <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} #{@headnamed}
1054 #{@named}#{@txt}
1055 </#{tag}>
1056 </div>
1057 }
1058 end
1059 def seg_heading4
1060 %{
1061 <div class="substance">
1062 #{@p_num.ocn_display}
1063 <h1 class="norm" #{@p_num.id}>#{@p_num.name}
1064 #{@txt}
1065 </h1>
1066 </div>
1067 }
1068 end
1069 def seg_heading5
1070 seg_heading_sub('p','bold')
1071 end
1072 def seg_heading6
1073 seg_heading_sub('p','bold')
1074 end
1075 def dl #check :trailer
1076 "<dl><b>#{@txt}</b> #{@trailer}</dl>"
1077 end
1078 def table_css_end
1079 '</table>
1080 </p>
1081 </div>'
1082 end
1083 def gsub_body #fix
1084 @txt=case @txt
1085 when /^\((i+|iv|v|vi+|ix|x|xi+)\)/
1086 @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'<b>(\1)</b>')
1087 when /^\(?(\d|[a-z])+\)/
1088 @txt.gsub(/^\((\d+|[a-z])+\)/,'<b>(\1)</b>')
1089 when /^\s*\d{1,3}\.\s/
1090 @txt.gsub(/^\s*(\d+\.)/,'<b>\1</b>')
1091 when /^\s*[A-Z]\.\s/
1092 @txt.gsub(/^\s*([A-Z]\.)/,'<b>\1</b>')
1093 else @txt
1094 end
1095 end
1096 def bold_para
1097 %{#{the_margin.txt_0}
1098 <p class="bold">
1099 #{@txt}
1100 </p>
1101 #{the_margin.num_css}
1102 &nbsp;&nbsp;&nbsp;
1103 #{the_table_close}}
1104 end
1105 def bold_heading
1106 %{<p class="bold">
1107 #{@txt}
1108 </p>
1109 #{the_margin.num_css}
1110 &nbsp;&nbsp;&nbsp;
1111 #{the_table_close}}
1112 end
1113 def toc_head_copy_at
1114 %{<p class="center">#{@txt}</p>\n}
1115 end
1116 def center
1117 %{<p class="center">#{@txt}</p>\n}
1118 end
1119 def bold
1120 %{<p class="bold">#{@txt}</p>\n}
1121 end
1122 def center_bold
1123 %{<p class="centerbold">#{@txt}</p>\n}
1124 end
1125 end
1126 class FormatScroll < FormatTextObject
1127 def initialize(md,txt)
1128 super(md,txt)
1129 end
1130 end
1131 class FormatSeg < FormatTextObject
1132 def initialize(md,txt)
1133 super(md,txt)
1134 end
1135 def endnote_seg_body(fn='')
1136 fn="../#{@md.fnb}" if fn.to_s.empty?
1137 %{
1138 <p class="endnote">
1139 #{@endnote_part_a}#{fn}#{@md.lang_code_insert}#{Sfx[:html]}#{@endnote_part_b}
1140 </p>
1141 }
1142 end
1143 def clean(txt)
1144 txt=txt.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/,'').
1145 gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'')
1146 end
1147 def subtoc_lev(tag,attrib)
1148 @txt=clean(@txt)
1149 txt=if @txt \
1150 and @txt =~/<\/?i>|<a\s+name="\S+?">/mi
1151 @txt.gsub(/<\/?i>|<a\s+name="\S+?">/mi,'') #removes name markers from subtoc, go directly to substantive text
1152 else @txt
1153 end
1154 note=''
1155 if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end
1156 note=$1
1157 note=note.gsub(/[\s]+/m,' ')
1158 txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ').
1159 gsub(/<a[\s]+name="-\d+"[\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
1160 end
1161 %{<#{tag} class="#{attrib}">
1162 <a href="##{@ocn}"><i>#{txt}</i></a> #{note}
1163 </#{tag}>}
1164 end
1165 def subtoc_lev5
1166 subtoc_lev('h5','subtoc') if @txt
1167 end
1168 def subtoc_lev6
1169 subtoc_lev('h6','subtoc') if @txt
1170 end
1171 def subtoc_lev7
1172 subtoc_lev('h7','subtoc') if @txt
1173 end
1174 def heading_sub(tag,attrib)
1175 @txt=@txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
1176 %{
1177 <div class="substance">
1178 #{@p_num.ocn_display}
1179 <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} #{@headnamed}
1180 #{@txt}
1181 </#{tag}>
1182 </div>
1183 }
1184 end
1185 def heading5
1186 heading_sub('p','bold')
1187 end
1188 def heading6
1189 heading_sub('p','bold')
1190 end
1191 def heading4
1192 %{
1193 <div class="substance">
1194 #{@p_num.ocn_display}
1195 <h1 class="norm" #{@p_num.id}>#{@p_num.name}
1196 #{@t_o[:format]}
1197 #{@txt}
1198 </h1>
1199 </div>
1200 }
1201 end
1202 def navigation_heading4
1203 %{<table summary="navigation segment heading 4" width=100% bgcolor="#08163f" border="0">
1204 <tr><td align="center">
1205 <p class="bold">
1206 #{@txt}
1207 </p>
1208 #{the_table_close}}
1209 end
1210 def navigation_heading5
1211 %{<p class="bold">
1212 #{@txt}
1213 </p>}
1214 end
1215 def navigation_heading6
1216 %{<p class="bold">
1217 #{@txt}
1218 </p>}
1219 end
1220 def navigation_center
1221 "<center>#{@txt}</center>"
1222 end
1223 end
1224 class FormatToc < FormatTextObject
1225 def initialize(md,txt)
1226 super(md,txt)
1227 end
1228 def links_guide
1229 %{ <li class="doc">
1230 <a href="#{@lnk_url}" target="_top">
1231 #{@lnk_txt}
1232 </a>
1233 </li>
1234 }
1235 end
1236 def lev(tag,attrib)
1237 if @txt
1238 %{<#{tag} class="#{attrib}">
1239 #{@txt}
1240 </#{tag}>
1241 }
1242 else ''
1243 end
1244 end
1245 def lev0 #docinfo
1246 lev('h1','toc')
1247 end
1248 def lev1
1249 lev('h1','toc')
1250 end
1251 def lev2
1252 lev('h2','toc')
1253 end
1254 def lev3
1255 lev('h3','toc')
1256 end
1257 def lev4
1258 lev('h4','toc')
1259 end
1260 def lev5
1261 lev('h5','toc')
1262 end
1263 def lev6
1264 lev('h6','toc')
1265 end
1266 def lev7
1267 lev('h7','toc')
1268 end
1269 def strip_endnotes(txt)
1270 txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
1271 txt
1272 end
1273 def mini_lev0
1274 @txt=strip_endnotes(@txt)
1275 lev('h1','minitoc')
1276 end
1277 def mini_lev1
1278 @txt=strip_endnotes(@txt)
1279 lev('h1','minitoc')
1280 end
1281 def mini_lev2
1282 @txt=strip_endnotes(@txt)
1283 lev('h2','minitoc')
1284 end
1285 def mini_lev3
1286 @txt=strip_endnotes(@txt)
1287 lev('h3','minitoc')
1288 end
1289 def mini_lev4
1290 @txt=strip_endnotes(@txt)
1291 lev('h4','minitoc')
1292 end
1293 def mini_lev5
1294 @txt=strip_endnotes(@txt)
1295 lev('h5','minitoc')
1296 end
1297 def mini_lev6
1298 @txt=strip_endnotes(@txt)
1299 lev('h6','minitoc')
1300 end
1301 def mini_lev7
1302 @txt=strip_endnotes(@txt)
1303 lev('h7','minitoc')
1304 end
1305 def mini_lev0 #docinfo
1306 lev('h1','minitoc')
1307 end
1308 def mini_tail
1309 %{
1310 <h4 class="minitoc">
1311 <a href="sisu_manifest.html">Manifest (alternative outputs)</a>
1312 </h4>
1313 }
1314 end
1315 def mini_concord_tail
1316 %{
1317 <h4 class="minitoc">
1318 <a href="concordance.html">Concordance (wordlist)</a>
1319 </h4>
1320 <h4 class="minitoc">
1321 <a href="sisu_manifest.html">Manifest (alternative outputs)</a>
1322 </h4>
1323 }
1324 end
1325 end
1326 class FormatStr
1327 def initialize(md,str)
1328 @str=str
1329 end
1330 def center
1331 %{<p class="center">#{@str}</p>\n}
1332 end
1333 def bold
1334 %{<p class="bold">#{@str}</p>\n}
1335 end
1336 def center_bold
1337 %{<p class="centerbold">#{@str}</p>\n}
1338 end
1339 def endnote_body
1340 %{
1341 <p class="endnote">
1342 #{@str}
1343 </p>
1344 }
1345 end
1346 end
1347 end
1348 __END__