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,2269 @@
1
+ # encoding: utf-8
2
+ =begin
3
+
4
+ * Name: SiSU
5
+
6
+ ** Description: documents, structuring, processing, publishing, search
7
+ *** document abstraction
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/ao_doc_str.rb;hb=HEAD>
55
+
56
+ =end
57
+ module SiSU_AO_DocumentStructureExtract
58
+ require_relative 'ao_persist' # ao_persist.rb
59
+ class Instantiate < SiSU_Param::Parameters::Instructions
60
+ def initialize
61
+ @@counter=@@column=@@columns=0
62
+ @@line_mode=''
63
+ end
64
+ end
65
+ class Build
66
+ def initialize(md,data)
67
+ @md,@data=md,data
68
+ SiSU_AO_DocumentStructureExtract::Instantiate.new
69
+ @pb=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page])
70
+ @pbn=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new])
71
+ @pbl=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line])
72
+ @per=SiSU_AO_Persist::PersistDocStructExt.new
73
+ end
74
+ def ln_get(lv)
75
+ case lv
76
+ when /A/ then 0
77
+ when /B/ then 1
78
+ when /C/ then 2
79
+ when /D/ then 3
80
+ when /1/ then 4
81
+ when /2/ then 5
82
+ when /3/ then 6
83
+ when /4/ then 7
84
+ when /5/ then 8
85
+ when /6/ then 9
86
+ end
87
+ end
88
+ def image_test(str)
89
+ str=~/\{\s*\S+?\.png.+?\}https?:\/\/\S+/ \
90
+ ? true
91
+ : false
92
+ end
93
+ def bullet_test(str)
94
+ (str=~/\*/) \
95
+ ? true
96
+ : false
97
+ end
98
+ def quotes?
99
+ @per.quote==:open \
100
+ ? true
101
+ : false
102
+ end
103
+ def hang_and_indent_test(str)
104
+ hang_indent=if str=~/^_([1-9])[^_]/
105
+ [$1,$1]
106
+ elsif str=~/^__([1-9])/
107
+ [0,$1]
108
+ elsif str=~/^_([0-9])_([0-9])/
109
+ [$1,$2]
110
+ else
111
+ [0,0]
112
+ end
113
+ hang,indent=hang_indent[0],hang_indent[1]
114
+ [hang,indent]
115
+ end
116
+ def hang_and_indent_def_test(str1,str2)
117
+ hang_indent=if str1=~/^_([1-9])[^_]/
118
+ [$1,$1]
119
+ elsif str1=~/^__([1-9])/
120
+ [0,$1]
121
+ elsif str1=~/^_([0-9])_([0-9])/
122
+ [$1,$2]
123
+ else
124
+ [0,0]
125
+ end
126
+ obj=if str2 =~/^(.+?)\s+\\\\(?:\s+|\n)/
127
+ str2.gsub(/^(.+?)(\s+\\\\(?:\s+|\n))/,
128
+ "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2")
129
+ else
130
+ str2.gsub(/^(.+?)\n/,
131
+ "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\n")
132
+ end
133
+ hang,indent=hang_indent[0],hang_indent[1]
134
+ [
135
+ hang,
136
+ indent,
137
+ obj,
138
+ ]
139
+ end
140
+ def endnote_test?(str)
141
+ (str=~/~\{.+?\}~|~\[.+?\]~/) \
142
+ ? true
143
+ : false
144
+ end
145
+ def extract_tags(str,nametag=nil)
146
+ tags=[]
147
+ if str.nil?
148
+ else
149
+ if str =~/(?:^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/
150
+ str=str.gsub(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i,
151
+ "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}").
152
+ gsub(/ [ ]+/i,' ')
153
+ tags=str.scan(/#{Mx[:tag_o]}(\S+?)#{Mx[:tag_c]}/).flatten.uniq
154
+ str=str.gsub(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks?
155
+ end
156
+ tags=nametag ? (tags << nametag) : tags
157
+ tags.each do |t|
158
+ t.gsub!(/[^a-z0-9._-]/,'')
159
+ end
160
+ end
161
+ [
162
+ str,
163
+ tags,
164
+ ]
165
+ end
166
+ def rgx_idx_ocn_seg
167
+ @rgx_idx_ocn_seg=/(.+?)\s*[+](\d+)/
168
+ end
169
+ def construct_idx_array_and_hash(idxraw)
170
+ idx_array_raw=idxraw.scan(/[^;]+/)
171
+ idx_hash,idx_array,idx_lst={},[],[]
172
+ idx_array_raw.each do |idx|
173
+ idx=idx.strip
174
+ idx_lst=case idx
175
+ when /\S+?\s*:/
176
+ idx_couplet_tmp=[]
177
+ idx_couplet=idx.scan(/\s*[^:]+\s*/)
178
+ if idx_couplet[1] =~/[|]/
179
+ idx_couplet_tmp <<
180
+ idx_couplet[0] <<
181
+ idx_couplet[1].scan(/\s*[^|]+\s*/)
182
+ else
183
+ idx_couplet_tmp <<
184
+ idx_couplet[0] <<
185
+ [idx_couplet[1]]
186
+ end
187
+ idx_couplet=idx_couplet_tmp
188
+ else [idx]
189
+ end
190
+ term_nodes=[]
191
+ idx_lst.each do |term_node|
192
+ case term_node
193
+ when String
194
+ term_node=
195
+ term_node[0].chr.capitalize +
196
+ term_node[1,term_node.length]
197
+ term_node=(term_node =~/.+?[+]\d+/) \
198
+ ? term_node
199
+ : (term_node + '+0')
200
+ term_nodes << term_node
201
+ use,plus=rgx_idx_ocn_seg.match(term_node)[1,2]
202
+ @use=use.strip
203
+ unless idx_hash[@use] \
204
+ and defined? idx_hash[@use]
205
+ idx_hash[@use]=
206
+ { sub: [], plus: plus }
207
+ end
208
+ when Array
209
+ subterm_nodes=[]
210
+ term_node.each do |subterm_node|
211
+ subterm_node=(subterm_node =~/.+?[+]\d+/) \
212
+ ? subterm_node
213
+ : (subterm_node + '+0')
214
+ subterm_nodes << subterm_node
215
+ sub,sub_plus=rgx_idx_ocn_seg.match(subterm_node)[1,2]
216
+ unless idx_hash[@use] \
217
+ and defined? idx_hash[@use]
218
+ idx_hash[@use]=
219
+ { sub: [], plus: 0 }
220
+ end
221
+ idx_hash[@use][:sub] <<
222
+ { sub.strip => { plus: sub_plus } }
223
+ end
224
+ term_nodes << subterm_nodes
225
+ end
226
+ end
227
+ idx_array << term_nodes
228
+ end
229
+ {
230
+ hash: idx_hash,
231
+ array: idx_array,
232
+ }
233
+ end
234
+ def extract_structure_loop(data,tuned_file)
235
+ data.each do |t_o|
236
+ if t_o =~/^--([+~-])[#]$/
237
+ h=case $1
238
+ when /[+]/
239
+ @per.ocn=:on
240
+ {
241
+ flag: :ocn_on,
242
+ }
243
+ when /[~]/
244
+ @per.ocn=:ocn_off_headings_keep
245
+ {
246
+ flag: :ocn_off,
247
+ mod: :headings_keep,
248
+ }
249
+ when /[-]/ #of particular relevance with level 1~ which is required to precede substantive text & used e.g. in html segmented text
250
+ @per.ocn=:ocn_off_headings_dummy_lev1
251
+ {
252
+ flag: :ocn_off,
253
+ mod: :headings_exclude,
254
+ }
255
+ else
256
+ @per.ocn=:on
257
+ {
258
+ flag: :ocn_on,
259
+ }
260
+ end
261
+ t_o=SiSU_AO_DocumentStructure::ObjectFlag.new.flag_ocn(h)
262
+ next
263
+ end
264
+ if t_o =~/^:[~](#{SiSU_is.language_list_regex?}|-)$/ # work with for identifying language of objects
265
+ lng=$1
266
+ h=case lng
267
+ when /(?:#{SiSU_is.language_list_regex?})/
268
+ @per.lng=:on
269
+ @per.lng_is=lng.to_sym
270
+ {
271
+ flag: :lng_on,
272
+ act: lng.to_sym,
273
+ }
274
+ else # ^:~-
275
+ if @per.lng==:on
276
+ @per.lng=:off
277
+ @per.lng_is=:doc_default
278
+ {
279
+ flag: :lng_off,
280
+ act: :doc_default,
281
+ }
282
+ end
283
+ end
284
+ t_o=SiSU_AO_DocumentStructure::ObjectFlag.new.flag_lng(h)
285
+ next
286
+ end
287
+ t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @per.code==:off
288
+ unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any
289
+ idx=if t_o=~/^=\{\s*(.+)\s*\}\s*$\Z/m
290
+ m=$1
291
+ m=m.split(/[ ]*\n/).join(' ').
292
+ gsub(/\s+([|:;])\s+/,'\1').
293
+ gsub(/\s+([+]\d+)\s+/,'\1')
294
+ t_o=t_o.gsub(/\n=\{.+?\}\s*$/m,'')
295
+ idx_array_and_hash=construct_idx_array_and_hash(m)
296
+ idx_array_and_hash[:hash]
297
+ else nil
298
+ end
299
+ end
300
+ if t_o !~/^(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \
301
+ and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$|^`:quote_(?:open|close)`/ \
302
+ and @per.code==:off \
303
+ and @per.poem==:off \
304
+ and @per.group==:off \
305
+ and @per.block==:off \
306
+ and @per.alt==:off \
307
+ and @per.box==:off \
308
+ and @per.table==:off
309
+ t_o=case t_o
310
+ when /^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ #metadata, header
311
+ if t_o=~/^#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*(.+)/m
312
+ tag,obj=$1,$2
313
+ @metadata[tag]=obj
314
+ end
315
+ t_o=nil
316
+ when /^%+\s/ #comment
317
+ t_o=if t_o=~/^%+\s+(.+)/
318
+ h={ obj: $1 }
319
+ SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
320
+ else nil
321
+ end
322
+ when /^:?([A-D1-6])\~/ #heading / lv
323
+ lv=$1
324
+ ln=ln_get(lv)
325
+ t_o=if t_o=~/^:?[A-D1-6]\~\s+(.+)/m
326
+ obj=$1
327
+ note=endnote_test?(obj)
328
+ obj,tags=extract_tags(obj)
329
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
330
+ or @per.ocn==:ocn_off_headings_keep
331
+ unless obj =~ /[~-][#]\s*$/
332
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
333
+ and t_o =~/^1\~\S*\s+/m
334
+ obj << ' -#'
335
+ elsif @per.ocn==:ocn_off_headings_dummy_lev1 \
336
+ or @per.ocn==:ocn_off_headings_keep
337
+ obj << ' ~#'
338
+ end
339
+ end
340
+ end
341
+ h={
342
+ lv: lv,
343
+ ln: ln,
344
+ obj: obj,
345
+ idx: idx,
346
+ tags: tags,
347
+ }
348
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h)
349
+ elsif t_o=~/^:?[A-D1-6]\~(\S+?)-\s+(.+)/m
350
+ name,obj=$1,$2
351
+ note=endnote_test?(obj)
352
+ obj,tags=extract_tags(obj)
353
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
354
+ or @per.ocn==:ocn_off_headings_keep
355
+ unless obj =~ /[~-][#]\s*$/
356
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
357
+ and t_o =~/^1\~\S*\s+/m
358
+ obj << ' -#'
359
+ elsif @per.ocn==:ocn_off_headings_dummy_lev1 \
360
+ or @per.ocn==:ocn_off_headings_keep
361
+ obj << ' ~#'
362
+ end
363
+ end
364
+ end
365
+ h={
366
+ lv: lv,
367
+ name: name,
368
+ obj: obj,
369
+ idx: idx,
370
+ autonum_: false,
371
+ tags: tags,
372
+ }
373
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h)
374
+ elsif t_o=~/^:?[A-D1-6]\~(\S+)\s+(.+)/m
375
+ name,obj=$1,$2
376
+ note=endnote_test?(obj)
377
+ obj,tags=extract_tags(obj,name)
378
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
379
+ or @per.ocn==:ocn_off_headings_keep
380
+ unless obj =~ /[~-][#]\s*$/
381
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
382
+ and t_o =~/^1\~\S*\s+/m
383
+ obj << ' -#'
384
+ elsif @per.ocn==:ocn_off_headings_dummy_lev1 \
385
+ or @per.ocn==:ocn_off_headings_keep
386
+ obj << ' ~#'
387
+ end
388
+ end
389
+ end
390
+ h={
391
+ lv: lv,
392
+ name: name,
393
+ obj: obj,
394
+ idx: idx,
395
+ tags: tags,
396
+ }
397
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h)
398
+ else nil
399
+ end
400
+ when /^_(?:[1-9]!?|[1-9]?\*)\s+/ #indented and/or bullet paragraph
401
+ t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9]!?)\s+)(.+)/m
402
+ tst,obj=$1,$2
403
+ if t_o=~/^_[1-9]!\s+.+/m
404
+ hang,indent,obj=hang_and_indent_def_test(tst,obj)
405
+ else
406
+ hang,indent=hang_and_indent_test(tst)
407
+ end
408
+ bullet=bullet_test(tst)
409
+ image=image_test(obj)
410
+ note=endnote_test?(obj)
411
+ obj,tags=extract_tags(obj)
412
+ unless obj=~/\A\s*\Z/m
413
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
414
+ or @per.ocn==:ocn_off_headings_keep
415
+ unless obj =~ /[~-][#]\s*$/
416
+ obj << ' ~#'
417
+ end
418
+ end
419
+ h={
420
+ bullet_: bullet,
421
+ hang: hang,
422
+ indent: indent,
423
+ obj: obj,
424
+ idx: idx,
425
+ note_: note,
426
+ image_: image,
427
+ tags: tags,
428
+ quote: quotes?,
429
+ }
430
+ SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
431
+ end
432
+ else nil
433
+ end
434
+ when /^_[0-9]?_[0-9]!?\s+/ #hanging indent paragraph
435
+ t_o=if t_o=~/^(_[0-9]?_[0-9]!?\s+)(.+)/m
436
+ tst,obj=$1,$2
437
+ if t_o=~/^_[0-9]?_[0-9]!\s+.+/m
438
+ hang,indent,obj=hang_and_indent_def_test(tst,obj)
439
+ else
440
+ hang,indent=hang_and_indent_test(tst)
441
+ end
442
+ image=image_test(obj)
443
+ note=endnote_test?(obj)
444
+ obj,tags=extract_tags(obj)
445
+ unless obj=~/\A\s*\Z/m
446
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
447
+ or @per.ocn==:ocn_off_headings_keep
448
+ unless obj =~ /[~-][#]\s*$/
449
+ obj << ' ~#'
450
+ end
451
+ end
452
+ h={
453
+ hang: hang,
454
+ indent: indent,
455
+ obj: obj,
456
+ idx: idx,
457
+ note_: note,
458
+ image_: image,
459
+ tags: tags,
460
+ quote: quotes?,
461
+ }
462
+ SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
463
+ end
464
+ else nil
465
+ end
466
+ when /^<(?:br)?:(?:pa?r|o(?:bj|---)?)>\s*$/ #[br:par] #[br:obj]
467
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_obj])
468
+ when /^(?:-\\\\-|<:pb>)\s*$/ #[br:pg]
469
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page],:markup)
470
+ when /^(?:=\\\\=|<:pn>)\s*$/ #[br:pgn]
471
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new],:markup)
472
+ when /^-\.\.-\s*$/ #[br:pgl]
473
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line],:markup)
474
+ else #paragraph
475
+ image=image_test(t_o)
476
+ note=endnote_test?(t_o)
477
+ obj,tags=extract_tags(t_o)
478
+ if @per.ocn==:ocn_off_headings_dummy_lev1 \
479
+ or @per.ocn==:ocn_off_headings_keep
480
+ unless obj =~ /[~-][#]\s*$/
481
+ obj << ' ~#'
482
+ end
483
+ end
484
+ unless obj=~/\A\s*\Z/m
485
+ h={
486
+ bullet_: false,
487
+ indent: 0,
488
+ hang: 0,
489
+ obj: obj,
490
+ idx: idx,
491
+ note_: note,
492
+ image_: image,
493
+ tags: tags,
494
+ quote: quotes?,
495
+ }
496
+ t_o=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
497
+ end
498
+ t_o=SiSU_AO_DocumentStructureExtract::Structure.new(@md).structure_markup(t_o) #must happen earlier, node info etc. require
499
+ end
500
+ elsif @per.code==:off
501
+ if t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|```[ ]+code(?:\.[a-z][0-9a-z_]+)?)/
502
+ @per.code=case t_o
503
+ when /^code(?:\.[a-z][0-9a-z_]+)?\{/ then :curls
504
+ when /^```[ ]+code/ then :tics
505
+ else @per.code #error
506
+ end
507
+ @per.lngsyn=if t_o =~/^(?:code\.[a-z][0-9a-z_]+\{|```[ ]+code\.[a-z_]+)/
508
+ case t_o
509
+ when /^code\.([a-z][0-9a-z_]+)\{/
510
+ :"#{$1}"
511
+ when /^```[ ]+code\.([a-z][0-9a-z_]+)/
512
+ :"#{$1}"
513
+ else :txt
514
+ end
515
+ else :txt
516
+ end
517
+ @@counter=1
518
+ @codeblock_numbered=
519
+ (t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{#|```[ ]+code(?:\.[a-z][0-9a-z_]+)?\s[#])/) \
520
+ ? true
521
+ : false
522
+ @num_id[:code_block] +=1
523
+ h={
524
+ is_for: :code,
525
+ obj: '',
526
+ sym: :code_block_open,
527
+ num: @num_id[:code_block],
528
+ syntax: @per.lngsyn,
529
+ }
530
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
531
+ elsif t_o =~/^(?:poem\{|```[ ]+poem)/
532
+ @per.poem=case t_o
533
+ when /^poem\{/ then :curls
534
+ when /^```[ ]+poem/ then :tics
535
+ else @per.poem #error
536
+ end
537
+ @num_id[:poem] +=1
538
+ h={
539
+ is_for: :poem,
540
+ obj: '',
541
+ sym: :poem_open,
542
+ num: @num_id[:poem],
543
+ }
544
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
545
+ tuned_file << t_o
546
+ elsif t_o =~/^(?:box(?:\.[a-z_]+)?\{|```[ ]+box(?:\.[a-z_]+)?)/
547
+ @per.box=case t_o
548
+ when /^box\{/ then :curls
549
+ when /^```[ ]+box/ then :tics
550
+ else @per.box #error
551
+ end
552
+ @num_id[:box] +=1
553
+ h={
554
+ is_for: :box,
555
+ obj: '',
556
+ sym: :box_open,
557
+ num: @num_id[:box],
558
+ }
559
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
560
+ tuned_file << t_o
561
+ elsif t_o =~/^(?:group\{|```[ ]+group)/
562
+ @per.group=case t_o
563
+ when /^group\{/ then :curls
564
+ when /^```[ ]+group/ then :tics
565
+ else @per.group #error
566
+ end
567
+ @num_id[:group] +=1
568
+ h={
569
+ is_for: :group,
570
+ obj: '',
571
+ sym: :group_open,
572
+ num: @num_id[:group],
573
+ }
574
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
575
+ tuned_file << t_o
576
+ elsif t_o =~/^(?:block\{|```[ ]+block)/
577
+ @per.block=case t_o
578
+ when /^block\{/ then :curls
579
+ when /^```[ ]+block/ then :tics
580
+ else @per.block #error
581
+ end
582
+ @num_id[:block] +=1
583
+ h={
584
+ is_for: :block,
585
+ obj: '',
586
+ sym: :block_open,
587
+ num: @num_id[:block],
588
+ }
589
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
590
+ tuned_file << t_o
591
+ elsif t_o =~/^(?:alt\{|```[ ]+alt)/
592
+ @per.alt=case t_o
593
+ when /^alt\{/ then :curls
594
+ when /^```[ ]+alt/ then :tics
595
+ else @per.alt #error
596
+ end
597
+ @num_id[:alt] +=1
598
+ h={
599
+ is_for: :alt,
600
+ obj: '',
601
+ sym: :alt_open,
602
+ num: @num_id[:alt],
603
+ }
604
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
605
+ tuned_file << t_o
606
+ elsif t_o =~/^`:quote_open`/
607
+ @per.quote=:open
608
+ @num_id[:quote] +=1
609
+ h={
610
+ is_for: :quote,
611
+ obj: '',
612
+ sym: :quote_open,
613
+ num: @num_id[:quote],
614
+ }
615
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
616
+ #tuned_file << t_o #% find second source, entered twice, should be once so closed off here
617
+ elsif t_o =~/^(?:table\{|```[ ]+table|\{table)[ ~]/
618
+ @num_id[:table] +=1
619
+ h={
620
+ is_for: :table,
621
+ obj: '',
622
+ sym: :table_open,
623
+ num: @num_id[:table],
624
+ }
625
+ ins_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
626
+ tuned_file << ins_o
627
+ if t_o=~/^table\{(?:~h)?\s+/
628
+ @per.table=:curls
629
+ @rows=''
630
+ case t_o
631
+ when /table\{~h\s+c(\d+);\s+(.+)/
632
+ cols=$1
633
+ col=$2.scan(/\d+/)
634
+ heading=true
635
+ when /table\{\s+c(\d+);\s+(.+)/
636
+ cols=$1
637
+ col=$2.scan(/\d+/)
638
+ heading=false
639
+ end
640
+ @h={
641
+ head_: heading,
642
+ cols: cols,
643
+ widths: col,
644
+ idx: idx,
645
+ }
646
+ elsif t_o=~/^```[ ]+table(?:~h)?\s+c\d+/
647
+ @per.table=:tics
648
+ @rows=''
649
+ case t_o
650
+ when /^```[ ]+table~h\s+c(\d+);\s+(.+)/
651
+ cols=$1
652
+ col=$2.scan(/\d+/)
653
+ heading=true
654
+ when /^```[ ]+table\s+c(\d+);\s+(.+)/
655
+ cols=$1
656
+ col=$2.scan(/\d+/)
657
+ heading=false
658
+ end
659
+ @h={
660
+ head_: heading,
661
+ cols: cols,
662
+ widths: col,
663
+ idx: idx,
664
+ }
665
+ elsif t_o=~/^\{table(?:~h)?(?:\s+\d+;?)?\}\n.+\Z/m
666
+ m1,m2,hd=nil,nil,nil
667
+ tbl=/^\{table(?:~h)?(?:\s+\d+;?)?\}\n(.+)\Z/m.match(t_o)[1]
668
+ hd=((t_o =~/^\{table~h/) ? true : false)
669
+ tbl,tags=extract_tags(tbl)
670
+ rws=tbl.split(/\n/)
671
+ rows=''
672
+ cols=nil
673
+ rws.each do |r|
674
+ cols=(cols ? cols : (r.scan('|').length) +1)
675
+ r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
676
+ rows += r + Mx[:tc_c]
677
+ end
678
+ col=[]
679
+ if t_o =~/^\{table(?:~h)?\s+(\d+);?\}/ #width of col 1 given as %, usually when wider than rest that are even
680
+ c1=$1.to_i
681
+ width=(100 - c1)/(cols - 1)
682
+ col=[ c1 ]
683
+ (cols - 1).times { col << width }
684
+ else #all columns of equal width
685
+ width=100.00/cols
686
+ cols.times { col << width }
687
+ end
688
+ h={
689
+ head_: hd,
690
+ cols: cols,
691
+ widths: col,
692
+ obj: rows,
693
+ idx: idx,
694
+ tags: tags,
695
+ num: @num_id[:table],
696
+ }
697
+ t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) \
698
+ unless h.nil?
699
+ tuned_file << t_o
700
+ h={
701
+ is_for: :table,
702
+ obj: '',
703
+ sym: :table_close,
704
+ num: @num_id[:table],
705
+ }
706
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
707
+ t_o
708
+ elsif t_o=~/^```[ ]+table(?:~h)?\s+/
709
+ m1,m2,hd=nil,nil,nil
710
+ h=case t_o
711
+ when /^```[ ]+table~h\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one
712
+ m1,tbl,hd=$1,$2,true
713
+ when /^```[ ]+table\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one
714
+ m1,tbl,hd=$1,$2,false
715
+ else nil
716
+ end
717
+ tbl,tags=extract_tags(tbl)
718
+ col=m1.scan(/\d+/)
719
+ rws=tbl.split(/\n/)
720
+ rows=''
721
+ rws.each do |r|
722
+ r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
723
+ rows += r + Mx[:tc_c]
724
+ end
725
+ h={
726
+ head_: hd,
727
+ cols: col.length,
728
+ widths: col,
729
+ obj: rows,
730
+ idx: idx,
731
+ tags: tags,
732
+ num: @num_id[:table],
733
+ }
734
+ t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) \
735
+ unless h.nil?
736
+ tuned_file << t_o
737
+ h={
738
+ is_for: :table,
739
+ obj: '',
740
+ sym: :table_close,
741
+ num: @num_id[:table],
742
+ }
743
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
744
+ t_o
745
+ elsif t_o=~/^\{table(?:~h)?\s+/
746
+ m1,m2,hd=nil,nil,nil
747
+ h=case t_o
748
+ when /\{table~h\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one
749
+ m1,tbl,hd=$1,$2,true
750
+ when /\{table\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one
751
+ m1,tbl,hd=$1,$2,false
752
+ else nil
753
+ end
754
+ tbl,tags=extract_tags(tbl)
755
+ col=m1.scan(/\d+/)
756
+ rws=tbl.split(/\n/)
757
+ rows=''
758
+ rws.each do |r|
759
+ r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
760
+ rows += r + Mx[:tc_c]
761
+ end
762
+ h={
763
+ head_: hd,
764
+ cols: col.length,
765
+ widths: col,
766
+ obj: rows,
767
+ idx: idx,
768
+ tags: tags,
769
+ num: @num_id[:table],
770
+ }
771
+ t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) \
772
+ unless h.nil?
773
+ tuned_file << t_o
774
+ h={
775
+ is_for: :table,
776
+ obj: '',
777
+ sym: :table_close,
778
+ num: @num_id[:table],
779
+ }
780
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
781
+ t_o
782
+ end
783
+ end
784
+ t_o
785
+ end
786
+ if @per.table==:curls or @per.table==:tics
787
+ if (@per.table==:curls \
788
+ and t_o =~/^\}table/) \
789
+ or (@per.table==:tics \
790
+ and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
791
+ @per.table=:off
792
+ headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx]
793
+ @h={
794
+ head_: headings,
795
+ cols: columns,
796
+ widths: widths,
797
+ idx: idx,
798
+ obj: @rows,
799
+ }
800
+ t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(@h)
801
+ tuned_file << t_o
802
+ @h,@rows=nil,''
803
+ h={
804
+ is_for: :table,
805
+ obj: '',
806
+ sym: :table_close,
807
+ num: @num_id[:table],
808
+ }
809
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
810
+ t_o
811
+ else
812
+ if t_o.is_a?(String) \
813
+ and t_o !~/^(?:table\{|```[ ]+table)/
814
+ t_o=t_o.gsub(/^\n+/m,'').
815
+ gsub(/\n+/m,"#{Mx[:tc_p]}")
816
+ @rows += t_o + Mx[:tc_c]
817
+ end
818
+ t_o=nil
819
+ end
820
+ end
821
+ if @per.code==:curls \
822
+ or @per.code==:tics
823
+ if (@per.code==:curls \
824
+ && t_o =~/^\}code/) \
825
+ or (@per.code==:tics \
826
+ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/m)
827
+ @per.code=:off
828
+ if @tuned_code[-1]
829
+ @tuned_code[-1].
830
+ gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*\Z/m,'')
831
+ end
832
+ obj=@tuned_code.join("\n")
833
+ tags=[]
834
+ h={
835
+ obj: obj,
836
+ idx: idx,
837
+ syntax: @per.lngsyn,
838
+ tags: tags,
839
+ num: @num_id[:code_block],
840
+ number_: @codeblock_numbered,
841
+ }
842
+ @per.lngsyn=:txt
843
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h)
844
+ @tuned_code=[]
845
+ tuned_file << t_o
846
+ h={
847
+ is_for: :code,
848
+ obj: '',
849
+ sym: :code_close,
850
+ num: @num_id[:code_block],
851
+ }
852
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
853
+ end
854
+ if (@per.code==:curls \
855
+ || @per.code==:tics) \
856
+ and t_o.is_a?(String)
857
+ sub_array=t_o.dup + "#{Mx[:br_nl]}"
858
+ @line_mode=[]
859
+ sub_array.scan(/.+/) {|w| @line_mode << w if w =~/[\S]+/}
860
+ t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(:code).join
861
+ @tuned_code << t_o
862
+ t_o=nil
863
+ end
864
+ elsif (@per.poem==:curls \
865
+ || @per.poem==:tics) \
866
+ or (@per.box==:curls \
867
+ || @per.box==:tics) \
868
+ or (@per.group==:curls \
869
+ || @per.group==:tics) \
870
+ or (@per.block==:curls \
871
+ || @per.block==:tics) \
872
+ or (@per.alt==:curls \
873
+ || @per.alt==:tics) \
874
+ or (@per.quote==:open \
875
+ && t_o =~/`:quote_close`/m) #not
876
+ if (@per.poem==:curls \
877
+ && t_o =~/^\}poem$/m) \
878
+ or (@per.poem==:tics \
879
+ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
880
+ @per.poem=:off
881
+ h={
882
+ is_for: :poem,
883
+ obj: '',
884
+ idx: idx,
885
+ sym: :poem_close,
886
+ num: @num_id[:poem],
887
+ }
888
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
889
+ elsif (@per.box==:curls \
890
+ && t_o =~/^\}box/) \
891
+ or (@per.box==:tics \
892
+ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
893
+ @per.box=:off
894
+ obj,tags=extract_tags(@tuned_block.join("\n"))
895
+ h={
896
+ obj: obj,
897
+ idx: idx,
898
+ tags: tags,
899
+ num: @num_id[:box],
900
+ }
901
+ @tuned_block=[]
902
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.box(h)
903
+ tuned_file << t_o
904
+ h={
905
+ is_for: :box,
906
+ obj: '',
907
+ idx: idx,
908
+ sym: :box_close,
909
+ num: @num_id[:box],
910
+ }
911
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
912
+ elsif (@per.group==:curls \
913
+ && t_o =~/^\}group/) \
914
+ or (@per.group==:tics \
915
+ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
916
+ @per.group=:off
917
+ obj,tags=extract_tags(@tuned_block.join("\n"))
918
+ h={
919
+ obj: obj,
920
+ idx: idx,
921
+ tags: tags,
922
+ num: @num_id[:group],
923
+ }
924
+ @tuned_block=[]
925
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.group(h)
926
+ tuned_file << t_o
927
+ h={
928
+ is_for: :group,
929
+ obj: '',
930
+ sym: :group_close,
931
+ num: @num_id[:group],
932
+ }
933
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
934
+ elsif (@per.block==:curls \
935
+ && t_o =~/^\}block/) \
936
+ or (@per.block==:tics \
937
+ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
938
+ @per.block=:off
939
+ obj,tags=extract_tags(@tuned_block.join("\n"))
940
+ h={
941
+ obj: obj,
942
+ idx: idx,
943
+ tags: tags,
944
+ num: @num_id[:block],
945
+ }
946
+ @tuned_block=[]
947
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.block(h)
948
+ tuned_file << t_o
949
+ h={
950
+ is_for: :block,
951
+ obj: '',
952
+ sym: :block_close,
953
+ num: @num_id[:block],
954
+ }
955
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
956
+ elsif (@per.alt==:curls \
957
+ && t_o =~/^\}alt/) \
958
+ or (@per.alt==:tics \
959
+ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
960
+ @per.alt=:off
961
+ obj,tags=extract_tags(@tuned_block.join("\n"))
962
+ h={
963
+ obj: obj,
964
+ idx: idx,
965
+ tags: tags,
966
+ num: @num_id[:alt],
967
+ }
968
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.alt(h)
969
+ @tuned_block=[]
970
+ tuned_file << t_o
971
+ h={
972
+ is_for: :alt,
973
+ obj: '',
974
+ sym: :alt_close,
975
+ num: @num_id[:alt],
976
+ }
977
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
978
+ elsif @per.quote==:open \
979
+ and t_o =~/`:quote_close`/m
980
+ @per.quote=:off
981
+ h={
982
+ is_for: :quote,
983
+ idx: idx,
984
+ obj: '',
985
+ sym: :quote_close,
986
+ num: @num_id[:quote],
987
+ }
988
+ t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h)
989
+ elsif @per.quote==:open
990
+ t_o,tags=extract_tags(t_o)
991
+ h={
992
+ indent: 1,
993
+ obj: t_o,
994
+ idx: idx,
995
+ note_: note,
996
+ image_: image,
997
+ tags: tags,
998
+ quote: quotes?,
999
+ }
1000
+ SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
1001
+ end
1002
+ if (@per.poem==:curls \
1003
+ || @per.poem==:tics) \
1004
+ or (@per.group==:curls \
1005
+ || @per.group==:tics) \
1006
+ or (@per.alt==:curls \
1007
+ || @per.alt==:tics) \
1008
+ and t_o =~/\S/ \
1009
+ and t_o !~/^(?:\}(?:verse|code|box|alt|group|block)|(?:verse|code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|alt|group|block)\{)/ \
1010
+ and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic
1011
+ sub_array=t_o.dup
1012
+ @line_mode=sub_array.scan(/.+/)
1013
+ type=if @per.poem==:curls or @per.poem==:tics
1014
+ t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join
1015
+ poem=t_o.split(/\n\n/)
1016
+ poem.each do |v|
1017
+ v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n")
1018
+ obj,tags=extract_tags(v)
1019
+ h={
1020
+ obj: obj,
1021
+ tags: tags,
1022
+ num: @num_id[:poem],
1023
+ }
1024
+ t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.verse(h)
1025
+ tuned_file << t_o
1026
+ end
1027
+ :poem
1028
+ else :group
1029
+ end
1030
+ end
1031
+ @verse_count+=1 if @per.poem==:curls or @per.poem==:tics
1032
+ end
1033
+ if @per.code==:off
1034
+ if @per.poem==:curls or @per.poem==:tics \
1035
+ or @per.box==:curls or @per.box==:tics \
1036
+ or @per.group==:curls or @per.group==:tics \
1037
+ or @per.alt==:curls or @per.alt==:tics \
1038
+ or (@per.quote==:open and t_o =~/`:quote_close`/m)
1039
+ if t_o.is_a?(String)
1040
+ t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}").
1041
+ gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}").
1042
+ gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
1043
+ t_o=t_o + Mx[:br_nl] if t_o =~/\S+/
1044
+ elsif t_o.is==:group \
1045
+ || t_o.is==:block \
1046
+ || t_o.is==:alt \
1047
+ || t_o.is==:box \
1048
+ || t_o.is==:verse
1049
+ t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}").
1050
+ gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}").
1051
+ gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
1052
+ end
1053
+ @tuned_block << t_o if t_o =~/\S+/
1054
+ else tuned_file << t_o
1055
+ end
1056
+ else tuned_file << t_o
1057
+ end
1058
+ end
1059
+ tuned_file
1060
+ end
1061
+ def identify_parts
1062
+ tuned_file=[]
1063
+ @tuned_block,@tuned_code=[],[]
1064
+ @@counter,@verse_count=0,0
1065
+ @num_id={
1066
+ code_block: 0,
1067
+ poem: 0,
1068
+ box: 0,
1069
+ group: 0,
1070
+ alt: 0,
1071
+ quote: 0,
1072
+ table: 0,
1073
+ }
1074
+ @metadata={}
1075
+ @data,bibliography=SiSU_AO_References::Bibliography.new(@md,@data).biblio_extraction
1076
+ tuned_file=extract_structure_loop(@data,tuned_file)
1077
+ if @md.flag_endnotes
1078
+ tuned_file << @pb
1079
+ h={
1080
+ ln: 1,
1081
+ lc: 1,
1082
+ obj: 'Endnotes',
1083
+ autonum_: false,
1084
+ }
1085
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1086
+ h={
1087
+ ln: 4,
1088
+ lc: 2,
1089
+ obj: 'Endnotes',
1090
+ name: 'endnotes',
1091
+ autonum_: false,
1092
+ }
1093
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1094
+ h={
1095
+ obj: 'Endnotes'
1096
+ }
1097
+ end
1098
+ if @md.flag_auto_biblio
1099
+ tuned_file << @pb
1100
+ h={
1101
+ ln: 1,
1102
+ lc: 1,
1103
+ obj: 'References',
1104
+ autonum_: false,
1105
+ }
1106
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1107
+ h={
1108
+ ln: 4,
1109
+ lc: 2,
1110
+ obj: 'Bibliography',
1111
+ name: 'biblio',
1112
+ autonum_: false,
1113
+ }
1114
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1115
+ h={
1116
+ obj: 'Bibliography'
1117
+ }
1118
+ citenumber=0
1119
+ bibliography.each do |c|
1120
+ citenumber +=1 if c.is_a?(Hash)
1121
+ if c[:is]==:book
1122
+ h={
1123
+ obj: %{[#{citenumber}] *{#{c[:author]}}* /{"#{c[:fulltitle]}"}/ #{c[:publisher]} (#{c[:year]}) #{c[:url]}},
1124
+ tags: [c[:id]],
1125
+ hang: 0,
1126
+ indent: 2,
1127
+ ocn_: false,
1128
+ }
1129
+ tuned_file << SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
1130
+ elsif c[:is]==:article
1131
+ h={
1132
+ obj: %{[#{citenumber}] *{#{c[:author]}}* /{"#{c[:title]}"}/ #{c[:journal]} #{c[:volume]} (#{c[:year]}) #{c[:url]}},
1133
+ tags: [c[:id]],
1134
+ hang: 0,
1135
+ indent: 2,
1136
+ ocn_: false,
1137
+ }
1138
+ tuned_file << SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
1139
+ end
1140
+ end
1141
+ elsif @md.flag_biblio
1142
+ tuned_file << @pb
1143
+ h={
1144
+ ln: 1,
1145
+ lc: 1,
1146
+ obj: 'References',
1147
+ autonum_: false,
1148
+ }
1149
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1150
+ h={
1151
+ ln: 4,
1152
+ lc: 2,
1153
+ obj: 'Bibliography',
1154
+ name: 'biblio',
1155
+ autonum_: false,
1156
+ }
1157
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1158
+ h={
1159
+ obj: 'Bibliography'
1160
+ }
1161
+ if bibliography.length > 0
1162
+ tuned_file=extract_structure_loop(bibliography,tuned_file)
1163
+ else
1164
+ tuned_file, citations =
1165
+ SiSU_AO_References::Citations.new(@md,tuned_file).songsheet # ao_references.rb
1166
+ citenumber=0
1167
+ citations.compact.each do |c|
1168
+ citenumber +=1 if c.is_a?(Hash)
1169
+ if c[:is]==:book
1170
+ h={
1171
+ obj: %{[#{citenumber}] *{#{c[:author]}}* /{#{c[:publication]}}/ (#{c[:year]})},
1172
+ hang: 0,
1173
+ indent: 2,
1174
+ ocn_: false,
1175
+ }
1176
+ tuned_file << SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
1177
+ elsif c[:is]==:article
1178
+ h={
1179
+ obj: %{[#{citenumber}] *{#{c[:author]}}* /{"#{c[:title]}"}/ #{c[:publication]} editor #{c[:editor]} (#{c[:year]})},
1180
+ hang: 0,
1181
+ indent: 2,
1182
+ ocn_: false,
1183
+ }
1184
+ tuned_file << SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
1185
+ end
1186
+ end
1187
+ end
1188
+ end
1189
+ if @md.book_idx
1190
+ tuned_file << @pb
1191
+ h={
1192
+ ln: 1,
1193
+ lc: 1,
1194
+ obj: 'Index',
1195
+ autonum_: false,
1196
+ }
1197
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1198
+ h={
1199
+ ln: 4,
1200
+ lc: 2,
1201
+ obj: 'Index',
1202
+ name: 'book_index',
1203
+ autonum_: false,
1204
+ }
1205
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1206
+ h={
1207
+ obj: 'Index'
1208
+ }
1209
+ end
1210
+ tuned_file << @pb
1211
+ h={
1212
+ ln: 1,
1213
+ lc: 1,
1214
+ obj: 'Metadata',
1215
+ autonum_: false,
1216
+ ocn_: false,
1217
+ }
1218
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1219
+ h={
1220
+ ln: 4,
1221
+ lc: 2,
1222
+ obj: 'SiSU Metadata, document information',
1223
+ name: 'metadata',
1224
+ autonum_: false,
1225
+ ocn_: false,
1226
+ }
1227
+ tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h)
1228
+ h={
1229
+ obj: 'eof',
1230
+ }
1231
+ meta=SiSU_AO_DocumentStructure::ObjectMetadata.new.metadata(@metadata)
1232
+ [tuned_file,meta,bibliography]
1233
+ end
1234
+ def table_rows_and_columns_array(table_str)
1235
+ table=[]
1236
+ table_str.split(/#{Mx[:tc_c]}/).each do |table_row|
1237
+ table_row_with_columns=table_row.split(/#{Mx[:tc_p]}/)
1238
+ table << table_row_with_columns
1239
+ end
1240
+ table
1241
+ end
1242
+ def meta_heading(h)
1243
+ h={
1244
+ lv: h[:lv],
1245
+ ln: h[:ln],
1246
+ name: h[:name],
1247
+ obj: h[:obj],
1248
+ ocn: '0',
1249
+ }
1250
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h)
1251
+ end
1252
+ def meta_para(str)
1253
+ h={
1254
+ obj: str,
1255
+ ocn_: false,
1256
+ }
1257
+ SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
1258
+ end
1259
+ def build_lines(type=:none)
1260
+ lines=@data
1261
+ lines.each.map do |line|
1262
+ line=if line =~/\S/ \
1263
+ and line !~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|\}code)/ \
1264
+ and line !~/^(?:```[ ]+code(?:\.[a-z][0-9a-z_]+)?|```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \
1265
+ and not line.is_a?(Hash) #watch
1266
+ @@counter+=1 if @per.code==:curls or @per.code==:tics
1267
+ line=line.gsub(/\s\s/,"#{Mx[:nbsp]*2}").
1268
+ gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}")
1269
+ line=line.gsub(/^/,"#{Mx[:gr_o]}codeline#{Mx[:gr_c]}") if type==:code # REMOVE try sort for texpdf special case
1270
+ line=if line =~/(?:https?|file|ftp):\/\/\S+$/
1271
+ line.gsub(/\s*$/," #{Mx[:br_nl]}")
1272
+ else line.gsub(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code'
1273
+ end
1274
+ elsif line =~/^\s*$/
1275
+ line.gsub(/\s*$/,"#{Mx[:br_nl]}")
1276
+ else line
1277
+ end
1278
+ line
1279
+ end
1280
+ end
1281
+ end
1282
+ class Structure # this must happen early
1283
+ def initialize(md)
1284
+ @md=md
1285
+ end
1286
+ def structure(data)
1287
+ data.compact.each do |dob|
1288
+ structure_markup(dob)
1289
+ end
1290
+ end
1291
+ def structure_markup(dob) #build structure where structure provided only in meta header
1292
+ dob=if dob.is==:para \
1293
+ && (((dob.hang !~/[1-9]/) && (dob.indent !~/[1-9]/)) \
1294
+ || (dob.hang != dob.indent)) \
1295
+ and not dob.bullet_
1296
+ dob=case dob.obj
1297
+ when /^#{@md.lv0}/
1298
+ h={
1299
+ is: :heading,
1300
+ lv: 'A',
1301
+ ln: 0,
1302
+ }
1303
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1304
+ when /^#{@md.lv1}/
1305
+ h={
1306
+ is: :heading,
1307
+ lv: 'B',
1308
+ ln: 1,
1309
+ }
1310
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1311
+ when /^#{@md.lv2}/
1312
+ h={
1313
+ is: :heading,
1314
+ lv: 'C',
1315
+ ln: 2,
1316
+ }
1317
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1318
+ when /^#{@md.lv3}/
1319
+ h={
1320
+ is: :heading,
1321
+ lv: 'D',
1322
+ ln: 3,
1323
+ }
1324
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1325
+ when /^#{@md.lv4}/
1326
+ h={
1327
+ is: :heading,
1328
+ lv: '1',
1329
+ ln: 4,
1330
+ }
1331
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1332
+ when /^#{@md.lv5}/
1333
+ h={
1334
+ is: :heading,
1335
+ lv: '2',
1336
+ ln: 5,
1337
+ }
1338
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1339
+ when /^#{@md.lv6}/
1340
+ h={
1341
+ is: :heading,
1342
+ lv: '3',
1343
+ ln: 6,
1344
+ }
1345
+ SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob)
1346
+ else dob
1347
+ end
1348
+ else dob
1349
+ end
1350
+ dob
1351
+ end
1352
+ end
1353
+ class OCN
1354
+ def initialize(md,data,fnx,process)
1355
+ @md,@data,@fnx,@process=md,data,fnx,process
1356
+ end
1357
+ def structure_info
1358
+ def lv
1359
+ %w[A~ B~ C~ D~ 1 2 3 4]
1360
+ end
1361
+ def possible_parents(child)
1362
+ case child
1363
+ when /A~/ then 'none'
1364
+ when /B~/ then 'A~'
1365
+ when /C~/ then 'B~'
1366
+ when /D~/ then 'C~'
1367
+ when /1/ then 'A~, B~, C~, D~'
1368
+ when /2/ then '1'
1369
+ when /3/ then '2'
1370
+ when /4/ then '3'
1371
+ end
1372
+ end
1373
+ def possible_children(parent)
1374
+ case parent
1375
+ when /A~/ then 'B~, 1'
1376
+ when /B~/ then 'C~, 1'
1377
+ when /C~/ then 'D~, 1'
1378
+ when /D~/ then '1'
1379
+ when /1/ then '2'
1380
+ when /2/ then '3'
1381
+ when /3/ then '4'
1382
+ when /4/ then 'none'
1383
+ end
1384
+ end
1385
+ self
1386
+ end
1387
+ def document_structure_check_info(node,node_parent,status=:ok)
1388
+ node_ln=/^([0-7])/.match(node)[1].to_i
1389
+ node_parent_ln=/^([0-7])/.match(node_parent)[1].to_i
1390
+ if status==:error \
1391
+ or @md.opt.act[:maintenance][:set]==:on
1392
+ puts %{node: #{node}, parent node: #{node_parent} #{status.upcase}}
1393
+ if status==:error
1394
+ node_ln=/^([0-7])/.match(node)[1].to_i
1395
+ node_parent_ln=/^([0-7])/.match(node_parent)[1].to_i
1396
+ STDERR.puts %{current level: #{structure_info.lv[node_ln]} (possible parent levels: #{structure_info.possible_parents(structure_info.lv[node_ln])})
1397
+ parent level: #{structure_info.lv[node_parent_ln]} (possible child levels: #{structure_info.possible_children(structure_info.lv[node_parent_ln])})
1398
+ SKIPPED processing file:
1399
+ [#{@md.opt.lng}] "#{@md.fns}"}
1400
+ if @md.opt.act[:no_stop][:set]==:on
1401
+ $process_document = :skip
1402
+ else exit
1403
+ end
1404
+ end
1405
+ end
1406
+ end
1407
+ def warning_incorrect_parent_level_or_level(txt)
1408
+ puts %{ERROR. There is an error in markup of heading levels either here or in the parent heading.
1409
+ The current header reads:
1410
+ "#{txt}"
1411
+ has incorrect level and/or parent level
1412
+ --}
1413
+ end
1414
+ def required_headers_present?
1415
+ if @process == :complete
1416
+ unless (defined? @md.title \
1417
+ and @md.title.full)
1418
+ STDERR.puts %{required header missing:
1419
+
1420
+ @title:
1421
+ SKIPPED processing file:
1422
+ [#{@md.opt.lng}] "#{@md.fns}"
1423
+ }
1424
+ if @md.opt.act[:no_stop][:set]==:on
1425
+ $process_document = :skip
1426
+ else exit
1427
+ end
1428
+ end
1429
+ unless (defined? @md.creator.author \
1430
+ and @md.creator.author)
1431
+ STDERR.puts %{required header missing:
1432
+
1433
+ @creator:
1434
+ :author: anonymous?
1435
+ SKIPPED processing file:
1436
+ [#{@md.opt.lng}] "#{@md.fns}"
1437
+ }
1438
+ if @md.opt.act[:no_stop][:set]==:on
1439
+ $process_document = :skip
1440
+ else exit
1441
+ end
1442
+ end
1443
+ end
1444
+ end
1445
+ def ocn #and auto segment numbering increment
1446
+ required_headers_present?
1447
+ data=@data
1448
+ @o_array=[]
1449
+ node=ocn=ocn_dv=ocn_sp=ocnh=ocnh0=ocnh1=ocnh2=ocnh3=ocnh4=ocnh5=ocnh6=ocnh7=ocno=ocnp=ocnt=ocnc=ocng=ocni=ocnu=0 # h heading, o other, t table, g group, i image
1450
+ regex_exclude_ocn_and_node = /#{Rx[:meta]}|^@\S+?:\s|^4~endnotes|^#{Mx[:lv_o]}4:endnotes#{Mx[:lv_c]}|^\^~ |<:e[:_]\d+?>|^<:\#|<:- |<[:!]!4|<hr width|#{Mx[:br_endnotes]}|\A\s*\Z/mi #ocn here #&nbsp; added with Tune.code #¡
1451
+ parent=node1=node2=node3=node4=node5=node6=node7=nil
1452
+ node0='0:0;0'
1453
+ @collapsed_lv0=0
1454
+ @lev_occurences={ a: 0, b: 0, c: 0, d: 0, l1: 0, l2: 0, l3: 0, l4: 0 }
1455
+ data.each do |dob|
1456
+ h={}
1457
+ if (dob.obj !~ regex_exclude_ocn_and_node || dob.is==:code) \
1458
+ && (dob.of !=:comment \
1459
+ && dob.of !=:layout \
1460
+ && dob.of !=:meta) \
1461
+ && dob.ocn_
1462
+ #dob.ln now is determined, and set earlier, check how best to remove this -->
1463
+ if dob.is==:heading
1464
+ @ln=ln=case dob.lv
1465
+ when 'A' then 0
1466
+ when 'B' then 1
1467
+ when 'C' then 2
1468
+ when 'D' then 3
1469
+ when '1' then 4
1470
+ when '2' then 5
1471
+ when '3' then 6
1472
+ when '4' then 7
1473
+ when '5' then 8
1474
+ when '6' then 9
1475
+ end
1476
+ end
1477
+ if not dob.obj =~/~#|-#/
1478
+ ocn+=1
1479
+ end
1480
+ if @process == :complete \
1481
+ or (@fnx == @md.opt.fns \
1482
+ && @md.opt.fns =~/.sst$/)
1483
+ if dob.is==:heading \
1484
+ and (ln.to_s =~/^[0-9]/ \
1485
+ or ln.to_s =~@md.lv0 \
1486
+ or ln.to_s =~@md.lv1 \
1487
+ or ln.to_s =~@md.lv2 \
1488
+ or ln.to_s =~@md.lv3 \
1489
+ or ln.to_s =~@md.lv4 \
1490
+ or ln.to_s =~@md.lv5 \
1491
+ or ln.to_s =~@md.lv6 \
1492
+ or ln.to_s =~@md.lv7)
1493
+ if not dob.obj =~/~#|-#/
1494
+ ocnh+=1
1495
+ end
1496
+ if ln==0 \
1497
+ or ln=~@md.lv0
1498
+ @lev_occurences[:a] += 1
1499
+ if not dob.obj =~/~#|-#/
1500
+ ocn_flag=true
1501
+ ocnh0+=1 #heading
1502
+ node0="0:#{ocnh0};#{ocn}"
1503
+ else
1504
+ #document_structure_check_info(node0,node0,:error) #fix
1505
+ ocn_flag=false
1506
+ node0="0:0;0"
1507
+ end
1508
+ document_structure_check_info(node0,node0)
1509
+ @collapsed_lv0=0
1510
+ collapsed_level=@collapsed_lv0
1511
+ node,ocn_sp,parent=node0,"h#{ocnh}",'ROOT'
1512
+ elsif ln==1 \
1513
+ or ln=~@md.lv1
1514
+ @lev_occurences[:b] += 1
1515
+ if not dob.obj =~/~#|-#/
1516
+ ocn_flag=true
1517
+ ocnh1+=1 #heading
1518
+ node1="1:#{ocnh1};#{ocn}"
1519
+ else
1520
+ #document_structure_check_info(node0,node0,:error) #fix
1521
+ ocn_flag=false
1522
+ node1="1:0;0"
1523
+ end
1524
+ parent=if node0
1525
+ document_structure_check_info(node1,node0)
1526
+ @collapsed_lv1=@collapsed_lv0+1
1527
+ node0
1528
+ else
1529
+ warning_incorrect_parent_level_or_level(dob.obj)
1530
+ document_structure_check_info(node0,node0,:error)
1531
+ node0
1532
+ end
1533
+ collapsed_level=@collapsed_lv1
1534
+ node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX
1535
+ elsif ln==2 \
1536
+ or ln=~@md.lv2
1537
+ @lev_occurences[:c] += 1
1538
+ if not dob.obj =~/~#|-#/
1539
+ ocn_flag=true
1540
+ ocnh2+=1
1541
+ node2="2:#{ocnh2};#{ocn}"
1542
+ else
1543
+ #document_structure_check_info(node0,node0,:error) #fix
1544
+ ocn_flag=false
1545
+ node2="2:0;0"
1546
+ end
1547
+ parent=if node1
1548
+ document_structure_check_info(node2,node1)
1549
+ @collapsed_lv2=@collapsed_lv1+1
1550
+ node1
1551
+ else
1552
+ warning_incorrect_parent_level_or_level(dob.obj)
1553
+ document_structure_check_info(node2,node0,:error)
1554
+ node0
1555
+ end
1556
+ collapsed_level=@collapsed_lv2
1557
+ node,ocn_sp=node2,"h#{ocnh}"
1558
+ elsif ln==3 \
1559
+ or ln=~@md.lv3
1560
+ @lev_occurences[:d] += 1
1561
+ if not dob.obj =~/~#|-#/
1562
+ ocn_flag=true
1563
+ ocnh3+=1
1564
+ node3="3:#{ocnh3};#{ocn}"
1565
+ else
1566
+ #document_structure_check_info(node0,node0,:error) #fix
1567
+ ocn_flag=false
1568
+ node3="3:0;0"
1569
+ end
1570
+ parent=if node2
1571
+ document_structure_check_info(node3,node2)
1572
+ @collapsed_lv3=@collapsed_lv2+1
1573
+ node2
1574
+ elsif node1
1575
+ warning_incorrect_parent_level_or_level(dob.obj)
1576
+ puts %{parent is :A~ & this level #{dob.lv}
1577
+ either parent should be level :B~
1578
+ or this level should be level :B~ rather than #{dob.lv}}
1579
+ document_structure_check_info(node3,node1,:error)
1580
+ @collapsed_lv3=@collapsed_lv1+1
1581
+ node1
1582
+ else
1583
+ document_structure_check_info(node3,node0,:error)
1584
+ warning_incorrect_parent_level_or_level(dob.obj)
1585
+ node0
1586
+ end
1587
+ collapsed_level=@collapsed_lv3
1588
+ node,ocn_sp=node3,"h#{ocnh}"
1589
+ elsif ln==4 \
1590
+ or ln=~@md.lv4
1591
+ @lev_occurences[:l1] += 1
1592
+ if not dob.obj =~/~#|-#/
1593
+ ocn_flag=true
1594
+ ocnh4+=1
1595
+ node4="4:#{ocnh4};#{ocn}"
1596
+ else
1597
+ ocn_flag=false
1598
+ node4="4:0;0"
1599
+ end
1600
+ parent=if node3
1601
+ document_structure_check_info(node4,node3)
1602
+ @collapsed_lv4=@collapsed_lv3+1
1603
+ node3
1604
+ elsif node2
1605
+ document_structure_check_info(node4,node2)
1606
+ @collapsed_lv4=@collapsed_lv2+1
1607
+ node2
1608
+ elsif node1
1609
+ document_structure_check_info(node4,node1)
1610
+ @collapsed_lv4=@collapsed_lv1+1
1611
+ node1
1612
+ elsif node0
1613
+ document_structure_check_info(node4,node0)
1614
+ @collapsed_lv4=@collapsed_lv0+1
1615
+ node0
1616
+ else
1617
+ warning_incorrect_parent_level_or_level(dob.obj)
1618
+ document_structure_check_info(node4,node0,:error)
1619
+ node0
1620
+ end
1621
+ collapsed_level=@collapsed_lv4
1622
+ node,ocn_sp=node4,"h#{ocnh}"
1623
+ elsif ln==5 \
1624
+ or ln=~@md.lv5
1625
+ @lev_occurences[:l2] += 1
1626
+ if not dob.obj =~/~#|-#/
1627
+ ocn_flag=true
1628
+ ocnh5+=1
1629
+ node5="5:#{ocnh5};#{ocn}"
1630
+ else
1631
+ ocn_flag=false
1632
+ node5="5:0;0"
1633
+ end
1634
+ parent=if node4
1635
+ document_structure_check_info(node5,node4)
1636
+ @collapsed_lv5=@collapsed_lv4+1
1637
+ node4
1638
+ elsif node3
1639
+ warning_incorrect_parent_level_or_level(dob.obj)
1640
+ document_structure_check_info(node5,node3,:error)
1641
+ @collapsed_lv5=@collapsed_lv3+1
1642
+ node3
1643
+ elsif node2
1644
+ warning_incorrect_parent_level_or_level(dob.obj)
1645
+ document_structure_check_info(node5,node2,:error)
1646
+ @collapsed_lv5=@collapsed_lv2+1
1647
+ node2
1648
+ elsif node1
1649
+ warning_incorrect_parent_level_or_level(dob.obj)
1650
+ document_structure_check_info(node5,node1,:error)
1651
+ @collapsed_lv5=@collapsed_lv1+1
1652
+ node1
1653
+ else
1654
+ warning_incorrect_parent_level_or_level(dob.obj)
1655
+ document_structure_check_info(node5,node0,:error)
1656
+ node0
1657
+ end
1658
+ collapsed_level=@collapsed_lv5
1659
+ node,ocn_sp=node5,"h#{ocnh}"
1660
+ elsif ln==6 \
1661
+ or ln=~@md.lv6
1662
+ @lev_occurences[:l3] += 1
1663
+ if not dob.obj =~/~#|-#/
1664
+ ocn_flag=true
1665
+ ocnh6+=1
1666
+ node6="6:#{ocnh6};#{ocn}"
1667
+ else
1668
+ ocn_flag=false
1669
+ node6="6:0;0"
1670
+ end
1671
+ parent=if node5
1672
+ document_structure_check_info(node6,node5)
1673
+ @collapsed_lv6=@collapsed_lv5+1
1674
+ node5
1675
+ elsif node4
1676
+ warning_incorrect_parent_level_or_level(dob.obj)
1677
+ puts "parent is level #4 (1~) & this level ##{dob.ln} (#{dob.lv}~)
1678
+ either parent should be level #5 (2~)
1679
+ or this level should be #5 (2~) rather ##{dob.ln} (#{dob.lv}~)"
1680
+ document_structure_check_info(node6,node4,:error)
1681
+ @collapsed_lv6=@collapsed_lv4+1
1682
+ node4
1683
+ elsif node3
1684
+ warning_incorrect_parent_level_or_level(dob.obj)
1685
+ document_structure_check_info(node6,node3,:error)
1686
+ @collapsed_lv6=@collapsed_lv3+1
1687
+ node3
1688
+ elsif node2
1689
+ warning_incorrect_parent_level_or_level(dob.obj)
1690
+ document_structure_check_info(node6,node2,:error)
1691
+ @collapsed_lv6=@collapsed_lv2+1
1692
+ node2
1693
+ elsif node1
1694
+ warning_incorrect_parent_level_or_level(dob.obj)
1695
+ document_structure_check_info(node6,node1,:error)
1696
+ @collapsed_lv6=@collapsed_lv1+1
1697
+ node1
1698
+ else
1699
+ warning_incorrect_parent_level_or_level(dob.obj)
1700
+ document_structure_check_info(node6,node0,:error)
1701
+ node0
1702
+ end
1703
+ collapsed_level=@collapsed_lv6
1704
+ node,ocn_sp=node6,"h#{ocnh}"
1705
+ elsif ln==7 \
1706
+ or ln=~@md.lv7
1707
+ @lev_occurences[:l4] += 1
1708
+ if not dob.obj =~/~#|-#/
1709
+ ocn_flag=true
1710
+ ocnh7+=1
1711
+ node7="7:#{ocnh7};#{ocn}"
1712
+ else
1713
+ ocn_flag=false
1714
+ node7="7:0;0"
1715
+ end
1716
+ parent=if node6
1717
+ document_structure_check_info(node7,node6)
1718
+ @collapsed_lv7=@collapsed_lv6+1
1719
+ node5
1720
+ elsif node5
1721
+ warning_incorrect_parent_level_or_level(dob.obj)
1722
+ puts "parent is level #5 (2~) & this level ##{dob.ln} (#{dob.lv}~)
1723
+ either parent should be level #6 (3~)
1724
+ or this level should be #6 (3~) rather ##{dob.ln} (#{dob.lv}~)"
1725
+ document_structure_check_info(node7,node5,:error)
1726
+ @collapsed_lv6=@collapsed_lv5+1
1727
+ node5
1728
+ elsif node4
1729
+ warning_incorrect_parent_level_or_level(dob.obj)
1730
+ puts "parent is level #4 (1~) & this level ##{dob.ln} (#{dob.lv}~)
1731
+ either parent should be level 6~
1732
+ or this level should be #6 (3~) rather ##{dob.ln} (#{dob.lv}~)"
1733
+ document_structure_check_info(node7,node4,:error)
1734
+ @collapsed_lv6=@collapsed_lv4+1
1735
+ node4
1736
+ elsif node3
1737
+ warning_incorrect_parent_level_or_level(dob.obj)
1738
+ document_structure_check_info(node7,node3,:error)
1739
+ @collapsed_lv6=@collapsed_lv3+1
1740
+ node3
1741
+ elsif node2
1742
+ warning_incorrect_parent_level_or_level(dob.obj)
1743
+ document_structure_check_info(node7,node2,:error)
1744
+ @collapsed_lv6=@collapsed_lv2+1
1745
+ node2
1746
+ elsif node1
1747
+ warning_incorrect_parent_level_or_level(dob.obj)
1748
+ document_structure_check_info(node7,node1,:error)
1749
+ @collapsed_lv6=@collapsed_lv1+1
1750
+ node1
1751
+ else
1752
+ warning_incorrect_parent_level_or_level(dob.obj)
1753
+ document_structure_check_info(node7,node0,:error)
1754
+ node0
1755
+ end
1756
+ collapsed_level=@collapsed_lv7
1757
+ node,ocn_sp=node7,"h#{ocnh}"
1758
+ end
1759
+ else
1760
+ unless @lev_occurences[:l1] > 0
1761
+ STDERR.puts %{Substantive text objects must follow a level 1~ heading and there are none at this point in processing: #{@lev_occurences[:l1]}
1762
+ SKIPPED processing file:
1763
+ [#{@md.opt.lng}] "#{@md.fns}"}
1764
+ puts dob.obj #.gsub(/^(.{1,80})/,'"\1"')
1765
+ exit
1766
+ end
1767
+ unless @ln >= 4
1768
+ lev=case @ln
1769
+ when 0 then 'A'
1770
+ when 1 then 'B'
1771
+ when 2 then 'C'
1772
+ when 3 then 'D'
1773
+ when 4 then '1'
1774
+ when 5 then '2'
1775
+ when 6 then '3'
1776
+ when 7 then '4'
1777
+ when 8 then '5'
1778
+ when 9 then '6'
1779
+ end
1780
+ STDERR.puts %{Substantive text objects must follow a level 1~ 2~ or 3~ heading: #{lev}~
1781
+ SKIPPED processing file:
1782
+ [#{@md.opt.lng}] "#{@md.fns}"}
1783
+ puts dob.obj.gsub(/^(.{1,80})/,'"\1"')
1784
+ if @md.opt.act[:no_stop][:set]==:on
1785
+ $process_document = :skip
1786
+ break
1787
+ else exit
1788
+ end
1789
+ end
1790
+ if not dob.obj =~/~#|-#/
1791
+ ocn_flag=true
1792
+ else
1793
+ ocn_flag=false
1794
+ end
1795
+ ocno+=1
1796
+ if dob.is==:table
1797
+ ocnt+=1
1798
+ ocn_sp,parent="t#{ocnt}",node
1799
+ elsif dob.is==:code
1800
+ ocnc+=1
1801
+ ocn_sp,parent="c#{ocnc}",node
1802
+ elsif dob.is==:group \
1803
+ || dob.is==:box \
1804
+ || dob.is==:block \
1805
+ || dob.is==:alt \
1806
+ || dob.is==:verse
1807
+ ocng+=1 #group, poem
1808
+ ocn_sp,parent="g#{ocng}",node
1809
+ elsif dob.is==:image #check
1810
+ ocni+=1
1811
+ ocn_sp,parent="i#{ocni}",node
1812
+ else ocnp+=1 #paragraph
1813
+ ocn_sp,parent="p#{ocnp}",node
1814
+ end
1815
+ end
1816
+ end
1817
+ if dob.is==:heading
1818
+ if ocn_flag==true
1819
+ dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=
1820
+ ln, node, ocn, ocn_flag, ocn_dv,ocn_sp, parent, collapsed_level
1821
+ else
1822
+ ocnu+=1
1823
+ heading_use=:ok
1824
+ if dob.obj=~/#{Mx[:pa_non_object_no_heading]}/
1825
+ dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_no_heading]}/,'')
1826
+ heading_use=:ok
1827
+ elsif dob.obj=~/#{Mx[:pa_non_object_dummy_heading]}/
1828
+ dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_dummy_heading]}/,'')
1829
+ heading_use=:dummy
1830
+ end
1831
+ dob.ln,dob.node,dob.ocn,dob.ocn_,dob.use_, dob.odv,dob.osp,dob.parent,dob.lc=
1832
+ ln, node, nil, ocn_flag,heading_use,ocn_dv, ocn_sp, parent, collapsed_level
1833
+ end
1834
+ else
1835
+ if dob.of !=:meta \
1836
+ && dob.of !=:comment \
1837
+ && dob.of !=:layout
1838
+ if ocn_flag == true
1839
+ dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=
1840
+ ocn, ocn_flag,ocn_dv, ocn_sp, parent
1841
+ else
1842
+ ocnu+=1
1843
+ dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj
1844
+ ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}"
1845
+ dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=
1846
+ nil, ocn_flag,ocn_dv, ocn_sp, parent
1847
+ end
1848
+ end
1849
+ end
1850
+ h
1851
+ else dob
1852
+ end
1853
+ if dob.is==:code \
1854
+ || dob.is==:verse \
1855
+ || dob.is==:alt \
1856
+ || dob.is==:box \
1857
+ || dob.is==:group \
1858
+ || dob.is==:block
1859
+ dob.obj=dob.obj.gsub(/\n+/,"\n") #newlines taken out
1860
+ end
1861
+ @o_array << dob
1862
+ end
1863
+ if @process == :complete \
1864
+ or (@fnx == @md.opt.fns \
1865
+ && @md.opt.fns =~/.sst$/)
1866
+ unless @lev_occurences[:a] == 1
1867
+ STDERR.puts %{The number of level A~ in this document: #{@lev_occurences[:a]}
1868
+ There must be one level A~ (no more and no less)
1869
+ SKIPPED processing file:
1870
+ [#{@md.opt.lng}] "#{@md.fns}"}
1871
+ if @md.opt.act[:no_stop][:set]==:on
1872
+ $process_document = :skip
1873
+ else exit
1874
+ end
1875
+ end
1876
+ unless @lev_occurences[:l1] > 0
1877
+ STDERR.puts %{The number of level 1~ in this document: #{@lev_occurences[:l1]}
1878
+ There must be at least one level 1~ (and as many as required)
1879
+ SKIPPED processing file:
1880
+ [#{@md.opt.lng}] "#{@md.fns}"}
1881
+ if @md.opt.act[:no_stop][:set]==:on
1882
+ $process_document = :skip
1883
+ else exit
1884
+ end
1885
+ end
1886
+ end
1887
+ @o_array
1888
+ end
1889
+ end
1890
+ class XML
1891
+ def initialize(md,data)
1892
+ @data,@md=data,md
1893
+ end
1894
+ def dom
1895
+ @s=[ 'A', 'B', 'C', 'D', '1', '2', '3' ]
1896
+ tuned_file=structure_build
1897
+ tuned_file
1898
+ end
1899
+ def spaces
1900
+ Ax[:spaces]
1901
+ end
1902
+ def structure_build
1903
+ data=@data
1904
+ tuned_file=[]
1905
+ hs=[0,false,false,false]
1906
+ t={
1907
+ lv: @s[0],
1908
+ status: :open,
1909
+ }
1910
+ tuned_file << tags(t)
1911
+ if @md.opt.act[:verbose_plus][:set]==:on
1912
+ puts "\nXML sisu structure outline --->\n"
1913
+ puts "<#{@s[0]}>"
1914
+ end
1915
+ data.each_with_index do |o,i|
1916
+ if o.is==:heading \
1917
+ || o.is==:heading_insert
1918
+ case o.ln
1919
+ when 0
1920
+ tuned_file << tag_close(o.ln,hs)
1921
+ tuned_file << tag_open(o,@s)
1922
+ if @md.opt.act[:verbose_plus][:set]==:on
1923
+ puts_tag_close(o.ln,hs)
1924
+ puts_tag_open(o,@s)
1925
+ end
1926
+ hs=[0,true,false,false,false]
1927
+ when 1
1928
+ tuned_file << tag_close(o.ln,hs)
1929
+ tuned_file << tag_open(o,@s)
1930
+ if @md.opt.act[:verbose_plus][:set]==:on
1931
+ puts_tag_close(o.ln,hs)
1932
+ puts_tag_open(o,@s)
1933
+ end
1934
+ hs=[1,true,true,false,false]
1935
+ when 2
1936
+ tuned_file << tag_close(o.ln,hs)
1937
+ tuned_file << tag_open(o,@s)
1938
+ if @md.opt.act[:verbose_plus][:set]==:on
1939
+ puts_tag_close(o.ln,hs)
1940
+ puts_tag_open(o,@s)
1941
+ end
1942
+ hs=[2,true,true,true,false]
1943
+ when 3
1944
+ tuned_file << tag_close(o.ln,hs)
1945
+ tuned_file << tag_open(o,@s)
1946
+ if @md.opt.act[:verbose_plus][:set]==:on
1947
+ puts_tag_close(o.ln,hs)
1948
+ puts_tag_open(o,@s)
1949
+ end
1950
+ hs=[3,true,true,true,true]
1951
+ when 4
1952
+ tuned_file << tag_close(o.ln,hs)
1953
+ tuned_file << tag_open(o,@s)
1954
+ if @md.opt.act[:verbose_plus][:set]==:on
1955
+ puts_tag_close(o.ln,hs)
1956
+ puts_tag_open(o,@s)
1957
+ end
1958
+ hs[0]=4
1959
+ when 5
1960
+ tuned_file << tag_close(o.ln,hs)
1961
+ tuned_file << tag_open(o,@s)
1962
+ if @md.opt.act[:verbose_plus][:set]==:on
1963
+ puts_tag_close(o.ln,hs)
1964
+ puts_tag_open(o,@s)
1965
+ end
1966
+ hs[0]=5
1967
+ when 6
1968
+ tuned_file << tag_close(o.ln,hs)
1969
+ tuned_file << tag_open(o,@s)
1970
+ if @md.opt.act[:verbose_plus][:set]==:on
1971
+ puts_tag_close(o.ln,hs)
1972
+ puts_tag_open(o,@s)
1973
+ end
1974
+ hs[0]=6
1975
+ end
1976
+ end
1977
+ tuned_file << o
1978
+ end
1979
+ if @md.opt.act[:verbose_plus][:set]==:on
1980
+ puts_tag_close(0,hs)
1981
+ end
1982
+ tuned_file << tag_close(0,hs)
1983
+ tuned_file=tuned_file.flatten
1984
+ end
1985
+ def tags(o)
1986
+ tag=(o[:status]==:open) \
1987
+ ? %{<#{o[:lv]} id="#{o[:node]}">}
1988
+ : "</#{o[:lv]}>"
1989
+ ln=case o[:lv]
1990
+ when 'A' then 0
1991
+ when 'B' then 1
1992
+ when 'C' then 2
1993
+ when 'D' then 3
1994
+ when '1' then 4
1995
+ when '2' then 5
1996
+ when '3' then 6
1997
+ when '4' then 7
1998
+ when '5' then 8
1999
+ when '6' then 9
2000
+ end
2001
+ h={
2002
+ tag: tag,
2003
+ node: o[:node],
2004
+ lv: o[:lv],
2005
+ ln: ln,
2006
+ status: o[:status],
2007
+ }
2008
+ SiSU_AO_DocumentStructure::ObjectStructure.new.xml_dom(h) #downstream code utilise else ignore like comments
2009
+ end
2010
+ def tag_open(o,tag)
2011
+ t={ lv: tag[o.ln], node: o.node, status: :open }
2012
+ t_o=tags(t)
2013
+ t_o
2014
+ end
2015
+ def tag_close(lev,hs)
2016
+ ary=[]
2017
+ case hs[0]
2018
+ when 0
2019
+ if (lev <= 0) and hs[0]
2020
+ t={
2021
+ lv: @s[0],
2022
+ status: :close,
2023
+ }
2024
+ ary << tags(t)
2025
+ end
2026
+ when 1
2027
+ if (lev <= 1) and hs[1]
2028
+ t={
2029
+ lv: @s[1],
2030
+ status: :close,
2031
+ }
2032
+ ary << tags(t)
2033
+ end
2034
+ if (lev==0)
2035
+ t={
2036
+ lv: @s[0],
2037
+ status: :close,
2038
+ }
2039
+ ary << tags(t)
2040
+ end
2041
+ when 2
2042
+ if (lev <= 2) and hs[2]
2043
+ t={
2044
+ lv: @s[2],
2045
+ status: :close,
2046
+ }
2047
+ ary << tags(t)
2048
+ end
2049
+ if (lev <= 1) and hs[1]
2050
+ t={
2051
+ lv: @s[1],
2052
+ status: :close,
2053
+ }
2054
+ ary << tags(t)
2055
+ end
2056
+ if (lev==0)
2057
+ t={
2058
+ lv: @s[0],
2059
+ status: :close,
2060
+ }
2061
+ ary << tags(t)
2062
+ end
2063
+ when 3
2064
+ if (lev <= 3) and hs[3]
2065
+ t={
2066
+ lv: @s[3],
2067
+ status: :close,
2068
+ }
2069
+ ary << tags(t)
2070
+ end
2071
+ if (lev <= 2) and hs[2]
2072
+ t={
2073
+ lv: @s[2],
2074
+ status: :close,
2075
+ }
2076
+ ary << tags(t)
2077
+ end
2078
+ if (lev <= 1) and hs[1]
2079
+ t={
2080
+ lv: @s[1],
2081
+ status: :close,
2082
+ }
2083
+ ary << tags(t)
2084
+ end
2085
+ if (lev==0)
2086
+ t={
2087
+ lv: @s[0],
2088
+ status: :close,
2089
+ }
2090
+ ary << tags(t)
2091
+ end
2092
+ when 4
2093
+ if (lev <= 4)
2094
+ t={
2095
+ lv: @s[4],
2096
+ status: :close,
2097
+ }
2098
+ ary << tags(t)
2099
+ end
2100
+ if (lev <= 3) and hs[3]
2101
+ t={
2102
+ lv: @s[3],
2103
+ status: :close,
2104
+ }
2105
+ ary << tags(t)
2106
+ end
2107
+ if (lev <= 2) and hs[2]
2108
+ t={
2109
+ lv: @s[2],
2110
+ status: :close,
2111
+ }
2112
+ ary << tags(t)
2113
+ end
2114
+ if (lev <= 1) and hs[1]
2115
+ t={
2116
+ lv: @s[1],
2117
+ status: :close,
2118
+ }
2119
+ ary << tags(t)
2120
+ end
2121
+ if (lev==0)
2122
+ t={
2123
+ lv: @s[0],
2124
+ status: :close,
2125
+ }
2126
+ ary << tags(t)
2127
+ end
2128
+ when 5
2129
+ if (lev <= 5)
2130
+ t={
2131
+ lv: @s[5],
2132
+ status: :close,
2133
+ }
2134
+ ary << tags(t)
2135
+ end
2136
+ if (lev <= 4)
2137
+ t={
2138
+ lv: @s[4],
2139
+ status: :close,
2140
+ }
2141
+ ary << tags(t)
2142
+ end
2143
+ if (lev <= 3) and hs[3]
2144
+ t={
2145
+ lv: @s[3],
2146
+ status: :close,
2147
+ }
2148
+ ary << tags(t)
2149
+ end
2150
+ if (lev <= 2) and hs[2]
2151
+ t={
2152
+ lv: @s[2],
2153
+ status: :close,
2154
+ }
2155
+ ary << tags(t)
2156
+ end
2157
+ if (lev <= 1) and hs[1]
2158
+ t={
2159
+ lv: @s[1],
2160
+ status: :close,
2161
+ }
2162
+ ary << tags(t)
2163
+ end
2164
+ if (lev==0)
2165
+ t={
2166
+ lv: @s[0],
2167
+ status: :close,
2168
+ }
2169
+ ary << tags(t)
2170
+ end
2171
+ when 6
2172
+ if (lev <= 6)
2173
+ t={
2174
+ lv: @s[6],
2175
+ status: :close,
2176
+ }
2177
+ ary << tags(t)
2178
+ end
2179
+ if (lev <= 5)
2180
+ t={
2181
+ lv: @s[5],
2182
+ status: :close,
2183
+ }
2184
+ ary << tags(t)
2185
+ end
2186
+ if (lev <= 4)
2187
+ t={
2188
+ lv: @s[4],
2189
+ status: :close,
2190
+ }
2191
+ ary << tags(t)
2192
+ end
2193
+ if (lev <= 3) and hs[3]
2194
+ t={
2195
+ lv: @s[3],
2196
+ status: :close,
2197
+ }
2198
+ ary << tags(t)
2199
+ end
2200
+ if (lev <= 2) and hs[2]
2201
+ t={
2202
+ lv: @s[2],
2203
+ status: :close,
2204
+ }
2205
+ ary << tags(t)
2206
+ end
2207
+ if (lev <= 1) and hs[1]
2208
+ t={
2209
+ lv: @s[1],
2210
+ status: :close,
2211
+ }
2212
+ ary << tags(t)
2213
+ end
2214
+ if (lev==0)
2215
+ t={
2216
+ lv: @s[0],
2217
+ status: :close,
2218
+ }
2219
+ ary << tags(t)
2220
+ end
2221
+ end
2222
+ ary
2223
+ end
2224
+ def puts_tag_open(o,tag)
2225
+ puts %{#{spaces*o.ln}<#{tag[o.ln]} id="#{o.node}">}
2226
+ end
2227
+ def puts_tag_close(lev,hs)
2228
+ case hs[0]
2229
+ when 0
2230
+ #puts "#{spaces*0}</#{@s[0]}>" if (lev <= 0) and hs[0]
2231
+ puts "</#{@s[0]}>" if (lev==0)
2232
+ when 1
2233
+ puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
2234
+ puts "</#{@s[0]}>" if (lev==0)
2235
+ when 2
2236
+ puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
2237
+ puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
2238
+ puts "</#{@s[0]}>" if (lev==0)
2239
+ when 3
2240
+ puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
2241
+ puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
2242
+ puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
2243
+ puts "</#{@s[0]}>" if (lev==0)
2244
+ when 4
2245
+ puts "#{spaces*4}</#{@s[4]}>" if (lev <= 4)
2246
+ puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
2247
+ puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
2248
+ puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
2249
+ puts "</#{@s[0]}>" if (lev==0)
2250
+ when 5
2251
+ puts "#{spaces*5}</#{@s[5]}>" if (lev <= 5)
2252
+ puts "#{spaces*4}</#{@s[4]}>" if (lev <= 4)
2253
+ puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
2254
+ puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
2255
+ puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
2256
+ puts "</#{@s[0]}>" if (lev==0)
2257
+ when 6
2258
+ puts "#{spaces*6}</#{@s[6]}>" if (lev <= 6)
2259
+ puts "#{spaces*5}</#{@s[5]}>" if (lev <= 5)
2260
+ puts "#{spaces*4}</#{@s[4]}>" if (lev <= 4)
2261
+ puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
2262
+ puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
2263
+ puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
2264
+ puts "</#{@s[0]}>" if (lev==0)
2265
+ end
2266
+ end
2267
+ end
2268
+ end
2269
+ __END__