sisu 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. checksums.yaml +7 -0
  2. data/bin/sisu +367 -0
  3. data/bin/sisugem +367 -0
  4. data/data/sisu/image/arrow_next_red.png +0 -0
  5. data/data/sisu/image/arrow_prev_red.png +0 -0
  6. data/data/sisu/image/arrow_up_red.png +0 -0
  7. data/data/sisu/image/b_bluebell.png +0 -0
  8. data/data/sisu/image/b_doc.png +0 -0
  9. data/data/sisu/image/b_epub.png +0 -0
  10. data/data/sisu/image/b_home.png +0 -0
  11. data/data/sisu/image/b_info.png +0 -0
  12. data/data/sisu/image/b_odf.png +0 -0
  13. data/data/sisu/image/b_pdf.png +0 -0
  14. data/data/sisu/image/b_search.png +0 -0
  15. data/data/sisu/image/b_toc.png +0 -0
  16. data/data/sisu/image/bullet_08.png +0 -0
  17. data/data/sisu/image/bullet_09.png +0 -0
  18. data/data/sisu/image/bullet_10.png +0 -0
  19. data/data/sisu/image/bullet_11.png +0 -0
  20. data/data/sisu/image/bullet_12.png +0 -0
  21. data/data/sisu/image/bullet_doc.png +0 -0
  22. data/data/sisu/image/bullet_red.png +0 -0
  23. data/data/sisu/image/dot_clear.png +0 -0
  24. data/data/sisu/image/dot_white.png +0 -0
  25. data/data/sisu/image/gplv3.png +0 -0
  26. data/data/sisu/image/gplv3_free_software.png +0 -0
  27. data/data/sisu/image/next.png +0 -0
  28. data/data/sisu/image/previous.png +0 -0
  29. data/data/sisu/image/rb7.ico +0 -0
  30. data/data/sisu/image/sisu.png +0 -0
  31. data/data/sisu/image/toctoc.png +0 -0
  32. data/data/sisu/version.yml +5 -0
  33. data/lib/sisu.rb +94 -0
  34. data/lib/sisu/air.rb +80 -0
  35. data/lib/sisu/ao.rb +590 -0
  36. data/lib/sisu/ao_character_check.rb +102 -0
  37. data/lib/sisu/ao_composite.rb +286 -0
  38. data/lib/sisu/ao_doc_objects.rb +565 -0
  39. data/lib/sisu/ao_doc_str.rb +2269 -0
  40. data/lib/sisu/ao_endnotes.rb +136 -0
  41. data/lib/sisu/ao_expand_insertions.rb +514 -0
  42. data/lib/sisu/ao_hash_digest.rb +174 -0
  43. data/lib/sisu/ao_idx.rb +422 -0
  44. data/lib/sisu/ao_images.rb +187 -0
  45. data/lib/sisu/ao_metadata.rb +86 -0
  46. data/lib/sisu/ao_misc_arrange.rb +207 -0
  47. data/lib/sisu/ao_numbering.rb +720 -0
  48. data/lib/sisu/ao_persist.rb +194 -0
  49. data/lib/sisu/ao_references.rb +502 -0
  50. data/lib/sisu/ao_syntax.rb +640 -0
  51. data/lib/sisu/cgi.rb +84 -0
  52. data/lib/sisu/cgi_pgsql.rb +270 -0
  53. data/lib/sisu/cgi_sql_common.rb +986 -0
  54. data/lib/sisu/cgi_sqlite.rb +244 -0
  55. data/lib/sisu/conf.rb +287 -0
  56. data/lib/sisu/constants.rb +388 -0
  57. data/lib/sisu/css.rb +3484 -0
  58. data/lib/sisu/db_columns.rb +1997 -0
  59. data/lib/sisu/db_create.rb +689 -0
  60. data/lib/sisu/db_dbi.rb +90 -0
  61. data/lib/sisu/db_drop.rb +207 -0
  62. data/lib/sisu/db_import.rb +877 -0
  63. data/lib/sisu/db_indexes.rb +146 -0
  64. data/lib/sisu/db_load_tuple.rb +323 -0
  65. data/lib/sisu/db_remove.rb +182 -0
  66. data/lib/sisu/db_select.rb +230 -0
  67. data/lib/sisu/db_sqltxt.rb +173 -0
  68. data/lib/sisu/db_tests.rb +114 -0
  69. data/lib/sisu/dbi.rb +166 -0
  70. data/lib/sisu/dbi_discrete.rb +206 -0
  71. data/lib/sisu/digests.rb +306 -0
  72. data/lib/sisu/dp.rb +1606 -0
  73. data/lib/sisu/dp_identify_markup.rb +161 -0
  74. data/lib/sisu/dp_make.rb +668 -0
  75. data/lib/sisu/embedded.rb +149 -0
  76. data/lib/sisu/errors.rb +84 -0
  77. data/lib/sisu/generic_parts.rb +131 -0
  78. data/lib/sisu/git.rb +277 -0
  79. data/lib/sisu/html.rb +775 -0
  80. data/lib/sisu/html_concordance.rb +391 -0
  81. data/lib/sisu/html_format.rb +1348 -0
  82. data/lib/sisu/html_harvest.rb +109 -0
  83. data/lib/sisu/html_harvest_author_format.rb +111 -0
  84. data/lib/sisu/html_harvest_authors.rb +466 -0
  85. data/lib/sisu/html_harvest_topics.rb +893 -0
  86. data/lib/sisu/html_lite_shared.rb +324 -0
  87. data/lib/sisu/html_manifest.rb +1032 -0
  88. data/lib/sisu/html_minitoc.rb +230 -0
  89. data/lib/sisu/html_parts.rb +437 -0
  90. data/lib/sisu/html_persist.rb +237 -0
  91. data/lib/sisu/html_promo.rb +440 -0
  92. data/lib/sisu/html_scroll.rb +235 -0
  93. data/lib/sisu/html_segments.rb +716 -0
  94. data/lib/sisu/html_shared.rb +62 -0
  95. data/lib/sisu/html_table.rb +64 -0
  96. data/lib/sisu/html_tune.rb +301 -0
  97. data/lib/sisu/hub.rb +277 -0
  98. data/lib/sisu/hub_actions.rb +1122 -0
  99. data/lib/sisu/hub_loop_markup_files.rb +170 -0
  100. data/lib/sisu/hub_options.rb +1695 -0
  101. data/lib/sisu/i18n.rb +702 -0
  102. data/lib/sisu/manpage.rb +377 -0
  103. data/lib/sisu/manpage_format.rb +85 -0
  104. data/lib/sisu/object_munge.rb +307 -0
  105. data/lib/sisu/prog_text_translation.rb +1702 -0
  106. data/lib/sisu/qrcode.rb +754 -0
  107. data/lib/sisu/relaxng.rb +1153 -0
  108. data/lib/sisu/remote.rb +246 -0
  109. data/lib/sisu/rexml.rb +148 -0
  110. data/lib/sisu/se.rb +158 -0
  111. data/lib/sisu/se_cleanoutput.rb +145 -0
  112. data/lib/sisu/se_clear.rb +105 -0
  113. data/lib/sisu/se_createsite.rb +273 -0
  114. data/lib/sisu/se_css.rb +221 -0
  115. data/lib/sisu/se_date.rb +92 -0
  116. data/lib/sisu/se_db.rb +214 -0
  117. data/lib/sisu/se_envcall.rb +326 -0
  118. data/lib/sisu/se_file_op.rb +2758 -0
  119. data/lib/sisu/se_filemap.rb +247 -0
  120. data/lib/sisu/se_get_init.rb +238 -0
  121. data/lib/sisu/se_hub_particulars.rb +234 -0
  122. data/lib/sisu/se_info_env.rb +2179 -0
  123. data/lib/sisu/se_info_port.rb +70 -0
  124. data/lib/sisu/se_info_system.rb +202 -0
  125. data/lib/sisu/se_load.rb +108 -0
  126. data/lib/sisu/se_processing.rb +659 -0
  127. data/lib/sisu/se_programs.rb +394 -0
  128. data/lib/sisu/se_remotes.rb +553 -0
  129. data/lib/sisu/se_standardise_lang.rb +176 -0
  130. data/lib/sisu/se_version.rb +174 -0
  131. data/lib/sisu/shared_images.rb +137 -0
  132. data/lib/sisu/shared_markup_alt.rb +336 -0
  133. data/lib/sisu/shared_metadata.rb +1361 -0
  134. data/lib/sisu/shared_sem.rb +156 -0
  135. data/lib/sisu/sisu_thor_lib.rb +407 -0
  136. data/lib/sisu/sitemaps.rb +224 -0
  137. data/lib/sisu/src_kdissert_share.rb +102 -0
  138. data/lib/sisu/src_po4a_share.rb +309 -0
  139. data/lib/sisu/src_po4a_shelf.rb +1217 -0
  140. data/lib/sisu/src_po4a_shelf_set.rb +297 -0
  141. data/lib/sisu/src_po4a_sst_ao_sst.rb +893 -0
  142. data/lib/sisu/src_po4a_sst_ao_sst_set.rb +284 -0
  143. data/lib/sisu/src_po4a_sstm.rb +135 -0
  144. data/lib/sisu/src_shared.rb +347 -0
  145. data/lib/sisu/src_sisupod_make.rb +171 -0
  146. data/lib/sisu/src_sisupod_sstm.rb +109 -0
  147. data/lib/sisu/sst_convert_markup.rb +323 -0
  148. data/lib/sisu/sst_do_inline_footnotes.rb +440 -0
  149. data/lib/sisu/sst_from_xml.rb +178 -0
  150. data/lib/sisu/sst_identify_markup.rb +482 -0
  151. data/lib/sisu/sst_to_s_xml_sax.rb +471 -0
  152. data/lib/sisu/termsheet.rb +163 -0
  153. data/lib/sisu/texinfo.rb +430 -0
  154. data/lib/sisu/texinfo_format.rb +541 -0
  155. data/lib/sisu/texpdf.rb +1162 -0
  156. data/lib/sisu/texpdf_format.rb +1689 -0
  157. data/lib/sisu/texpdf_parts.rb +235 -0
  158. data/lib/sisu/txt_asciidoc.rb +354 -0
  159. data/lib/sisu/txt_asciidoc_decorate.rb +207 -0
  160. data/lib/sisu/txt_markdown.rb +389 -0
  161. data/lib/sisu/txt_markdown_decorate.rb +207 -0
  162. data/lib/sisu/txt_orgmode.rb +376 -0
  163. data/lib/sisu/txt_orgmode_decorate.rb +186 -0
  164. data/lib/sisu/txt_output.rb +86 -0
  165. data/lib/sisu/txt_plain.rb +410 -0
  166. data/lib/sisu/txt_plain_decorate.rb +189 -0
  167. data/lib/sisu/txt_read.rb +109 -0
  168. data/lib/sisu/txt_rst.rb +371 -0
  169. data/lib/sisu/txt_rst_decorate.rb +186 -0
  170. data/lib/sisu/txt_shared.rb +241 -0
  171. data/lib/sisu/txt_textile.rb +367 -0
  172. data/lib/sisu/txt_textile_decorate.rb +186 -0
  173. data/lib/sisu/update.rb +141 -0
  174. data/lib/sisu/urls.rb +696 -0
  175. data/lib/sisu/utils.rb +232 -0
  176. data/lib/sisu/utils_composite.rb +115 -0
  177. data/lib/sisu/utils_response.rb +114 -0
  178. data/lib/sisu/utils_screen_text_color.rb +472 -0
  179. data/lib/sisu/utils_spell.rb +99 -0
  180. data/lib/sisu/webrick.rb +191 -0
  181. data/lib/sisu/wikispeak.rb +375 -0
  182. data/lib/sisu/xhtml.rb +472 -0
  183. data/lib/sisu/xhtml_epub2.rb +890 -0
  184. data/lib/sisu/xhtml_epub2_concordance.rb +322 -0
  185. data/lib/sisu/xhtml_epub2_format.rb +2272 -0
  186. data/lib/sisu/xhtml_epub2_persist.rb +278 -0
  187. data/lib/sisu/xhtml_epub2_segments.rb +599 -0
  188. data/lib/sisu/xhtml_epub2_tune.rb +330 -0
  189. data/lib/sisu/xhtml_parts.rb +183 -0
  190. data/lib/sisu/xhtml_shared.rb +62 -0
  191. data/lib/sisu/xhtml_table.rb +97 -0
  192. data/lib/sisu/xml_docbook5.rb +376 -0
  193. data/lib/sisu/xml_dom.rb +624 -0
  194. data/lib/sisu/xml_fictionbook2.rb +389 -0
  195. data/lib/sisu/xml_format.rb +865 -0
  196. data/lib/sisu/xml_md_oai_pmh_dc.rb +229 -0
  197. data/lib/sisu/xml_odf_odt.rb +887 -0
  198. data/lib/sisu/xml_odf_odt_format.rb +674 -0
  199. data/lib/sisu/xml_parts.rb +191 -0
  200. data/lib/sisu/xml_persist.rb +126 -0
  201. data/lib/sisu/xml_sax.rb +521 -0
  202. data/lib/sisu/xml_scaffold_structure_collapsed.rb +198 -0
  203. data/lib/sisu/xml_scaffold_structure_sisu.rb +201 -0
  204. data/lib/sisu/xml_shared.rb +665 -0
  205. data/lib/sisu/xml_tables.rb +261 -0
  206. data/lib/sisu/zap.rb +90 -0
  207. metadata +251 -0
