1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
=begin
* Name: SiSU
* Description: a framework for document structuring, publishing and search
* Author: Ralph Amissah
* Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007 Ralph Amissah All Rights Reserved.
* License: GPL 3 or later:
SiSU, a framework for document structuring, publishing and search
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007 Ralph Amissah
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
If you have Internet connection, the latest version of the GPL should be
available at these locations:
<http://www.fsf.org/licenses/gpl.html>
<http://www.gnu.org/copyleft/gpl.html>
<http://www.jus.uio.no/sisu/gpl.fsf>
* SiSU uses:
* Standard SiSU markup syntax,
* Standard SiSU meta-markup syntax, and the
* Standard SiSU object citation numbering and system
* Hompages:
<http://www.jus.uio.no/sisu>
<http://www.sisudoc.org>
* Download:
<http://www.jus.uio.no/sisu/SiSU/download.html>
* Ralph Amissah
<ralph@amissah.com>
<ralph.amissah@gmail.com>
** Description: simple xml representation (node style)
=end
module SiSU_simple_xml_model_node
require "#{SiSU_lib}/defaults"
require "#{SiSU_lib}/param"
include SiSU_Param
include SiSU_Viz
require "#{SiSU_lib}/sysenv"
include SiSU_Env
require "#{SiSU_lib}/dal_syntax"
require "#{SiSU_lib}/dal_doc_str"
require "#{SiSU_lib}/shared_xml"
require "#{SiSU_lib}/xml_format"
include SiSU_XML_format
include SiSU_XML_munge
require "#{SiSU_lib}/rexml"
include SiSU_Rexml
@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0
@@tablefoot=''
class Convert
@@fns=nil
def initialize(opt)
@opt=opt
end
def read
begin
@md=SiSU_Param::Parameters.new(@opt).get #bug, relies on info persistence, assumes -m has previously been run
@env=SiSU_Env::Info_env.new(@opt.fns)
path=@env.path.output_tell
loc=@env.url.output_tell
tool=if @opt.cmd =~/[MV]/; "#{Dir.pwd}/#{@md.fn[:sxn]}\n\t#{@env.program.xml_viewer} #{path}/#{@md.fnb}/#{@md.fn[:sxn]}"
elsif @opt.cmd =~/v/; "#{@env.program.web_browser} #{Dir.pwd}/#{@md.fn[:sxn]}"
else ''
end
SiSU_Screen::Ansi.new(@opt.cmd,'invert','XML Node',"#{@md.fns} -> #{@md.fn[:sxn]}").colorize unless @opt.cmd =~/q/
tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{Dir.pwd}/#{@md.fn[:sxn]}")
tell.flow if @opt.cmd =~/[MV]/
unless @@fns==@opt.fns
@@fns=@opt.fns
@@dal_array=[]
end
@dal_array=if @@dal_array.empty?; read_fnm
else @@dal_array.dup #.dup #jokes on you
end
SiSU_simple_xml_model_node::Convert::Songsheet.new(@dal_array,@md,@env).songsheet
rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error
ensure #file closed in songsheet
end
end
def read_fnm
dal=[]
if FileTest.file?("#{Dir.pwd}/#{@opt.fns}")
dal=IO.readlines("#{Dir.pwd}/#{@opt.fns}","\n\n")
else puts 'Error'
end
end
private
class Songsheet
def initialize(data,md,dir)
@data,@md,@env=data,md,dir
end
def songsheet
begin
SiSU_simple_xml_model_node::Convert::Scroll.new(@data,@md).songsheet
SiSU_simple_xml_model_node::Convert::Tidy.new(@md,@env).xml if @md.cmd =~/[vVM]/ # test wellformedness, comment out when not in use
SiSU_Rexml::Rexml.new(@md,@md.fn[:sxn]).xml if @md.cmd =~/M/ # test rexml parsing, comment out when not in use #debug
rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error
ensure
end
end
end
class Scroll
require "#{SiSU_lib}/shared_txt"
require "#{SiSU_lib}/css"
include SiSU_text_utils
@@xml={ :body=>[],:open=>[],:close=>[],:head=>[] }
@@parent={ :ocn=>[],:node=>[] }
@@offspring={ :ocn=>[],:node=>[] }
@@current=nil
def initialize(data='',md=nil)
@data,@md=data,md
@vz=SiSU_Env::Get_init.instance.skin
@regx=/^(?:(?:<:p[bn]>\s*)?(?::?[A-C]~|\d~)(?:(\S+))?\s+)?(.+)/
@tab="\t"
if @md
@env=SiSU_Env::Info_env.new(@md.fns)
@trans=SiSU_XML_munge::Trans.new(@md)
end
@sys=SiSU_Env::System_call.new
@ocn=[]
@node={ :ocn=>[],:no=>[] }
end
def songsheet
pre
markup
post
publish
end
protected
def embedded_endnotes(para='')
para.gsub!(/~\{(.+?)\}~/,'<endnote symbol="norm">\1</endnote> ')
para.gsub!(/~\[([*+])\s+(.+?)\]~/,'<endnote symbol="\1">\2</endnote> ')
end
def xml_head(meta)
txt=meta.text
txt.gsub!(/\/{(.+?)}\//,'<i>\1</i>')
txt.gsub!(/[*!]{(.+?)}[*!]/,'<b>\1</b>')
txt.gsub!(/_{(.+?)}_/,'<u>\1</u>')
txt.gsub!(/-{(.+?)}-/,'<del>\1</del>')
txt.gsub!(/<br(?: \/)?>/,'<br />')
txt.gsub!(/ & /,' and ')
@@xml[:head] <<<<WOK
#{@tab}<header class="#{meta.attrib}">
#{@tab*2}<#{meta.el}>
#{@tab*3}#{txt}
#{@tab*2}</#{meta.el}>
#{@tab}</header>
WOK
end
def xml_sc(md='')
sc=if @md.sc_info
<<WOK
<source_control>
<sc class="sourcefile">
#{@md.sc_filename}
</sc>
<sc class="number">
#{@md.sc_number}
</sc>
<sc class="date">
#{@md.sc_date}
</sc>
</source_control>
WOK
else ''
end
@@xml[:sc]=sc
end
def parent
def node
@@parent[:node]
end
def ocn
@@parent[:ocn]
end
def prt_node
parent.node.each_with_index { |a,n| puts "n.#{n} a.#{a}" unless n == 0 } #x == node
end
def prt_ocn
parent.ocn.each_with_index { |a,n| puts "n.#{n} a.#{a}" unless n == 0 } #x == node
end
self
end
def offspring
def node
@@offspring=if parent.node
@offspring=[]
parent.node.each_with_index do |n,o|
if n
@offspring[n] ||=[]
@offspring[n] << o
end
end
@offspring
else @@offspring
end
end
self
end
def build_relationships(o='',lv='')
if lv.to_s =~/[0-6]/
@node[:ocn][lv]=o.ocn
@node[:no][lv]=o.node
end
if lv.to_s =~/^[1-6]/; @@current=lv
end
if o.node == 1 or lv == 1
@@parent[:node][o.node]=0
elsif @@current == lv and @@current !=nil
if @node[:no][lv-1] != nil
@@parent[:node][o.node]=@node[:no][lv-1]
elsif @node[:no][lv-2] != nil
@@parent[:node][o.node]=@node[:no][lv-2]
elsif @node[:no][lv-3] != nil:
@@parent[:node][o.node]=@node[:no][lv-3]
else puts 'error'
end
elsif lv == nil
if o.ocn.class == Fixnum and @@current
@@parent[:node][o.node]=@node[:no][@@current]
end
else puts 'error'
end
if @@current == lv and @@current !=nil
if @node[:ocn][lv-1] != nil
@@parent[:ocn][o.ocn]=@node[:ocn][lv-1]
elsif @node[:ocn][lv-2] != nil
@@parent[:ocn][o.ocn]=@node[:ocn][lv-2]
elsif @node[:ocn][lv-3] != nil:
@@parent[:ocn][o.ocn]=@node[:ocn][lv-3]
else puts 'error'
end
elsif lv == nil
if o.ocn.class == Fixnum and @@current
@@parent[:ocn][o.ocn]=@node[:ocn][@@current]
end
else puts 'error'
end
end
def node_structure(o='',para='',lv='',hname='') #extracted endnotes
if o.ocn
lv=lv.to_i
lv=nil if lv == 0
build_relationships(o,lv)
end
end
def xml_structure(o='',para='',lv='',hname='') #extracted endnotes
if o.ocn
puts para if lv and @md.cmd =~/M/
lv=lv.to_i
n=lv - 1
n3=lv + 2
lv=nil if lv == 0
embedded_endnotes(para)
if para[@regx]
paragraph="#{para[@regx,2]}"
util=SiSU_text_utils::Wrap.new(paragraph,70)
wrapped=util.line_wrap
end
if @md.cmd =~/[VM]/
if offspring.node[o.node]
puts "#{o.node}::#{parent.node[o.node]}::[#{offspring.node[o.node].join(',')}]"
else
puts "#{o.node}::#{parent.node[o.node]}"
end
end
@@xml[:body] << "#{@tab*0}<object>" if para[@regx]
#@@xml[:body] << "#{@tab*1}<heading>#{lv}</heading>" << "\n" if lv
@@xml[:body] << "#{@tab*1}" << "\n" if para[@regx]
if @md.mod.inspect =~/odf/ #condition not currently present, but consider
@@xml[:body] << %{#{@tab*1}<ocn>#{o.ocn}</ocn>\n}
end
@@xml[:body] << if lv; %{#{@tab*1}<text class="h#{lv}">\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n} << "\n"
elsif wrapped =~/\A%%?\s+/; %{<!--\n#{@tab*1}<text class="comment">\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n-->\n} # comments [not included, review]
else %{#{@tab*1}<text class="norm">\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n} # main text, contents, body KEEP
end
#@@xml[:body] << "#{@tab*1}<text>\n#{@tab*2}#{wrapped}\n#{@tab*1}</text>\n" # main text, contents, body KEEP
@@xml[:body] << "#{@endnotes}" if @endnotes # main text, endnotes KEEP
##@@xml[:body] << "#{@tab*1}<text>#{para[@regx,2]}</text>\n" if para[@regx,2] # old unwrapped main text, contents, body KEEP
@@xml[:body] << %{#{@tab*1}<node>\n}
@@xml[:body] << %{#{@tab*2}<id>#{o.node}</id>\n}
@@xml[:body] << %{#{@tab*2}<parent>#{parent.node[o.node]}</parent>\n}
if offspring.node[o.node]
@@xml[:body] << %{#{@tab*2}<offspring>#{offspring.node[o.node].join(',')}</offspring>\n}
end
@@xml[:body] << %{#{@tab*1}</node>\n}
@@xml[:body] << "#{@tab*0}</object>" << "\n" if para[@regx]
@endnotes=[]
end
end
def group_structure(o='',para='')
para.gsub!(/<:group(?:-end)?>/,'')
para.strip!
@@xml[:body] << %{#{@tab*0}<object>}
if @md.mod.inspect =~/odf/
@@xml[:body] << %{#{@tab*1}<ocn>#{o.ocn}</ocn>\n}
end
@@xml[:body] << %{#{@tab*1}<text class="group">#{@tab*1}\n}
@@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
@@xml[:body] << %{#{@tab*1}</text>\n}
@@xml[:body] << %{#{@tab*1}<node>\n}
@@xml[:body] << %{#{@tab*2}<id>#{o.node}</id>\n}
@@xml[:body] << %{#{@tab*2}<parent>#{parent.node[o.node]}</parent>\n}
if offspring.node[o.node]
@@xml[:body] << %{#{@tab*2}<offspring>#{offspring.node[o.node].join(',')}</offspring>\n}
end
@@xml[:body] << %{#{@tab*1}</node>\n}
@@xml[:body] << "#{@tab*0}</object>"
end
def poem_structure(o='',para='')
para.gsub!(/<:verse(?:-end)?>/,'')
para.strip!
@@xml[:body] << %{#{@tab*0}<object>}
if @md.mod.inspect =~/odf/
@@xml[:body] << %{#{@tab*1}<ocn>#{o.ocn}</ocn>\n}
end
@@xml[:body] << %{#{@tab*1}<text class="verse">#{@tab*1}\n}
@@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
@@xml[:body] << %{#{@tab*1}</text>\n}
@@xml[:body] << %{#{@tab*1}<node>\n}
@@xml[:body] << %{#{@tab*2}<id>#{o.node}</id>\n}
@@xml[:body] << %{#{@tab*2}<parent>#{parent.node[o.node]}</parent>\n}
if offspring.node[o.node]
@@xml[:body] << %{#{@tab*2}<offspring>#{offspring.node[o.node].join(',')}</offspring>\n}
end
@@xml[:body] << %{#{@tab*1}</node>\n}
@@xml[:body] << "#{@tab*0}</object>" << "\n"
end
def code_structure(o='',para='')
para.gsub!(/<:code(?:-end)?>/,'')
para.strip!
@@xml[:body] << %{#{@tab*0}<object>}
if @md.mod.inspect =~/odf/
@@xml[:body] << %{#{@tab*1}<ocn>#{o.ocn}</ocn>\n}
end
@@xml[:body] << %{#{@tab*1}<text class="code">#{@tab*1}\n}
@@xml[:body] << %{#{@tab*2}#{para}#{@tab*1}\n}
@@xml[:body] << %{#{@tab*1}</text>\n}
@@xml[:body] << %{#{@tab*1}<node>\n}
@@xml[:body] << %{#{@tab*2}<id>#{o.node}</id>\n}
@@xml[:body] << %{#{@tab*2}<parent>#{parent.node[o.node]}</parent>\n}
if offspring.node[o.node]
@@xml[:body] << %{#{@tab*2}<offspring>#{offspring.node[o.node].join(',')}</offspring>\n}
end
@@xml[:body] << %{#{@tab*1}</node>\n}
@@xml[:body] << "#{@tab*0}</object>" << "\n"
end
def table_structure(o='',table='') #tables
@@xml[:body] << %{#{@tab*0}<object>}
if @md.mod.inspect =~/odf/
@@xml[:body] << %{#{@tab*1}<ocn>#{o.ocn}</ocn>\n}
end
@@xml[:body] << %{#{@tab*1}#{table}\n#{@tab*1}\n} # unless lv # main text, contents, body KEEP
@@xml[:body] << %{#{@tab*1}<node>\n}
@@xml[:body] << %{#{@tab*2}<id>#{o.node}</id>\n}
@@xml[:body] << %{#{@tab*2}<parent>#{parent.node[o.node]}</parent>\n}
if offspring.node[o.node]
@@xml[:body] << %{#{@tab*2}<offspring>#{offspring.node[o.node].join(',')}</offspring>\n}
end
@@xml[:body] << %{#{@tab*1}</node>\n}
@@xml[:body] << "#{@tab*0}</object>" << "\n" #if para[@regx]
@endnotes=[]
end
def markup
data=[]
@data=@data.join.split("\n\n")
@data=SiSU_document_structure::Code.new(@md,@data).code
@data.each do |para|
data << SiSU_document_structure::Structure.new(@md,para).structure
end
data=Syntax::Markup.new(@md,data).songsheet
data=SiSU_document_structure::Tables.new(@md,data).tables
obj=SiSU_document_structure::OCN.new(@md,data).ocn
obj.compact!
data=nil
dir=SiSU_Env::Info_env.new(@md.fns)
xml_sc(@md)
@endnotes,@level,@cont,@copen,@xml_contents_close=[],[],[],[],[]
@rcdc=false
(0..6).each { |x| @cont[x]=@level[x]=false }
(4..6).each { |x| @xml_contents_close[x]='' }
obj.each do |o|
para=o.txt unless o.txt =~/^%% / #comments are lost, consider
if para
para=@trans.markup_light(para)
@trans.char_enc.utf8(para) if @sys.locale =~/utf-?8/i #% utf8
if para =~/\A(?:@|0~)(\S+?):?\s+(.+?)\Z/m # for headers
d_meta=SiSU_text_utils::Header_scan.new(@md,para).meta
if d_meta; xml_head(d_meta)
end
end
end
end
obj.each do |o|
para=o.txt unless o.txt =~/^%% / #comments are lost, consider
if para
@rcdc=true if @rcdc==false and (para =~/~metadata/ or para =~/^1~meta\s+Document Information/)
if para !~/(^0~|^@\S+?:|^\s*$|<ENDNOTES>|<EOF>)/
@sto=SiSU_text_parts::Split_text_object.new(@md,para).lev_segname_para
unless @rcdc
format_scroll=SiSU_XML_format::Format_scroll.new(@md,@sto.text) if @sto.format =~/i[12]|null/
case @sto.format
when /^(1)~(\S+)?/
node_structure(o,para,$1,$2)
when /^(2)~(\S+)?/
node_structure(o,para,$1,$2)
when /^(3)~(\S+)?/
node_structure(o,para,$1,$2)
when /^(4)~(\S+)?/ # work on see Split_text_object
node_structure(o,para,$1,$2)
when /^(5)~(\S+)?/
node_structure(o,para,$1,$2)
when /^(6)~(\S+)?/
node_structure(o,para,$1,$2)
else
if para =~ /<:verse>/
node_structure(o,para)
elsif para =~ /<:group>/
node_structure(o,para)
elsif para =~ /<:code>/
node_structure(o,para)
elsif para =~/<!Th?.+/ # tables come as single block #work area 2005w13
table=SiSU_Tables::Table_xml.new(para)
para=table.table_split
node_structure(o,para)
else node_structure(o,para,nil,nil)
end
end
end
end
end
end
obj.each do |o|
para=o.txt unless o.txt =~/^%% / #comments are lost, consider
if para
@rcdc=true if @rcdc==false and (para =~/~metadata/ or para =~/^1~meta\s+Document Information/)
if para !~/(^0~|^@\S+?:|^\s*$|<ENDNOTES>|<EOF>)/
@sto=SiSU_text_parts::Split_text_object.new(@md,para).lev_segname_para
unless @rcdc
format_scroll=SiSU_XML_format::Format_scroll.new(@md,@sto.text) if @sto.format =~/i[12]|null/
case @sto.format
when /^(1)~(\S+)?/
xml_structure(o,para,$1,$2)
para=@sto.lev_para_ocn.heading_body1
when /^(2)~(\S+)?/
xml_structure(o,para,$1,$2)
para=@sto.lev_para_ocn.heading_body2
when /^(3)~(\S+)?/
xml_structure(o,para,$1,$2)
para=@sto.lev_para_ocn.heading_body3
when /^(4)~(\S+)?/ # work on see Split_text_object
xml_structure(o,para,$1,$2)
para=@sto.lev_para_ocn.heading_body4
when /^(5)~(\S+)?/
xml_structure(o,para,$1,$2)
para=@sto.lev_para_ocn.heading_body5
when /^(6)~(\S+)?/
xml_structure(o,para,$1,$2)
para=@sto.lev_para_ocn.heading_body6
else
if para =~ /<:verse>/
poem_structure(o,para)
elsif para =~ /<:group>/
group_structure(o,para)
elsif para =~ /<:code>/
para.gsub!(/</,'<')
para.gsub!(/>/,'>')
code_structure(o,para)
elsif para =~/<!Th?.+/ # tables come as single block #work area 2005w13
table=SiSU_Tables::Table_xml.new(para)
para=table.table_split
table_structure(o,para)
else xml_structure(o,para,nil,nil)
end
end
para='' if para =~/<a name="n\d+">/ and para =~/^(-\{{2}~\d+|<!e[:_]\d+!>)/ # -endnote
if para =~/.*<:#>.*$/
para=case para
when /<:i1>/
format_text=Format_text_object.new(para,'')
format_text.scr_inden_ocn_e_no_paranum
when /<:i2>/
format_text=Format_text_object.new(para,'')
format_text.scr_inden_ocn_e_no_paranum
end
end
if para !~/#{@vz.margin_txt_0}|#{@vz.margin_txt_1}|#{@vz.margin_txt_2}/
# i don't get the condition for no paranum
end
if para =~/<:center>/
one,two=/(.*)<:center>(.*)/.match(para)[1,2]
format_text=Format_text_object.new(one,two)
para=format_text.center
end
end
para.gsub!(/<:\S+?>/,'')
para.gsub!(/<!.+!>/,'') ## Clean Prepared Text #bugwatch reinstate
end
end
end
6.downto(4) do |x|
y=x - 1; v=x - 3
@@xml[:body] << "#{@tab*5}</content>\n#{@tab*y}</contents#{v}>\n" if @level[x] == true
end
3.downto(1) do |x|
y=x - 1
@@xml[:body] << "#{@tab*y}</heading#{x}>\n" if @level[x] == true
end
#6.downto(1) { |x| y=x - 1; @@xml[:body] << "#{@tab*y}</level #{x}>\n" if @level[x] == true }
end
def pre
rdf=SiSU_XML_tags::RDF.new(@md)
dir=SiSU_Env::Info_env.new
@@xml[:head],@@xml[:body]=[],[]
css=SiSU_Env::CSS_select.new(@md).xml_sax
encoding=if @sys.locale =~/utf-?8/i; '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
else '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>'
end
@@xml[:open] =<<WOK
#{encoding}
<?xml-stylesheet type="text/css" href="../#{dir.path.style}/#{css}"?>
#{rdf.comment_xml_node}
<document>
WOK
@@xml[:head] << "<head>\n"
@@xml[:body] << "<body>\n"
end
def post
@@xml[:head] << @@xml[:sc]
@@xml[:head] << "</head>\n"
@@xml[:body] << "</body>\n"
@@xml[:close] = "</document>\n"
end
def publish
content=[]
data=@data
content << @@xml[:open] << @@xml[:head] << @@xml[:body] << @@xml[:metadata]
content << @@xml[:owner_details] if @md.stmp =~/\w\w/
content << @@xml[:tail] << @@xml[:close]
Output.new(content.to_s,@md).xml
@@xml={}
end
end
class Output
include SiSU_Param
include SiSU_Env
def initialize(data,md)
@data,@md=data,md
end
def xml
@sisu=[]
@data.each do |para|
para.gsub!(/<:\S+?>/,'')
para.gsub!(/<!.+?!>/,'')
para="#{para}\n" unless para.empty?
@sisu << para
end
new_file_data=@sisu.to_s
@sisu=new_file_data.scan(/.+/)
SiSU_Env::SiSU_file.new(@md).mkdir
filename_sxm=SiSU_Env::SiSU_file.new(@md,@md.fn[:sxn]).mkfile_pwd
if filename_sxm.class == File
@sisu.each {|para| filename_sxm.puts para}
filename_sxm.close
else puts 'file not created, is directory writable?'
end
end
end
class Tidy
def initialize(md,dir)
@md,@env=md,dir
@prog=SiSU_Env::Info_program.new
end
def xml
if @prog.tidy !=false #note values can be other than true
if @md.cmd =~/[VM]/
tell=SiSU_Screen::Ansi.new(@md.cmd,'invert','Using XML Tidy','check document structure')
tell.colorize unless @md.cmd =~/q/
tell.grey_open unless @md.cmd =~/q/
tidyfile='/dev/null' #don't want one or screen output, check for alternative flags
tidy=SiSU_Env::System_call.new("#{Dir.pwd}/#{@md.fn[:sxn]}",tidyfile)
tidy.well_formed?
tell.p_off unless @md.cmd =~/q/
end
end
end
end
end
end
__END__
Notes:
ocn
ocn are given to substantive text objects
nodes
nodes != ocn
nodes are given to every text object (regardless of whether or not it is "substantive" and/or introduced by the editor just for structuring purposes)
nodes are required for a node/tree based representation of content, e.g. a document mapping tool such as kdissert
nodes are given to all structural divisions/headings whether or not they are given an ocn
why arn't all structural divisions given an ocn?
sometimes to structure documents correctly, it is necessary to introduce a dummy level, e.g. using a marker like
4~ [Preamble]-#
these are heading items that are not in the original text, and do not warrant an ocn
they do however require a node value
[at other times the editor introduces a comment that is not to be recognised as a part of the original text]
it is unofortunate that the nature of documents is such that ocn != nodes
[that ocn should be the equivalent of nodes has been rejected]
map
parent <parent>x</parent>
parent of 1 is either 0 or as in kdissert -1 (i prefer 0)
offspring <offspring>x..y</offspring>
siblings - gratuitous, <siblings>x..y</siblings> and therefore optional but might as well
|