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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
#encoding: utf-8
#- Name: SiSU
#
# - Description: documents, structuring, processing, publishing, search
# json
#
# - Author: Ralph Amissah
# <ralph.amissah@gmail.com>
#
# - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
# 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
# 2020, 2021, Ralph Amissah,
# All Rights Reserved.
#
# - License: GPL 3 or later:
#
# SiSU, a framework for document structuring, publishing and search
#
# Copyright (C) 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/licensing/licenses/gpl.html>
# <http://www.gnu.org/licenses/gpl.html>
#
# <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
#
# - SiSU uses:
# - Standard SiSU markup syntax,
# - Standard SiSU meta-markup syntax, and the
# - Standard SiSU object citation numbering and system
#
# - Homepages:
# <http://www.sisudoc.org>
#
# - Git
# <https://git.sisudoc.org/projects/>
# <https://git.sisudoc.org/projects/?p=software/sisu.git;a=summary>
# <https://git.sisudoc.org/projects/?p=markup/sisu-markup-samples.git;a=summary>
module SiSU_JSONutils
require_relative 'generic_parts' # generic_parts.rb
class Clean
def initialize(para='')
@para=para
#@para,@n_char_max,@n_indent,@post,=para,n_char_max,n_indent,post
#@n_char_max_extend = n_char_max
#@n_hang=n_hang ? n_hang : @n_indent
end
def line_json_clean
@para=@para.gsub(/<br>/,' \\ ').
gsub(/#{Mx[:br_nl]}/,"\n\n").
gsub(/"/,'\"').
gsub(/'/,"\\\\'")
@para
end
end
end
module SiSU_JSON_Munge
require_relative 'json_parts' # json_parts.rb
class Trans
include SiSU_Parts_JSON
def initialize(md)
@md=md
@sys=SiSU_Env::SystemCall.new
@dir=SiSU_Env::InfoEnv.new(@md.fns)
if @md.sem_tag
@ab ||=semantic_tags.default
end
end
def semantic_tags
def default
{
pub: 'publication',
conv: 'convention',
vol: 'volume',
pg: 'page',
cty: 'city',
org: 'organization',
uni: 'university',
dept: 'department',
fac: 'faculty',
inst: 'institute',
co: 'company',
com: 'company',
conv: 'convention',
dt: 'date',
y: 'year',
m: 'month',
d: 'day',
ti: 'title',
au: 'author',
ed: 'editor', #editor?
v: 'version', #edition
n: 'name',
fn: 'firstname',
mn: 'middlename',
ln: 'lastname',
in: 'initials',
qt: 'quote',
ct: 'cite',
ref: 'reference',
ab: 'abreviation',
def: 'define',
desc: 'description',
trans: 'translate',
}
end
self
end
def char_enc #character encode
def utf8(dob='')
if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn
str=if defined? dob.obj then dob.obj
elsif dob.is_a?(String) then dob
end
if str
#¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûü
#¢£¥§©ª«®°±²³µ¶¹º»¼½¾×÷
str=str.gsub(/</um,'<'). # '<' # <
gsub(/>/um,'>'). # '>' # >
gsub(/¢/um,'¢'). # '¢' # ¢
gsub(/£/um,'£'). # '£' # £
gsub(/¥/um,'¥'). # '¥' # ¥
gsub(/§/um,'§'). # '§' # §
gsub(/©/um,'©'). # '©' # ©
gsub(/ª/um,'ª'). # 'ª' # ª
gsub(/«/um,'«'). # '«' # «
gsub(/®/um,'®'). # '®' # ®
gsub(/°/um,'°'). # '°' # °
gsub(/±/um,'±'). # '±' # ±
gsub(/²/um,'²'). # '²' # ²
gsub(/³/um,'³'). # '³' # ³
gsub(/µ/um,'µ'). # 'µ' # µ
gsub(/¶/um,'¶'). # '¶' # ¶
gsub(/¹/um,'¹'). # '¹' # ¹
gsub(/º/um,'º'). # 'º' # º
gsub(/»/um,'»'). # '»' # »
gsub(/¼/um,'¼'). # '¼' # ¼
gsub(/½/um,'½'). # '½' # ½
gsub(/¾/um,'¾'). # '¾' # ¾
gsub(/×/um,'×'). # '×' # ×
gsub(/÷/um,'÷'). # '÷' # ÷
gsub(/¿/um,'¿'). # '¿' # ¿
gsub(/À/um,'À'). # 'À' # À
gsub(/Á/um,'Á'). # 'Á' # Á
gsub(/Â/um,'Â'). # 'Â' # Â
gsub(/Ã/um,'Ã'). # 'Ã' # Ã
gsub(/Ä/um,'Ä'). # 'Ä' # Ä
gsub(/Å/um,'Å'). # 'Å' # Å
gsub(/Æ/um,'Æ'). # 'Æ' # Æ
gsub(/Ç/um,'Ç'). # 'Ç' # Ç
gsub(/È/um,'È'). # 'È' # È
gsub(/É/um,'É'). # 'É' # É
gsub(/Ê/um,'Ê'). # 'Ê' # Ê
gsub(/Ë/um,'Ë'). # 'Ë' # Ë
gsub(/Ì/um,'Ì'). # 'Ì' # Ì
gsub(/Í/um,'Í'). # 'Í' # Í
gsub(/Î/um,'Î'). # 'Î' # Î
gsub(/Ï/um,'Ï'). # 'Ï' # Ï
gsub(/Ð/um,'Ð'). # 'Ð' # Ð
gsub(/Ñ/um,'Ñ'). # 'Ñ' # Ñ
gsub(/Ò/um,'Ò'). # 'Ò' # Ò
gsub(/Ó/um,'Ó'). # 'Ó' # Ó
gsub(/Ô/um,'Ô'). # 'Ô' # Ô
gsub(/Õ/um,'Õ'). # 'Õ' # Õ
gsub(/Ö/um,'Ö'). # 'Ö' # Ö
gsub(/Ø/um,'Ø'). # 'Ø' # Ø
gsub(/Ù/um,'Ù'). # 'Ù' # Ù
gsub(/Ú/um,'Ú'). # 'Ú' # Ú
gsub(/Û/um,'Û'). # 'Û' # Û
gsub(/Ü/um,'Ü'). # 'Ü' # Ü
gsub(/Ý/um,'Ý'). # 'Ý' # Ý
gsub(/Þ/um,'Þ'). # 'Þ' # Þ
gsub(/ß/um,'ß'). # 'ß' # ß
gsub(/à/um,'à'). # 'à' # à
gsub(/á/um,'á'). # 'á' # á
gsub(/â/um,'â'). # 'â' # â
gsub(/ã/um,'ã'). # 'ã' # ã
gsub(/ä/um,'ä'). # 'ä' # ä
gsub(/å/um,'å'). # 'å' # å
gsub(/æ/um,'æ'). # 'æ' # æ
gsub(/ç/um,'ç'). # 'ç' # ç
gsub(/è/um,'è'). # 'è' # è
gsub(/é/um,'é'). # '´' # é
gsub(/ê/um,'ê'). # 'ˆ' # ê
gsub(/ë/um,'ë'). # 'ë' # ë
gsub(/ì/um,'ì'). # 'ì' # ì
gsub(/í/um,'í'). # '´' # í
gsub(/î/um,'î'). # 'î' # î
gsub(/ï/um,'ï'). # 'ï' # ï
gsub(/ð/um,'ð'). # 'ð' # ð
gsub(/ñ/um,'ñ'). # 'ñ' # ñ
gsub(/ò/um,'ò'). # 'ò' # ò
gsub(/ó/um,'ó'). # 'ó' # ó
gsub(/ô/um,'ô'). # 'ô' # ô
gsub(/õ/um,'õ'). # 'õ' # õ
gsub(/ö/um,'ö'). # 'ö' # ö
gsub(/ø/um,'ø'). # 'ø' # ø
gsub(/ù/um,'ú'). # 'ù' # ú
gsub(/ú/um,'û'). # 'ú' # û
gsub(/û/um,'ü'). # 'û' # ü
gsub(/ü/um,'ý'). # 'ü' # ý
gsub(/þ/um,'þ'). # 'þ' # þ
gsub(/ÿ/um,'ÿ'). # 'ÿ' # ÿ
gsub(/‘/um,'‘'). # '‘' # ‘
gsub(/’/um,'’'). # '’' # ’
gsub(/“/um,'“'). # “ # “
gsub(/”/um,'”'). # ” # ”
gsub(/–/um,'–'). # – # –
gsub(/—/um,'—'). # — # —
gsub(/∝/um,'∝'). # ∝ # ∝
gsub(/∞/um,'∞'). # ∞ # ∞
gsub(/™/um,'™'). # ™ # ™
gsub(/✠/um,'✠'). # ✗ # ✠
gsub(/ /um,' '). # space identify
gsub(/ /um,' ') # space identify
end
dob=if defined? dob.obj
dob.obj=str
dob
elsif dob.is_a?(String)
str
end
dob
end
end
def html(dob='')
if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn
dob.obj=dob.obj.gsub(/ /u,' '). # space identify
gsub(/ /u,' ') # space identify
end
end
self
end
def tidywords(wordlist)
wordlist_new=[]
wordlist.each do |x|
#imperfect solution will not catch all possible cases
x=x.gsub(/&/,'&') unless x =~/&\S+;/
x=x.gsub(/&([A-Z])/,'&\1')
wordlist_new << x
end
wordlist_new
end
def markup(dob='')
wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17
dob.obj=tidywords(wordlist).join(' ').strip
unless dob.is==:table
dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/u,'<br>').
gsub(/#{Mx[:br_paragraph]}/u,'<br>').
gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'<br>')
end
dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}/,'').
gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;').
gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;').
gsub(/(^|#{Mx[:gl_c]}|\s+)<\s+/,'\1< ').gsub(/\s+>(\s+|$)/,' >\1').
#gsub(/#{Mx[:fa_emphasis_o]}(.+?)#{Mx[:fa_emphasis_c]}/,'<em>\1</em>'). #reinstate
gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/m,'<b>\1</b>').
gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/m,'<i>\1</i>').
gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>').
gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>').
gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>').
gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'<ins>\1</ins>').
gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'<cite>\1</cite>').
gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'<del>\1</del>').
gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>').
gsub(/<:pb>\s*/,''). #Fix
gsub(/<+[-~]#>+/,'')
if dob.is !=:code
#embeds a red-bullet image -->
dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>').
gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>').
gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>').
gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'<del>\1</del>')
dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'<br>') unless dob.is==:table
dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*/,'').
gsub(/#{Mx[:br_page_new]}\s*/,'').
gsub(/#{Mx[:br_page_line]}\s*/,'').
gsub(/#{Mx[:pa_non_object_no_heading]}|#{Mx[:pa_non_object_dummy_heading]}/,'').
gsub(/<[-~]#>/,'').
gsub(/href="#{Xx[:segment]}/m,'href="').
gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/,
'<link xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:href="\2">\1</link>').
gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/,
'<link xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:href="../\2">\1</link>').
gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/,
'<link xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:href="#\2">\1</link>').
gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
%{<image xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:actuate="onLoad" xl:show="embed" xl:href="#{@md.file.output_path.xml.rel_image}/\\1" width="\\2" height="\\3" />[\\1] \\4}).
gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
%{<image xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:actuate="onLoad" xl:show="embed" xl:href="#{@md.file.output_path.xml.rel_image}/\\1"/>\\1}).
gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}image/,
%{<image xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:actuate="onLoad" xl:show="embed" xl:href="#{@md.file.output_path.xml.rel_image}/\\1" width="\\2" height="\\3" />[\\1] \\4}).
gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}image/,
%{<image xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:actuate="onLoad" xl:show="embed" xl:href="#{@md.file.output_path.xml.rel_image}/\\1"/>\\1}).
gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
'<link xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:href="\2">\1</link>'). #watch, compare html_tune
gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
%{#{the_url_decoration.xml_open}<link xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:href="\\1">\\1</link>#{the_url_decoration.xml_close}}).
gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
'<link xmlns:xl="http://www.w3.org/1999/xlink" xl:type="simple" xl:href="\1">\1</link>') #escaped urls not linked, deal with later
else
dob.obj=dob.obj.gsub(/</m,'<').gsub(/>/m,'>')
end
if dob.of==:block
dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ')
end
dob.obj=dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/,
%{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}).
gsub(/#{Dx[:url_o]}/,"#{Dx[:url_o_xml]}").
gsub(/#{Dx[:url_c]}/,"#{Dx[:url_c_xml]}").
gsub(/ |#{Mx[:nbsp]}/m,' ').
gsub(/;&([^#]|(?:[^gl][^t]|[^a][^m][^p]|[^n][^b][^s][^p])[^;])/,';&\1') # pattern not to match
dob
end
def markup_light(dob='')
dob.obj=dob.obj.gsub(/\/\{(.+?)\}\//,'<i>\1</i>').
gsub(/[*!]\{(.+?)\}[*!]/,'<b>\1</b>').
gsub(/_\{(.+?)\}_/,'<u>\1</u>').
gsub(/-\{(.+?)\}-/,'<del>\1</del>').
gsub(/<br(\s*\/)?>/,'<br>').
gsub(/<:pb>\s*/,'').
gsub(/<[-~]#>/,'').
gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort
gsub(/&([^;]{1,5})/,'&\1'). #sort, rough estimate, revisit #WATCH found in node not sax
gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,
"<image.path>#{@md.file.output_path.xml.rel_image}\/\\1</image.path>").
gsub(/ |#{Mx[:nbsp]}/,' ').
gsub(/;&([^#]|(?:[^gl][^t]|[^a][^m][^p]|[^n][^b][^s][^p])[^;])/,';&\1') # pattern not to match
wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17
dob.obj=tidywords(wordlist).join(' ').strip
dob
end
def clean(str)
str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;')
end
def markup_fictionbook(str='',is='')
str=str.gsub(/#{Mx[:en_a_o]}([\d+*]+).+?#{Mx[:en_a_c]}/m,'<a xl:href="#footnote\1" type="note">[\1]</a>').
gsub(/&/,'&'). #sort
gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;').
gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort
gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;')
str=str.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'<br>') unless is==:table
str=str.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>').
gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>').
gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>').
gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>').
gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>').
gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'<ins>\1</ins>').
gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'<cite>\1</cite>').
gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'<del>\1</del>').
gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>'). # tt, kbd
gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,'<image xl:href="#\1" />').
gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}").
gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,'<a name="\1"></a>').
gsub(/#{Mx[:gl_bullet]}/m,'● '). # not available
gsub(/#{Mx[:nbsp]}/,' '). # not available
gsub(/<(p|br)>/,'<\1 />')
clean(str)
end
def markup_docbook(dob='') # work on, initially a copy of fictionbook!
if dob.is !=:code
dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s*(.+?)#{Mx[:en_a_c]}/m,'<footnote><para><!-- fn\1 -->\2</para></footnote>').
gsub(/\\\\/,'</para><para>').
gsub(/&/,'&'). #sort
gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;').
gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort
gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;')
dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'<br>') unless dob.is==:table
dob.obj=dob.obj.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>').
gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>').
gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>').
gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>').
gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>').
gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'<ins>\1</ins>').
gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'<cite>\1</cite>').
gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'<del>\1</del>').
gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>'). # tt, kbd
gsub(/#{Mx[:lnk_o]}\s*(\S+?)\.(png|jpg|gif).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,
%{#{Xx[:split]}:spaces0:<figure id="fig-\\1">\n:spaces1:<title></title>\n:spaces1:<graphic fileref="../../_sisu/image/\\1.\\2" align="center" width="50%"></graphic>\n:spaces0:</figure>#{Xx[:split]}}). # common image location, else use ./images
gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,
'<ulink url="\2">\1</ulink>').
gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,
'<ulink url="\1">\1</ulink>').
gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,'<a name="\1"></a>').
gsub(/#{Mx[:gl_bullet]}/m,'● '). # not available
gsub(/#{Mx[:nbsp]}/,' '). # not available
gsub(/<(p|br)>/,'<\1 />')
dob.obj=clean(dob.obj)
elsif dob.is == :code
dob.obj=dob.obj.gsub(/&/m,'&'). #sort
gsub(/</,'<').gsub(/>/,'>')
else # p dob.is ??
end
dob
end
def markup_group(dob='')
dob.obj=dob.obj.gsub(/</,'<').gsub(/>/,'>').
gsub(/<:?br(?:\s+\/)?>/,'<br>').
gsub(/<(link xmlns:xl=".+?")>/,'<\1>').
gsub(/<(\/link)>/,'<\1>').
gsub(/<(\/?en)>/,'<\1>')
dob
end
def markup_block(dob='')
dob.obj=dob.obj.gsub(/</,'<').gsub(/>/,'>').
gsub(/<:?br(?:\s+\/)?>/,'<br>').
gsub(/<(link xmlns:xl=".+?")>/,'<\1>').
gsub(/<(\/link)>/,'<\1>').
gsub(/<(\/?en)>/,'<\1>')
dob
end
def xml_sem_block_paired(matched) # colon depth: many, recurs
matched=matched.gsub(/\b(au):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:au]} depth="many">\\2</sem:#{@ab[:au]}>}).
gsub(/\b(vol):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:vol]} depth="many">\\2</sem:#{@ab[:vol]}>}).
gsub(/\b(pub):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:pub]} depth="many">\\2</sem:#{@ab[:pub]}>}).
gsub(/\b(ref):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:ref]} depth="many">\\2</sem:#{@ab[:ref]}>}).
gsub(/\b(desc):\{(.+?)\}:\1\b/m,%{<sem:#{@ab[:desc]} depth="many">\\2</sem:#{@ab[:desc]}>}).
gsub(/\b(conv):\{(.+?)\}:\1\b/m,%{<sem:#{@ab[:conv]} depth="many">\\2</sem:#{@ab[:conv]}>}).
gsub(/\b(ct):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:ct]} depth="many">\\2</sem:#{@ab[:ct]}>}).
gsub(/\b(cty):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:cty]} depth="many">\\2</sem:#{@ab[:cty]}>}).
gsub(/\b(org):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:org]} depth="many">\\2</sem:#{@ab[:org]}>}).
gsub(/\b(dt):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:dt]} depth="many">\\2</sem:#{@ab[:dt]}>}).
gsub(/\b(n):\{(.+?)\}:\1\b/m, %{<sem:#{@ab[:n]} depth="many">\\2</sem:#{@ab[:n]}>}).
gsub(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m,'<sem:\1 depth="many">\2</sem:\1>')
end
def xml_semantic_tags(dob)
if @md.sem_tag
dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) }
dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) }
dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) }
dob.obj=dob.obj.gsub(/:\{(.+?)\}:au\b/m, %{<sem:#{@ab[:au]} depth="one">\\1</sem:#{@ab[:au]}>}).
gsub(/:\{(.+?)\}:n\b/m, %{<sem:#{@ab[:n]} depth="one">\\1</sem:#{@ab[:n]}>}).
gsub(/:\{(.+?)\}:ti\b/m, %{<sem:#{@ab[:ti]} depth="one">\\1</sem:#{@ab[:ti]}>}).
gsub(/:\{(.+?)\}:ref\b/m, %{<sem:#{@ab[:ref]} depth="one">\\1</sem:#{@ab[:ref]}>}).
gsub(/:\{(.+?)\}:desc\b/m, %{<sem:#{@ab[:desc]} depth="one">\\1</sem:#{@ab[:desc]}>}).
gsub(/:\{(.+?)\}:cty\b/m, %{<sem:#{@ab[:cty]} depth="one">\\1</sem:#{@ab[:cty]}>}).
gsub(/:\{(.+?)\}:org\b/m, %{<sem:#{@ab[:org]} depth="one">\\1</sem:#{@ab[:org]}>}).
gsub(/:\{(.+?)\}:([a-z]+(?:[_:.][a-z]+)*)/m,'<sem:\2 depth="one">\1</sem:\2>').
gsub(/;\{([^}]+(?![;]))\};ti\b/m, %{<sem:#{@ab[:ti]} depth="zero">\\1</sem:#{@ab[:ti]}>}).
gsub(/;\{([^}]+(?![;]))\};qt\b/m, %{<sem:#{@ab[:qt]} depth="zero">\\1</sem:#{@ab[:qt]}>}).
gsub(/;\{([^}]+(?![;]))\};ref\b/m, %{<sem:#{@ab[:ref]} depth="zero">\\1</sem:#{@ab[:ref]}>}).
gsub(/;\{([^}]+(?![;]))\};ed\b/m, %{<sem:#{@ab[:ed]} depth="zero">\\1</sem:#{@ab[:ed]}>}).
gsub(/;\{([^}]+(?![;]))\};v\b/m, %{<sem:#{@ab[:v]} depth="zero">\\1</sem:#{@ab[:v]}>}).
gsub(/;\{([^}]+(?![;]))\};desc\b/m, %{<sem:#{@ab[:desc]} depth="zero">\\1</sem:#{@ab[:desc]}>}).
gsub(/;\{([^}]+(?![;]))\};def\b/m, %{<sem:#{@ab[:def]} depth="zero">\\1</sem:#{@ab[:def]}>}).
gsub(/;\{([^}]+(?![;]))\};trans\b/m, %{<sem:#{@ab[:trans]} depth="zero">\\1</sem:#{@ab[:trans]}>}).
gsub(/;\{([^}]+(?![;]))\};y\b/m, %{<sem:#{@ab[:y]} depth="zero">\\1</sem:#{@ab[:y]}>}).
gsub(/;\{([^}]+(?![;]))\};ab\b/m, %{<sem:#{@ab[:ab]} depth="zero">\\1</sem:#{@ab[:ab]}>}).
gsub(/;\{([^}]+(?![;]))\};pg\b/m, %{<sem:#{@ab[:pg]} depth="zero">\\1</sem:#{@ab[:pg]}>}).
gsub(/;\{([^}]+(?![;]))\};fn?\b/m, %{<sem:#{@ab[:fn]} depth="zero">\\1</sem:#{@ab[:fn]}>}).
gsub(/;\{([^}]+(?![;]))\};mn?\b/m, %{<sem:#{@ab[:mn]} depth="zero">\\1</sem:#{@ab[:mn]}>}).
gsub(/;\{([^}]+(?![;]))\};ln?\b/m, %{<sem:#{@ab[:ln]} depth="zero">\\1</sem:#{@ab[:ln]}>}).
gsub(/;\{([^}]+(?![;]))\};in\b/m, %{<sem:#{@ab[:in]} depth="zero">\\1</sem:#{@ab[:in]}>}).
gsub(/;\{([^}]+(?![;]))\};uni\b/m, %{<sem:#{@ab[:uni]} depth="zero">\\1</sem:#{@ab[:uni]}>}).
gsub(/;\{([^}]+(?![;]))\};fac\b/m, %{<sem:#{@ab[:fac]} depth="zero">\\1</sem:#{@ab[:fac]}>}).
gsub(/;\{([^}]+(?![;]))\};inst\b/m, %{<sem:#{@ab[:inst]} depth="zero">\\1</sem:#{@ab[:inst]}>}).
gsub(/;\{([^}]+(?![;]))\};dept\b/m, %{<sem:#{@ab[:dpt]} depth="zero">\\1</sem:#{@ab[:dept]}>}).
gsub(/;\{([^}]+(?![;]))\};org\b/m, %{<sem:#{@ab[:org]} depth="zero">\\1</sem:#{@ab[:org]}>}).
gsub(/;\{([^}]+(?![;]))\};com?\b/m, %{<sem:#{@ab[:com]} depth="zero">\\1</sem:#{@ab[:com]}>}).
gsub(/;\{([^}]+(?![;]))\};cty\b/m, %{<sem:#{@ab[:cty]} depth="zero">\\1</sem:#{@ab[:cty]}>}).
gsub(/;\{([^}]+(?![;]))\};([a-z]+(?:[_:.][a-z]+)*)/m,'<sem:\2 depth="zero">\1</sem:\2>')
end
dob
end
end
end
module SiSU_XML_Tags #Format
require_relative 'dp' # dp.rb
include SiSU_Param
class RDF
include SiSU_Parts_JSON
def initialize(md='',seg_name=[],tracker=0)
@full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords=''
@md=md
@rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n}
if defined? @md.title.full \
and @md.title.full # DublinCore 1 - title
@rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n}
@full_title=%{ <meta name="dc.title" content="#{@md.title.full}" />\n}
end
if defined? @md.creator.author \
and @md.creator.author=~/\S+/ # DublinCore 2 - creator/author (author)
@rdf_author=%{ dc.author="#{@md.creator.author}"\n}
content=meta_content_clean(@md.creator.author)
@author=%{ <meta name="dc.author" content="#{content}" />\n}
end
if defined? @md.publisher \
and @md.publisher # DublinCore 5 - publisher (current copy published by)
@rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n}
content=meta_content_clean(@md.publisher)
@publisher=%{ <meta name="dc.publisher" content="#{content}" />\n}
end
if defined? @md.creator.contributor \
and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor
@rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n}
content=meta_content_clean(@md.creator.contributor)
@contributor=%{ <meta name="dc.contributor" content="#{content}" />\n}
end
if defined? @md.date.published \
and @md.date.published=~/\S+/ # DublinCore 7 - date year-mm-dd
@rdf_date=%{ dc.date="#{@md.date.published}"\n}
@date=%{ <meta name="dc.date" content="#{@md.date.published}" #{@md.date_scheme} />\n} # fix @md.date_scheme
end
if defined? @md.date.created \
and @md.date.created=~/\S+/ # DublinCore 7 - date.created year-mm-dd
@rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n}
@date_created=%{ <meta name="dc.date.created" content="#{@md.date.created}" #{@md.date_scheme} />\n}
end
if defined? @md.date.issued \
and @md.date.issued=~/\S+/ # DublinCore 7 - date.issued year-mm-dd
@rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n}
@date_issued=%{ <meta name="dc.date.issued" content="#{@md.date.issued}" #{@md.date_scheme} />\n}
end
if defined? @md.date.available \
and @md.date.available=~/\S+/ # DublinCore 7 - date.available year-mm-dd
@rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n}
@date_available=%{ <meta name="dc.date.available" content="#{@md.date.available}" #{@md.date_scheme} />\n}
end
if defined? @md.date.valid \
and @md.date.valid=~/\S+/ # DublinCore 7 - date.valid year-mm-dd
@rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n}
@date_valid=%{ <meta name="dc.date.valid" content="#{@md.date.valid}" #{@md.date_scheme} />\n}
end
if defined? @md.date.modified \
and @md.date.modified=~/\S+/ # DublinCore 7 - date.modified year-mm-dd
@rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n}
@date_modified=%{ <meta name="dc.date.modified" content="#{@md.date.modified}" #{@md.date_scheme} />\n}
end
if defined? @md.rights.all \
and @md.rights.all # DublinCore 15 - rights
@rdf_rights=%{ dc.rights="#{@md.rights.all}"\n}
content=meta_content_clean(@md.rights.all)
@rights=%{ <meta name="dc.rights" content="#{content}" />\n}
end
if defined? @md.classify.subject \
and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???)
@rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n}
content=meta_content_clean(@md.classify.subject)
@subject=%{ <meta name="dc.subject" content="#{content}" />\n}
end
if defined? @md.notes.description \
and @md.notes.description=~/\S+/ # DublinCore 4 - description
@rdf_description=%{ dc.description="#{@md.notes.description}"\n}
content=meta_content_clean(@md.notes.description)
@description=%{ <meta name="dc.description" content="#{content}" />\n}
end
if defined? @md.notes.coverage \
and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage
@rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n}
content=meta_content_clean(@md.notes.coverage)
@coverage=%{ <meta name="dc.coverage" content="#{content}" />\n}
end
if defined? @md.notes.relation \
and @md.notes.relation=~/\S+/ # DublinCore 13 - relation
@rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n}
content=meta_content_clean(@md.notes.relation)
@relation=%{ <meta name="dc.relation" content="#{content}" />\n}
end
if defined? @md.notes.type \
and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc)
@rdf_type=%{ dc.type="#{@md.notes.type}"\n}
content=meta_content_clean(@md.notes.type)
@type=%{ <meta name="dc.type" content="#{content}" />\n}
end
if defined? @md.notes.format \
and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type)
@rdf_format=%{ dc.format="#{@md.notes.format}"\n}
content=meta_content_clean(@md.notes.format)
@format=%{ <meta name="dc.format" content="#{content}" />\n}
end
#if defined? @md.identifier.sisupod \
#and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free)
# @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n}
# content=meta_content_clean(@md.identifier.sisupod)
# @identifier=%{ <meta name="dc.identifier" content="#{content}" />\n}
#end
if defined? @md.original.source \
and @md.original.source=~/\S+/ # DublinCore 11 - source (document source)
@rdf_source=%{ dc.source="#{@md.original.source}"\n}
content=meta_content_clean(@md.original.source)
@source=%{ <meta name="dc.source" content="#{content}" />\n}
end
if defined? @md.title.language \
and @md.title.language=~/\S+/ # DublinCore 12 - language (English)
@rdf_language=%{ dc.language="#{@md.title.language}"\n}
@language=%{ <meta name="dc.language" content="#{@md.title.language}" />\n}
end
if defined? @md.original.language \
and @md.original.language=~/\S+/
@rdf_language_original=%{ dc.language="#{@md.original.language}"\n}
@language_original=%{ <meta name="dc.language" content="#{@md.original.language}" />\n}
end
content=meta_content_clean(@md.keywords)
@keywords=%{ <meta name="keywords" content="#{content}" />\n} if @md.keywords
end
def meta_content_clean(content='')
content=if not content.nil?
content=content.tr('"',"'").
gsub(/&/,'&')
content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content)
else content
end
end
def rdfseg #segHead
rdftoc
end
def comment_xml(extra='')
generator="Generated by: #{@md.project_details.project} #{@md.project_details.version} of #{@md.project_details.date_stamp} (#{@md.project_details.date})" if @md.project_details.version
lastdone="Last Generated on: #{Time.now}"
rubyv="Ruby version: #{@md.ruby_version}"
sc=if @md.sc_info
"Source file: #{@md.sc_filename} version: #{@md.sc_number} of: #{@md.sc_date}"
else ''
end
if extra.empty?
<<WOK
<!-- Document processing information:
* #{generator}
* #{rubyv}
* #{sc}
* #{lastdone}
* SiSU http://www.jus.uio.no/sisu
-->
WOK
else
<<WOK
<!-- Document processing information:
* #{extra}
* #{generator}
* #{rubyv}
* #{sc}
* #{lastdone}
* SiSU http://www.jus.uio.no/sisu
-->
WOK
end
end
def comment_xml_sax
desc='SiSU XML, SAX type representation'
comment_xml(desc)
end
def comment_xml_node
desc='SiSU XML, Node type representation'
comment_xml(desc)
end
def comment_xml_dom
desc='SiSU XML, DOM type representation'
comment_xml(desc)
end
def metatag_html #values strung together, because some empty, and resulting output (line breaks) is much better
<<WOK
#{@full_title}#{@subtitle}#{@author}#{@subject}#{@description}#{@publisher}#{@contributor}#{@date}#{@date_created}#{@date_issued}#{@date_available}#{@date_valid}#{@date_modified}#{@type}#{@format}#{@identifier}#{@source}#{@language}#{@relation}#{@coverage}#{@rights}#{@copyright}#{@owner}
#{SiSU_Proj_XML::Bits.new.txt_generator}
#{the_png.ico}
WOK
end
end
end
module SiSU_JSON_Shared
require_relative 'xhtml_table' # xhtml_table.rb
class TableJSON < SiSU_XHTML_Table::TableXHTML
end
end
__END__
|