@@ -0,0 +1,389 @@
1
+ # encoding: utf-8
2
+ =begin
3
+
4
+ * Name: SiSU
5
+
6
+ ** Description: documents, structuring, processing, publishing, search
7
+ *** Fictionbook XML rendition
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/xml_fictionbook.rb;hb=HEAD>
55
+
56
+ =end
57
+ module SiSU_XML_Fictionbook
58
+ require_relative 'se_hub_particulars' # se_hub_particulars.rb
59
+ include SiSU_Particulars
60
+ require_relative 'ao' # ao.rb
61
+ require_relative 'se' # se.rb
62
+ include SiSU_Env
63
+ require_relative 'txt_shared' # txt_shared.rb
64
+ include SiSU_TextUtils
65
+ require_relative 'xml_shared' # xml_shared.rb
66
+ include SiSU_XML_Munge
67
+ class Source
68
+ def initialize(opt)
69
+ @opt=opt
70
+ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
71
+ end
72
+ def read
73
+ begin
74
+ @md,@ao_array=@particulars.md,@particulars.ao_array
75
+ @env=@particulars.env
76
+ report
77
+ SiSU_XML_Fictionbook::Source::Scroll.new(@ao_array,@md).songsheet
78
+ rescue
79
+ SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
80
+ __LINE__.to_s + ':' + __FILE__
81
+ end
82
+ ensure
83
+ Dir.chdir(@opt.f_pth[:pth])
84
+ end
85
+ end
86
+ private
87
+ def report
88
+ unless @opt.act[:quiet][:set]==:on
89
+ tool=(@opt.act[:verbose][:set]==:on \
90
+ || @opt.act[:verbose_plus][:set]==:on \
91
+ || @opt.act[:maintenance][:set]==:on) \
92
+ ? "#{@env.program.fictionbook_viewer} #{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}"
93
+ : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}"
94
+ (@opt.act[:verbose][:set]==:on \
95
+ || @opt.act[:verbose_plus][:set]==:on \
96
+ || @opt.act[:maintenance][:set]==:on) \
97
+ ? SiSU_Screen::Ansi.new(
98
+ @opt.act[:color_state][:set],
99
+ 'Fictionbook',
100
+ tool
101
+ ).green_hi_blue
102
+ : SiSU_Screen::Ansi.new(
103
+ @opt.act[:color_state][:set],
104
+ 'Fictionbook',
105
+ tool
106
+ ).green_title_hi
107
+ if (@opt.act[:verbose_plus][:set]==:on \
108
+ || @opt.act[:maintenance][:set]==:on)
109
+ SiSU_Screen::Ansi.new(
110
+ @opt.act[:color_state][:set],
111
+ @opt.fns,
112
+ "#{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}"
113
+ ).flow
114
+ end
115
+ end
116
+ end
117
+ class Scroll <Source
118
+ def initialize(data='',md='')
119
+ @data,@md=data,md
120
+ @trans=SiSU_XML_Munge::Trans.new(@md)
121
+ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(md.opt)
122
+ @env=@particulars.env
123
+ end
124
+ def songsheet
125
+ @t='sisu'
126
+ data=@data
127
+ if @md.opt.act[:verbose_plus][:set]==:on
128
+ structure_collapsed(data)
129
+ end
130
+ head
131
+ endnotes=extract_endnotes
132
+ images_base64=extract_images
133
+ data=markup_text(data)
134
+ structure_build_collapsed(data,endnotes,images_base64)
135
+ end
136
+ def spaces
137
+ Ax[:spaces]
138
+ end
139
+ def tags
140
+ # collapsed -->
141
+ def collapsed
142
+ %w[ 0 1 2 3 4 5 ]
143
+ end
144
+ def fictionbook
145
+ [
146
+ 'section',
147
+ 'section',
148
+ 'section',
149
+ 'section',
150
+ 'section',
151
+ 'section',
152
+ 'section'
153
+ ]
154
+ end
155
+ self
156
+ end
157
+ def put(line)
158
+ puts line if @md.opt.act[:verbose_plus][:set]==:on
159
+ end
160
+ def head
161
+ version=SiSU_Env::InfoVersion.instance.get_version
162
+ rb_ver=SiSU_Env::InfoVersion.instance.rbversion
163
+ date_available=if defined? @md.date.available; "\n <p>#{@md.date.available} Initial version</p>"
164
+ else ''
165
+ end
166
+ date_modified=if defined? @md.date.modified; "\n <p>#{@md.date.modified} Last Modified</p>"
167
+ else ''
168
+ end
169
+ coverpageimage=if defined? @md.make.cover_image[:cover]
170
+ %{\n <coverpage><image href="##{@md.make.cover_image[:cover]}" /></coverpage>}
171
+ else ''
172
+ end
173
+ if defined? @md.authors \
174
+ and @md.authors.length > 0
175
+ authors=[]
176
+ @md.authors.each do |author|
177
+ authors << ' <author>'
178
+ if not author[:others].empty?
179
+ authors << %{ <first-name>#{author[:others]}</first-name>}
180
+ end
181
+ if not author[:the].empty?
182
+ authors << %{ <last-name>#{author[:the]}</last-name>}
183
+ end
184
+ authors << ' </author>'
185
+ end
186
+ authors=authors.join("\n")
187
+ end
188
+ <<-WOK
189
+ <?xml version="1.0" encoding="UTF-8"?>
190
+ <FictionBook xmlns:xl="http://www.w3.org/1999/xlink"
191
+ xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
192
+ <description>
193
+ <title-info>
194
+ <genre match="100">***</genre>
195
+ #{authors}
196
+ <book-title>#{@md.title.full}</book-title>#{coverpageimage}
197
+ <annotation>
198
+ </annotation>
199
+ <date value="#{@md.date.published}">#{@md.date.published}</date>
200
+ </title-info>
201
+ <document-info>
202
+ <author>
203
+ <first-name/>
204
+ <last-name/>
205
+ <nickname/>
206
+ </author>
207
+ <program-used>#{version.project} #{version.version} and #{rb_ver}</program-used>
208
+ <date value="#{version.date}">#{version.date}</date>
209
+ <src-url>#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}</src-url>
210
+ <id></id>
211
+ <version>1.0</version>
212
+ <history>#{date_available}#{date_modified}
213
+ </history>
214
+ </document-info>
215
+ </description>
216
+ <body>
217
+ WOK
218
+ end
219
+ def extract_endnotes #work on
220
+ endnotes,endnotes_raw,endnotes_b=[],[],[]
221
+ @data.each do |para|
222
+ endnotes_raw << para.obj.scan(/#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m)
223
+ endnotes_b << para.obj.scan(/#{Mx[:en_b_o]}(.+?)#{Mx[:en_b_c]}/m)
224
+ end
225
+ endnotes_raw.flatten.each do |en|
226
+ en=@trans.markup_fictionbook(en)
227
+ endnotes << en.gsub(/([\d+*]+)\s+(.+)/m,
228
+ %{<section id="footnote\\1">\n
229
+ <title><p>\\1.</p></title>\n
230
+ <p>\\2</p>\n
231
+ </section>})
232
+ end
233
+ endnotes_raw=[]
234
+ endnotes
235
+ end
236
+ def extract_images #work on
237
+ begin
238
+ require 'base64'
239
+ rescue LoadError
240
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
241
+ error('base64 NOT FOUND (LoadError)')
242
+ end
243
+ images_raw,images_base64_fb2=[],[]
244
+ images_base64={}
245
+ if defined? @md.make.cover_image[:cover]
246
+ images_raw << @md.make.cover_image[:cover]
247
+ end
248
+ @data.each do |para|
249
+ images_raw << para.obj.scan(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m)
250
+ end
251
+ images_raw.flatten.sort.each do |img|
252
+ imgpth=@env.url.images_local + '/' + img
253
+ open(imgpth)
254
+ if FileTest.file?(imgpth)
255
+ images_base64[img]=Base64.encode64(File.read(imgpth))
256
+ end
257
+ end
258
+ images_raw=[]
259
+ images_base64.each_key do |k|
260
+ imgtype=case k
261
+ when /\.jpg/ then 'jpeg'
262
+ when /\.png/ then 'png'
263
+ when /\.gif/ then 'gif'
264
+ else 'jpeg'
265
+ end
266
+ images_base64_fb2 << %{<binary content-type="image/#{imgtype}" id="#{k}">#{images_base64[k]}
267
+ </binary>
268
+ }
269
+ end
270
+ images_base64_fb2.join("\n")
271
+ end
272
+ def markup_text(data)
273
+ data.each_with_index do |o,i|
274
+ if o.is ==:heading || o.is ==:para
275
+ o.obj=@trans.markup_fictionbook(o.obj,o.is) #unless o.obj==nil
276
+ end
277
+ end
278
+ data
279
+ end
280
+ def tail(images_base64_fb2)
281
+ <<-WOK
282
+ </body>
283
+ #{images_base64_fb2}
284
+ </FictionBook>
285
+ WOK
286
+ end
287
+ def output(o,comment='')
288
+ puts o.lc == (0..6) \
289
+ ? "#{spaces*o.lc}<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}</#{o.lc}>#{comment}"
290
+ : "<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}</#{o.lc}>#{comment}"
291
+ end
292
+ def structure_collapsed(data)
293
+ puts "\ncollapsed structure, heading outline --->\n\n"
294
+ data.each_with_index do |o,i|
295
+ if (o.is ==:heading || o.is ==:heading_insert)
296
+ output(o)
297
+ end
298
+ end
299
+ end
300
+ def endnotes_build(endnotes,filename_fictionbook)
301
+ if endnotes.length > 0
302
+ filename_fictionbook.puts %{</body><body name="notes">}
303
+ endnotes.each do |en|
304
+ filename_fictionbook.puts SiSU_TextUtils::Wrap.new(en,80,6).line_wrap
305
+ end
306
+ end
307
+ end
308
+ def structure_build_collapsed(data,endnotes,images_base64)
309
+ file=SiSU_Env::FileOp.new(@md)
310
+ filename_fictionbook=file.write_file.xml_fictionbook
311
+ h=0
312
+ doc_position=:head
313
+ filename_fictionbook.puts head
314
+ data.each_with_index do |o,i|
315
+ ocn=if @make.build.ocn?
316
+ (defined? o.ocn and not o.ocn.nil?) \
317
+ ? "\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}"
318
+ : ''
319
+ else ''
320
+ end
321
+ if o.is ==:heading
322
+ unless doc_position==:head
323
+ filename_fictionbook.puts structure_build_tag_close(o.lc,h)
324
+ end
325
+ doc_position=:body_and_tail
326
+ filename_fictionbook.puts %{#{spaces*o.lc}<#{tags.fictionbook[o.lc]}>
327
+ #{spaces*o.lc}<title>
328
+ }
329
+ filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,(o.lc*2+2)).line_wrap
330
+ filename_fictionbook.puts %{#{spaces*o.lc}</title>}
331
+ h=o.lc
332
+ elsif o.is ==:heading_insert \
333
+ and o.obj =~/Endnotes/ \
334
+ and o.ln == 1
335
+ break
336
+ elsif (o.of ==:para or o.of ==:block)
337
+ filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,6).line_wrap
338
+ end
339
+ end
340
+ filename_fictionbook.puts structure_build_tag_close(0,h)
341
+ endnotes_build(endnotes,filename_fictionbook)
342
+ filename_fictionbook.puts tail(images_base64)
343
+ filename_fictionbook.close
344
+ end
345
+ def structure_build_tag_close(lc,h)
346
+ x=[]
347
+ case h
348
+ when 0
349
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
350
+ when 1
351
+ x << "#{spaces*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
352
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
353
+ when 2
354
+ x << "#{spaces*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
355
+ x << "#{spaces*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
356
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
357
+ when 3
358
+ x << "#{spaces*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
359
+ x << "#{spaces*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
360
+ x << "#{spaces*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
361
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
362
+ when 4
363
+ x << "#{spaces*4}</#{tags.fictionbook[4]}>" if (lc <= 4)
364
+ x << "#{spaces*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
365
+ x << "#{spaces*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
366
+ x << "#{spaces*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
367
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
368
+ when 5
369
+ x << "#{spaces*5}</#{tags.fictionbook[5]}>" if (lc <= 5)
370
+ x << "#{spaces*4}</#{tags.fictionbook[4]}>" if (lc <= 4)
371
+ x << "#{spaces*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
372
+ x << "#{spaces*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
373
+ x << "#{spaces*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
374
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
375
+ when 6
376
+ x << "#{spaces*6}</#{tags.fictionbook[6]}>" if (lc <= 6)
377
+ x << "#{spaces*5}</#{tags.fictionbook[5]}>" if (lc <= 5)
378
+ x << "#{spaces*4}</#{tags.fictionbook[4]}>" if (lc <= 4)
379
+ x << "#{spaces*3}</#{tags.fictionbook[3]}>" if (lc <= 3)
380
+ x << "#{spaces*2}</#{tags.fictionbook[2]}>" if (lc <= 2)
381
+ x << "#{spaces*1}</#{tags.fictionbook[1]}>" if (lc <= 1)
382
+ x << "#{spaces*0}</#{tags.fictionbook[0]}>" if (lc <= 0)
383
+ end
384
+ x.join("\n")
385
+ end
386
+ end
387
+ end
388
+ end
389
+ __END__
@@ -0,0 +1,865 @@
1
+ # encoding: utf-8
2
+ =begin
3
+
4
+ * Name: SiSU
5
+
6
+ ** Description: documents, structuring, processing, publishing, search
7
+ ** xml 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/xml_format.rb;hb=HEAD>
55
+
56
+ =end
57
+ module SiSU_XML_Format
58
+ require_relative 'dp' # dp.rb
59
+ require_relative 'xml_parts' # xml_parts.rb
60
+ include SiSU_Param
61
+ class ParagraphNumber
62
+ def initialize(md,paranum)
63
+ @md=md
64
+ @paranum=(paranum ? (/(\d+)/m.match(paranum)[1]) : nil)
65
+ end
66
+ def display
67
+ p_num_display=if @paranum
68
+ @paranum.gsub(/(\d+)/,
69
+ '<font size="1" color="#777777">' +
70
+ '&nbsp;&nbsp;\1</font>')
71
+ else ''
72
+ end
73
+ p_num_display
74
+ end
75
+ def name
76
+ p_num_name=@paranum.gsub(/(\d+)/,'<a name="\1"></a>')
77
+ p_num_name
78
+ end
79
+ def goto
80
+ p_num_goto=@paranum.gsub(/(\d+)/,'<a href="#\1">')
81
+ p_num_goto
82
+ end
83
+ end
84
+ class HeadInformation
85
+ include SiSU_Parts_XML
86
+ def initialize #dc rdf
87
+ @full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords=''
88
+ @md=@@md
89
+ # DublinCore 1 - title
90
+ @rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n}
91
+ if defined? @md.title.full \
92
+ and @md.title.full # DublinCore 1 - title
93
+ @rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n}
94
+ @full_title=%{<meta name="dc.title" content="#{seg_name}#{@md.title.full}" />\n}
95
+ end
96
+ if defined? @md.creator.author \
97
+ and @md.creator.author # DublinCore 2 - creator/author (author)
98
+ @rdf_author=%{ dc.author="#{@md.creator.author}"\n}
99
+ @author=%{<meta name="dc.author" content="#{@md.creator.author}" />\n}
100
+ end
101
+ if defined? @md.classify.subject \
102
+ and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???)
103
+ @rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n}
104
+ @subject=%{<meta name="dc.subject" content="#{@md.classify.subject}" />\n}
105
+ end
106
+ if defined? @md.notes.description \
107
+ and @md.notes.description=~/\S+/ # DublinCore 4 - description
108
+ @rdf_description=%{ dc.description="#{@md.notes.description}"\n}
109
+ @description=%{<meta name="dc.description" content="#{@md.notes.description}" />\n}
110
+ end
111
+ if defined? @md.publisher \
112
+ and @md.publisher=~/\S+/ # DublinCore 5 - publisher (current copy published by)
113
+ @rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n}
114
+ @publisher=%{<meta name="dc.publisher" content="#{@md.publisher}" />\n}
115
+ end
116
+ if defined? @md.creator.contributor \
117
+ and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor
118
+ @rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n}
119
+ @contributor=%{<meta name="dc.contributor" content="#{@md.creator.contributor}" />\n}
120
+ end
121
+ if defined? @md.date.published \
122
+ and @md.date.published # DublinCore 7 - date year-mm-dd
123
+ @rdf_date=%{ dc.date="#{@md.date.published}"\n}
124
+ @date=%{<meta name="dc.date" content="#{@md.date.published}" #{@md.date_scheme} />\n}
125
+ end
126
+ if defined? @md.date.created \
127
+ and @md.date.created # DublinCore 7 - date.created year-mm-dd
128
+ @rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n}
129
+ @date_created=%{<meta name="dc.date.created" content="#{@md.date.created}" #{@md.date_created_scheme} />\n}
130
+ end
131
+ if defined? @md.date.issued \
132
+ and @md.date.issued # DublinCore 7 - date.issued year-mm-dd
133
+ @rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n}
134
+ @date_issued=%{<meta name="dc.date.issued" content="#{@md.date.issued}" #{@md.date_issued_scheme} />\n}
135
+ end
136
+ if defined? @md.date.available \
137
+ and @md.date.available # DublinCore 7 - date.available year-mm-dd
138
+ @rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n}
139
+ @date_available=%{<meta name="dc.date.available" content="#{@md.date.available}" #{@md.date_available_scheme} />\n}
140
+ end
141
+ if defined? @md.date.valid \
142
+ and @md.date.valid # DublinCore 7 - date.valid year-mm-dd
143
+ @rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n}
144
+ @date_valid=%{<meta name="dc.date.valid" content="#{@md.date.valid}" #{@md.date_valid_scheme} />\n}
145
+ end
146
+ if defined? @md.date.modified \
147
+ and @md.date.modified # DublinCore 7 - date.modified year-mm-dd
148
+ @rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n}
149
+ @date_modified=%{<meta name="dc.date.modified" content="#{@md.date.modified}" #{@md.date_modified_scheme} />\n}
150
+ end
151
+ if defined? @md.notes.coverage \
152
+ and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage
153
+ @rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n}
154
+ @coverage=%{<meta name="dc.coverage" content="#{@md.notes.coverage}" />\n}
155
+ end
156
+ if defined? @md.notes.relation \
157
+ and @md.notes.relation=~/\S+/ # DublinCore 13 - relation
158
+ @rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n}
159
+ @relation=%{<meta name="dc.relation" content="#{@md.notes.relation}" />\n}
160
+ end
161
+ if defined? @md.notes.type \
162
+ and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc)
163
+ @rdf_type=%{ dc.type="#{@md.notes.type}"\n}
164
+ @type=%{<meta name="dc.type" content="#{@md.notes.type}" />\n}
165
+ end
166
+ if defined? @md.notes.format \
167
+ and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type)
168
+ @rdf_format=%{ dc.format="#{@md.notes.format}"\n}
169
+ @format=%{<meta name="dc.format" content="#{@md.notes.format}" />\n}
170
+ end
171
+ #if defined? @md.identifier.sisupod \
172
+ #and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free)
173
+ # @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n}
174
+ # @identifier=%{<meta name="dc.identifier" content="#{@md.identifier.sisupod}" />\n}
175
+ #end
176
+ if defined? @md.original.source \
177
+ and @md.original.source=~/\S+/ # DublinCore 11 - source (document source)
178
+ @rdf_source=%{ dc.source="#{@md.original.source}"\n}
179
+ @source=%{<meta name="dc.source" content="#{@md.source}" />\n}
180
+ end
181
+ if defined? @md.original.language \
182
+ and @md.original.language=~/\S+/ # DublinCore 12 - language (English)
183
+ @rdf_language=%{ dc.language="#{@md.original.title}"\n}
184
+ @language=%{<meta name="dc.language" content="#{@md.language[:name]}" />\n}
185
+ end
186
+ if defined? @md.rights.all \
187
+ and @md.rights.all=~/\S+/ # DublinCore 15 - rights
188
+ rights=meta_content_clean(@md.rights.all)
189
+ copyright=meta_content_clean(@md.rights.copyright.all)
190
+ @rdf_rights=%{ dc.rights="#{rights}"\n}
191
+ @rights=%{<meta name="dc.rights" content="#{rights}" />\n}
192
+ end
193
+ @copyright=%{<meta name="copyright" content="#{copyright}" />\n} \
194
+ if @md.rights.copyright.all # possibly redundant see dc.rights
195
+ @owner=%{<meta name="owner" content="#{@md.owner}" />\n} if @md.owner
196
+ @keywords=%{<meta name="keywords" content="#{@md.keywords}" />\n} if @md.keywords
197
+ @index='index'
198
+ end
199
+ def meta_content_clean(content='')
200
+ content=if not content.nil?
201
+ content=content.tr('"',"'").
202
+ gsub(/&/,'&amp;')
203
+ content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content)
204
+ else content
205
+ end
206
+ end
207
+ def table_close
208
+ '</font> </td></tr></table>'
209
+ end
210
+ def toc_head
211
+ <<WOK
212
+ <html>
213
+ <head>
214
+ <title>#{@md.html_title}</title>
215
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
216
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
217
+ <rdf:Description
218
+ #{@rdfurl}
219
+ #{@rdf_title}
220
+ #{@rdf_subtitle}
221
+ #{@rdf_author}
222
+ #{@rdf_subject}
223
+ #{@rdf_description}
224
+ #{@rdf_publisher}
225
+ #{@rdf_contributor}
226
+ #{@rdf_date}
227
+ #{@rdf_date_created}
228
+ #{@rdf_date_issued}
229
+ #{@rdf_date_available}
230
+ #{@rdf_date_valid}
231
+ #{@rdf_date_modified}
232
+ #{@rdf_type}
233
+ #{@rdf_format}
234
+ #{@rdf_identifier}
235
+ #{@rdf_source}
236
+ #{@rdf_language}
237
+ #{@rdf_relation}
238
+ #{@rdf_coverage}
239
+ #{@rdf_rights}
240
+ />
241
+ </rdf:RDF>
242
+ #{@full_title}
243
+ #{@author}
244
+ #{@subject}
245
+ #{@description}
246
+ #{@publisher}
247
+ #{@contributor}
248
+ #{@date}
249
+ #{@date_created}
250
+ #{@date_issued}
251
+ #{@date_available}
252
+ #{@date_valid}
253
+ #{@date_modified}
254
+ #{@type}
255
+ #{@format}
256
+ #{@identifier}
257
+ #{@source}
258
+ #{@language}
259
+ #{@relation}
260
+ #{@coverage}
261
+ #{@rights}
262
+ #{@copyright}
263
+ #{@owner}
264
+ #{@png.ico}
265
+ #{@txt.generator}
266
+ #{@js.head}
267
+ \n</head>
268
+ #{@color.body}
269
+ #{@font.css_table_file}
270
+ <a name="top"></a>
271
+ <a name="up"></a>
272
+ <a name="start"></a>
273
+ #{@js.top}
274
+ WOK
275
+ end
276
+ end
277
+ class FormatTextObject
278
+ include SiSU_Parts_XML
279
+ attr_accessor :md,:txt,:format,:paranum,:p_num,:para_id,:headname,:font
280
+ def initialize(md,dob)
281
+ @md,@dob=md,dob
282
+ if @dob[:ocn]=~/\d+/
283
+ @paranum=/(\d+)/m.match(@dob[:ocn])[1]
284
+ @headname=''
285
+ @headname=%{<a name="h#{dob.name}"></a>} if defined? dob.name
286
+ @p_num=SiSU_XML_Format::ParagraphNumber.new(@md,dob.ocn)
287
+ end
288
+ rgx=/^[1-6-]~{1,2}/ #watch
289
+ @lnk_url=@lnk_url.gsub(rgx,'') if @lnk_url =~rgx
290
+ rgx=/~\{\d+\s+(.+?)\}~/
291
+ @lnk_url=@lnk_url.gsub(rgx,'\1') if @lnk_url =~rgx
292
+ end
293
+ def scr_endnote_body
294
+ "<endnote>#{@txt}</endnote> "
295
+ end
296
+ end
297
+ class FormatScroll < FormatTextObject
298
+ def initialize(md,dob)
299
+ super(md,dob)
300
+ end
301
+ def heading_body
302
+ %{<p class="norm">#{@p_num.name}#{@headname}#{@dob.obj} </p>} +
303
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
304
+ end
305
+ def heading_body0
306
+ %{<h1 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h1>} +
307
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
308
+ end
309
+ def heading_body1
310
+ %{<h2 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h2>} +
311
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
312
+ end
313
+ def heading_body2
314
+ %{<h3 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h3>} +
315
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
316
+ end
317
+ def heading_body3
318
+ %{<h4 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h4>} +
319
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
320
+ end
321
+ def heading_body4
322
+ %{<h5 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h5>} +
323
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
324
+ end
325
+ def heading_body5
326
+ %{<h6 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h6>} +
327
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
328
+ end
329
+ def heading_body6
330
+ %{<h7 class="norm">#{@p_num.name}#{@headname}#{@dob.obj}</h7>} +
331
+ %{<p class="paranum"><font size="1" color="#777777">&nbsp;&nbsp;#{@dob.ocn}</font></p>\n}
332
+ end
333
+ end
334
+ class ParagraphNumber
335
+ def initialize(md,ocn)
336
+ @md,@ocn=md,ocn.to_s
337
+ @ocn ||=''
338
+ end
339
+ def ocn_display
340
+ @make=SiSU_Env::ProcessingSettings.new(@md)
341
+ if @make.build.ocn?
342
+ ocn_class='ocn'
343
+ if @ocn.to_i==0
344
+ @ocn.gsub(/^(\d+|)$/,
345
+ %{<label class="#{ocn_class}"><a name="#{@ocn}">&nbsp;</a></label>})
346
+ else
347
+ @ocn.gsub(/^(\d+|)$/,
348
+ %{<label class="#{ocn_class}"><a name="#{@ocn}">\\1</a></label>})
349
+ end
350
+ else
351
+ ocn_class='ocn_off'
352
+ @ocn.gsub(/^(\d+|)$/,
353
+ %{<label class="#{ocn_class}">&nbsp;</label>})
354
+ end
355
+ end
356
+ def name
357
+ %{<a name="#{@ocn}"></a>}
358
+ end
359
+ def id #w3c? "tidy" complains about numbers as identifiers ! annoying
360
+ %{id="o#{@ocn}"}
361
+ end
362
+ def goto
363
+ %{<a href="##{@ocn}">}
364
+ end
365
+ end
366
+ class HeadInformation
367
+ include SiSU_Parts_XML
368
+ attr_reader :md,:sfx,:pdf,:rdf,:vz
369
+ def initialize(md)
370
+ @md=md
371
+ @rdf=SiSU_XML_Tags::RDF.new(md)
372
+ # DublinCore 1 - title
373
+ @stylesheet=SiSU_Style::CSS_HeadInfo.new(md).stylesheet
374
+ @seg_name_html=(SiSU_HTML::Source::Seg.new.seg_name_html || [])
375
+ @seg_name_html_tracker=(SiSU_HTML::Source::Seg.new.seg_name_html_tracker || [])
376
+ @index='index'
377
+ @metalink='#metadata'
378
+ @tocband_scroll,@tocband_segtoc=nil,nil
379
+ end
380
+ def doc_type
381
+ %{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
382
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
383
+ <html xmlns="http://www.w3.org/1999/xhtml">\n}
384
+ end
385
+ def table_close
386
+ %{ </font>
387
+ #{the_table_close}}
388
+ end
389
+ def html_close #moved
390
+ %{</body>
391
+ </html>}
392
+ end
393
+ end
394
+ class XML
395
+ end
396
+ class FormatTextObject
397
+ include SiSU_Parts_XML
398
+ attr_accessor :md,:dob,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url
399
+ def initialize(md,t_o)
400
+ @md,@t_o=md,t_o
401
+ if t_o.is_a?(Hash)
402
+ @txt =t_o[:txt] || nil
403
+ @ocn =t_o[:ocn] || nil
404
+ @ocn_display =t_o[:ocn_display] || nil
405
+ @headname =t_o[:headname] || nil
406
+ @trailer =t_o[:trailer] || nil
407
+ @endnote_part_a =t_o[:endnote_part_a] || nil
408
+ @endnote_part_b =t_o[:endnote_part_b] || nil
409
+ @lnk_url =t_o[:lnk_url] || nil
410
+ @lnk_txt =t_o[:lnk_txt] || nil
411
+ @format =t_o[:format] || nil
412
+ @target =t_o[:target] || nil #occasionally passed but not used
413
+ elsif t_o.class.inspect =~/Object/
414
+ @txt=if defined? t_o.obj; t_o.obj
415
+ else nil
416
+ end
417
+ @ocn=if defined? t_o.ocn; t_o.ocn.to_s
418
+ else nil
419
+ end
420
+ @headname=if t_o.is==:heading and defined? t_o.name; t_o.name
421
+ else nil
422
+ end
423
+ else
424
+ if @md.opt.act[:maintenance][:set]==:on
425
+ p __FILE__ << ':' << __LINE__.to_s
426
+ p t_o.class
427
+ p caller
428
+ end
429
+ end
430
+ if defined? @t_o.ocn
431
+ ocn=((@t_o.ocn.to_s =~/\d+/) ? @t_o.ocn : nil)
432
+ @p_num=ParagraphNumber.new(@md,ocn)
433
+ end
434
+ if @format and not @format.empty?
435
+ if @format=~/^\d:(\S+)/ #need more reliable marker #if @format =~ /#{Rx[:lv]}/
436
+ headname=$1 #format[/\d~(\S+)/m,1]
437
+ @headname=if headname =~/^[a-zA-Z]/; %{<a name="#{headname}" id="#{headname}"></a>} #consider: h_#{headname}
438
+ else %{<a name="h#{headname}" id="h#{headname}"></a>}
439
+ end
440
+ end
441
+ end
442
+ @dob=t_o if defined? t_o.is
443
+ end
444
+ def endnote_body
445
+ %{
446
+ <p class="endnote">
447
+ #{@txt}
448
+ </p>
449
+ }
450
+ end
451
+ def endnote_body_indent
452
+ %{
453
+ <p class="endnote_indent">
454
+ #{@txt}
455
+ </p>
456
+ }
457
+ end
458
+ def no_paranum
459
+ %{
460
+ <div class="substance">
461
+ <label class="ocn">&nbsp;</label>
462
+ <p class="norm">
463
+ #{@txt}
464
+ </p>
465
+ </div>
466
+ }
467
+ end
468
+ def para_form_css(tag,attrib) # regular paragraphs shaped here
469
+ ul=ulc=''
470
+ ul,ulc="<ul>\n ","\n </ul>" if @tag =~/li/
471
+ %{
472
+ <div class="substance">
473
+ #{@p_num.ocn_display}
474
+ #{ul}<#{tag} class="#{attrib}" #{@p_num.id}>
475
+ #{@txt}
476
+ </#{tag}>#{ulc}
477
+ </div>
478
+ }
479
+ end
480
+ def para
481
+ para_form_css('p','norm')
482
+ end
483
+ def code
484
+ para_form_css('p','code')
485
+ end
486
+ def center
487
+ para_form_css('p','center')
488
+ end
489
+ def bold
490
+ para_form_css('p','bold')
491
+ end
492
+ def bullet
493
+ para_form_css('li','bullet')
494
+ end
495
+ def format(tag,attrib)
496
+ para_form_css(tag,attrib)
497
+ end
498
+ def heading_normal(tag,attrib)
499
+ %{
500
+ <div class="substance">
501
+ #{@p_num.ocn_display}
502
+ <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name}
503
+ #{@headname}#{@txt}
504
+ </#{tag}>
505
+ </div>
506
+ }
507
+ end
508
+ def heading_body
509
+ heading_normal('p','norm')
510
+ end
511
+ def heading_body0
512
+ heading_normal('h1','norm')
513
+ end
514
+ def heading_body1
515
+ heading_normal('h1','norm')
516
+ end
517
+ def heading_body2
518
+ heading_normal('h2','norm')
519
+ end
520
+ def heading_body3
521
+ heading_normal('h3','norm')
522
+ end
523
+ def heading_body4
524
+ heading_normal('h4','norm')
525
+ end
526
+ def heading_body5
527
+ heading_normal('h5','norm')
528
+ end
529
+ def heading_body6
530
+ heading_normal('h6','norm')
531
+ end
532
+ def heading_body7
533
+ heading_normal('h7','norm')
534
+ end
535
+ def title_header(tag,attrib)
536
+ %{
537
+ <div class="content">
538
+ <#{tag} class="#{attrib}">
539
+ #{@txt}
540
+ </#{tag}>
541
+ </div>
542
+ }
543
+ end
544
+ def title_header1
545
+ title_header('h1','tiny')
546
+ end
547
+ def title_header2
548
+ title_header('h2','tiny')
549
+ end
550
+ def title_header3
551
+ title_header('h3','tiny')
552
+ end
553
+ def title_header4
554
+ ''
555
+ end
556
+ def title_header4_old
557
+ %{
558
+ <div class="substance">
559
+ <label class="ocn">&nbsp;</label>
560
+ <h4 class="banner">
561
+ #{@txt}
562
+ </h4>
563
+ </div>
564
+ }
565
+ end
566
+ def dl #check :trailer
567
+ "<dl><b>#{@txt}</b> #{@trailer}</dl>"
568
+ end
569
+ def table_css_end #<!TZ!>
570
+ '</table>
571
+ </p>
572
+ </div>'
573
+ end
574
+ def gsub_body
575
+ #fix
576
+ @txt=case @txt
577
+ when /^\s*\((i+|iv|v|vi+|ix|x|xi+)\)/
578
+ @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'<b>(\1)</b>').
579
+ gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((i+|iv|v|vi+|ix|x|xi+)\)/,'\1<b>(\2)</b>')
580
+ when /^\s*\(?(\d|[a-z])+\)/
581
+ @txt.gsub(/^\((\d+|[a-z])+\)/,'<b>(\1)</b>').
582
+ gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((\d+|[a-z])+\)/,'\1<b>(\2)</b>')
583
+ when /^\s*\d{1,3}\.\s/
584
+ @txt.gsub(/^\s*(\d+\.)/,'<b>\1</b>')
585
+ when /^\s*[A-Z]\.\s/
586
+ @txt.gsub(/^\s*([A-Z]\.)/,'<b>\1</b>')
587
+ else @txt
588
+ end
589
+ end
590
+ def bold_para
591
+ %{#{the_margin.txt_0}
592
+ <p class="bold">
593
+ #{@txt}
594
+ </p>
595
+ #{the_margin.num_css}
596
+ &nbsp;&nbsp;&nbsp;
597
+ #{the_table_close}}
598
+ end
599
+ def bold_header
600
+ @txt=@txt.gsub(/[1-9]~(\S+)/,'<a name="\1"></a>').
601
+ gsub(/[1-9]~/,'')
602
+ %{<p class="bold">
603
+ #{@txt}
604
+ </p>
605
+ #{the_margin.num_css}
606
+ &nbsp;&nbsp;&nbsp;
607
+ #{the_table_close}}
608
+ end
609
+ def toc_head_copy_at
610
+ %{<p class="center">#{@txt}</p>\n}
611
+ end
612
+ def center
613
+ %{<p class="center">#{@txt}</p>\n}
614
+ end
615
+ def bold
616
+ %{<p class="bold">#{@txt}</p>\n}
617
+ end
618
+ def center_bold
619
+ %{<p class="centerbold">#{@txt}</p>\n}
620
+ end
621
+ end
622
+ class FormatScroll < FormatTextObject
623
+ include SiSU_Parts_XML
624
+ def initialize(md,txt)
625
+ super(md,txt)
626
+ end
627
+ end
628
+ class FormatSeg < FormatTextObject
629
+ def initialize(md,txt)
630
+ super(md,txt)
631
+ end
632
+ def navigation_toc_lev1_advert
633
+ %{#{@banner.home_button}\n
634
+ <center>
635
+ #{@txt}
636
+ #{@two}
637
+ </a></center><p />}
638
+ end
639
+ def navigation_toc_lev1
640
+ %{#{@banner.nav_toc}}
641
+ end
642
+ def navigation_toc_lev2 #change bold use css
643
+ %{<p />
644
+ <table summary="navigation segment level 2">
645
+ <tr><td width ="20">
646
+ </td>
647
+ <td>
648
+ <font size="3" #{the_font.set_face}>
649
+ <b>#{@txt}</b>
650
+ </font>
651
+ </p>
652
+ #{the_table_close}}
653
+ end
654
+ def navigation_toc_lev3 #change bold use css
655
+ %{<p />
656
+ <table summary="navigation segment level 3">
657
+ <tr><td width ="20">
658
+ </td>
659
+ <td>
660
+ <font size="3" #{the_font.set_face}>
661
+ <b>#{@txt}</b>
662
+ </font>
663
+ </p>
664
+ #{the_table_close}}
665
+ end
666
+ def navigation_toc_lev4
667
+ %{<table summary="navigation segment level 4">
668
+ <tr><td width ="80">
669
+ </td>
670
+ <td>
671
+ <p>
672
+ #{@txt}
673
+ </p>
674
+ #{the_table_close}}
675
+ end
676
+ def navigation_toc_lev5
677
+ end
678
+ def navigation_toc_lev6
679
+ end
680
+ def endnote_seg_body(fn='') #FIX #url construction keep within single line... BUG WATCH 200408
681
+ fn='doc' if fn.empty? #you may wish to reconsider, sends to 'doc' where no segment info # Sfx[:html] or Sfx[:xhtml] ?
682
+ %{
683
+ <p class="endnote">
684
+ #{@endnote_part_a}#{fn}#{@md.lang_code_insert}#{Sfx[:html]}#{@endnote_part_b}
685
+ </p>
686
+ }
687
+ end
688
+ def subtoc_lev(tag,attrib)
689
+ txt=if @txt \
690
+ and @txt =~/<\/?i>|<a\s+name="\S+?">/mi
691
+ @txt.gsub(/<\/?i>|<a\s+name="\S+?">/mi,'') #removes name markers from subtoc, go directly to substantive text
692
+ else @txt
693
+ end
694
+ note=''
695
+ if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}\s*)/m
696
+ note=$1
697
+ note=note.gsub(/[\n\s]+/m,' ')
698
+ txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ').
699
+ gsub(/<a[\n\s]+name="-\d+"[\n\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
700
+ end
701
+ %{<#{tag} class="#{attrib}">
702
+ <a href="##{@ocn}"><i>#{txt}</i></a> #{note}
703
+ </#{tag}>}
704
+ end
705
+ def subtoc_lev5
706
+ subtoc_lev('h5','subtoc') if @txt
707
+ end
708
+ def subtoc_lev6
709
+ subtoc_lev('h6','subtoc') if @txt
710
+ end
711
+ def subtoc_lev7
712
+ subtoc_lev('h7','subtoc') if @txt
713
+ end
714
+ #% para sisu
715
+ def header_sub(tag,attrib)
716
+ @txt=@txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
717
+ %{
718
+ <div class="substance">
719
+ #{@p_num.ocn_display}
720
+ <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} #{@headname}
721
+ #{@txt}
722
+ </#{tag}>
723
+ </div>
724
+ }
725
+ end
726
+ def header4
727
+ %{
728
+ <div class="substance">
729
+ #{@p_num.ocn_display}
730
+ <h1 class="norm" #{@p_num.id}>#{@p_num.name}
731
+ #{@t_o[:format]}
732
+ #{@txt}
733
+ </h1>
734
+ </div>
735
+ }
736
+ end
737
+ def header5
738
+ header_sub('p','bold')
739
+ end
740
+ def header6
741
+ header_sub('p','bold')
742
+ end
743
+ def header7
744
+ header_sub('p','bold')
745
+ end
746
+ def navigation_header4
747
+ %{<table summary="navigation segment header 4" width=100% bgcolor="#08163f" border="0">
748
+ <tr><td align="center">
749
+ <p class="bold">
750
+ #{@txt}
751
+ </p>
752
+ #{the_table_close}}
753
+ end
754
+ def navigation_header5
755
+ %{<p class="bold">
756
+ #{@txt}
757
+ </p>}
758
+ end
759
+ def navigation_header6
760
+ %{<p class="bold">
761
+ #{@txt}
762
+ </p>}
763
+ end
764
+ def navigation_header7
765
+ %{<p class="bold">
766
+ #{@txt}
767
+ </p>}
768
+ end
769
+ def navigation_center
770
+ "<center>#{@txt}</center>"
771
+ end
772
+ end
773
+ class FormatToc < FormatTextObject
774
+ def initialize(md,txt)
775
+ super(md,txt)
776
+ end
777
+ def links_guide
778
+ %{ <li class="doc">
779
+ <a href="#{@lnk_url}" target="_top">
780
+ #{@lnk_txt}
781
+ </a>
782
+ </li>
783
+ }
784
+ end
785
+ def lev(tag,attrib)
786
+ if @txt
787
+ %{<#{tag} class="#{attrib}">
788
+ #{@txt}
789
+ </#{tag}>
790
+ }
791
+ else ''
792
+ end
793
+ end
794
+ def lev1
795
+ lev('h1','toc')
796
+ end
797
+ def lev2
798
+ lev('h2','toc')
799
+ end
800
+ def lev3
801
+ lev('h3','toc')
802
+ end
803
+ def lev4
804
+ lev('h4','toc')
805
+ end
806
+ def lev5
807
+ lev('h5','toc')
808
+ end
809
+ def lev6
810
+ lev('h6','toc')
811
+ end
812
+ def lev7
813
+ lev('h7','toc')
814
+ #lev('b','toc')
815
+ end
816
+ def lev0 #docinfo
817
+ lev('h0','toc')
818
+ end
819
+ def mini_lev1
820
+ lev('h1','minitoc')
821
+ end
822
+ def mini_lev2
823
+ lev('h2','minitoc')
824
+ end
825
+ def mini_lev3
826
+ lev('h3','minitoc')
827
+ end
828
+ def mini_lev4
829
+ lev('h4','minitoc')
830
+ end
831
+ def mini_lev5
832
+ lev('h5','minitoc')
833
+ end
834
+ def mini_lev6
835
+ lev('h6','minitoc')
836
+ end
837
+ def mini_lev7
838
+ lev('h7','minitoc')
839
+ end
840
+ def mini_lev0 #docinfo
841
+ lev('h0','minitoc')
842
+ end
843
+ def mini_tail
844
+ %{
845
+ <h4 class="minitoc">
846
+ <a href="sisu_manifest.html">Manifest (alternative outputs)</a>
847
+ </h4>
848
+ }
849
+ end
850
+ def mini_concord_tail
851
+ %{
852
+ <h4 class="minitoc">
853
+ <a href="concordance.html">Concordance (wordlist)</a>
854
+ </h4>
855
+ <h4 class="minitoc">
856
+ <a href="sisu_manifest.html">Manifest (alternative outputs)</a>
857
+ </h4>
858
+ }
859
+ end
860
+ end
861
+ class XML
862
+ end
863
+ end
864
+ __END__
865
+ ** Notes: tidy -xml index.xml >> index.tidy