cbeta 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/cbeta/p5a_to_html.rb +46 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfc12285c99810aa4898a53ba9a365067e9e2243
|
4
|
+
data.tar.gz: c72ba6cc3008b2209bf94b6461e22014418b5e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a5c617c28539e12a682b57a0d667382bd39b3aa1d0ea425984e8ab07aa384be9f3a4bbe492ed3b032c82754edc8fef09a733685028fd33ebd8c853872696a0
|
7
|
+
data.tar.gz: 5ab185de9728e68d949aeac191beb9d92ed26cb41892fa03c02b132fdd486bc1cc3b286f37a93771f2638e39dad5f6df97bca30b05fdcc9d26811a0437382468
|
data/lib/cbeta/p5a_to_html.rb
CHANGED
@@ -49,10 +49,10 @@ class CBETA::P5aToHTML
|
|
49
49
|
# x2h.convert('T05..T07')
|
50
50
|
#
|
51
51
|
# T 是大正藏的 ID, CBETA 的藏經 ID 系統請參考: http://www.cbeta.org/format/id.php
|
52
|
-
def convert(
|
53
|
-
return convert_all if
|
52
|
+
def convert(target=nil)
|
53
|
+
return convert_all if target.nil?
|
54
54
|
|
55
|
-
arg.upcase
|
55
|
+
arg = target.upcase
|
56
56
|
if arg.size == 1
|
57
57
|
handle_collection(arg)
|
58
58
|
else
|
@@ -114,6 +114,15 @@ class CBETA::P5aToHTML
|
|
114
114
|
r + '</p>'
|
115
115
|
end
|
116
116
|
|
117
|
+
def handle_cell(e)
|
118
|
+
doc = Nokogiri::XML::Document.new
|
119
|
+
cell = doc.create_element('td')
|
120
|
+
cell['rowspan'] = e['rows'] if e.key? 'rows'
|
121
|
+
cell['colspan'] = e['rows'] if e.key? 'cols'
|
122
|
+
cell.inner_html = traverse(e)
|
123
|
+
cell.to_s
|
124
|
+
end
|
125
|
+
|
117
126
|
def handle_collection(c)
|
118
127
|
@series = c
|
119
128
|
puts 'handle_collection ' + c
|
@@ -301,7 +310,12 @@ class CBETA::P5aToHTML
|
|
301
310
|
r += "</div><!-- end of lg-row -->"
|
302
311
|
@lg_row_open = false
|
303
312
|
end
|
304
|
-
r
|
313
|
+
r += "<span class='lb' \nid='#{line_head}'>#{line_head}</span>"
|
314
|
+
unless @next_line_buf.empty?
|
315
|
+
r += @next_line_buf
|
316
|
+
@next_line_buf = ''
|
317
|
+
end
|
318
|
+
r
|
305
319
|
end
|
306
320
|
|
307
321
|
def handle_lem(e)
|
@@ -383,6 +397,7 @@ class CBETA::P5aToHTML
|
|
383
397
|
when 'anchor' then handle_anchor(e)
|
384
398
|
when 'app' then handle_app(e)
|
385
399
|
when 'byline' then handle_byline(e)
|
400
|
+
when 'cell' then handle_cell(e)
|
386
401
|
when 'corr' then handle_corr(e)
|
387
402
|
when 'div' then handle_div(e)
|
388
403
|
when 'figure' then handle_figure(e)
|
@@ -403,15 +418,16 @@ class CBETA::P5aToHTML
|
|
403
418
|
when 'p' then handle_p(e)
|
404
419
|
when 'rdg' then ''
|
405
420
|
when 'reg' then ''
|
421
|
+
when 'row' then handle_row(e)
|
406
422
|
when 'sic' then ''
|
407
423
|
when 'sg' then handle_sg(e)
|
408
424
|
when 't' then handle_t(e)
|
425
|
+
when 'table' then handle_table(e)
|
409
426
|
else traverse(e)
|
410
427
|
end
|
411
428
|
r
|
412
429
|
end
|
413
430
|
|
414
|
-
|
415
431
|
def handle_note(e)
|
416
432
|
n = e['n']
|
417
433
|
if e.has_attribute?('type')
|
@@ -462,12 +478,16 @@ class CBETA::P5aToHTML
|
|
462
478
|
r + '</p>'
|
463
479
|
end
|
464
480
|
|
481
|
+
def handle_row(e)
|
482
|
+
"<tr>" + traverse(e) + "</tr>"
|
483
|
+
end
|
484
|
+
|
465
485
|
def handle_sg(e)
|
466
486
|
'(' + traverse(e) + ')'
|
467
487
|
end
|
468
488
|
|
469
489
|
def handle_sutra(xml_fn)
|
470
|
-
puts "
|
490
|
+
puts "convert sutra #{xml_fn}"
|
471
491
|
@back = { 0 => '' }
|
472
492
|
@char_count = 1
|
473
493
|
@dila_note = 0
|
@@ -476,6 +496,7 @@ class CBETA::P5aToHTML
|
|
476
496
|
@juan = 0
|
477
497
|
@lg_row_open = false
|
478
498
|
@mod_notes = Set.new
|
499
|
+
@next_line_buf = ''
|
479
500
|
@open_divs = []
|
480
501
|
@sutra_no = File.basename(xml_fn, ".xml")
|
481
502
|
|
@@ -535,7 +556,23 @@ eos
|
|
535
556
|
if e.has_attribute? 'place'
|
536
557
|
return '' if e['place'].include? 'foot'
|
537
558
|
end
|
538
|
-
traverse(e)
|
559
|
+
r = traverse(e)
|
560
|
+
|
561
|
+
# 處理雙行對照
|
562
|
+
i = e.xpath('../t').index(e)
|
563
|
+
case i
|
564
|
+
when 0
|
565
|
+
return r + ' '
|
566
|
+
when 1
|
567
|
+
@next_line_buf += r + ' '
|
568
|
+
return ''
|
569
|
+
else
|
570
|
+
return r
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
def handle_table(e)
|
575
|
+
'<table>' + traverse(e) + "</table>"
|
539
576
|
end
|
540
577
|
|
541
578
|
def handle_text(e, mode)
|
@@ -558,7 +595,7 @@ eos
|
|
558
595
|
end
|
559
596
|
|
560
597
|
def handle_vol(vol)
|
561
|
-
puts "
|
598
|
+
puts "convert volumn: #{vol}"
|
562
599
|
if vol.start_with? 'T'
|
563
600
|
@orig = "【大】"
|
564
601
|
else
|
@@ -577,7 +614,7 @@ eos
|
|
577
614
|
end
|
578
615
|
|
579
616
|
def handle_vols(v1, v2)
|
580
|
-
puts "
|
617
|
+
puts "convert volumns: #{v1}..#{v2}"
|
581
618
|
@series = v1[0]
|
582
619
|
folder = File.join(@xml_root, @series)
|
583
620
|
Dir.foreach(folder) { |vol|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbeta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Chou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem for use Chinese Buddhist Text resources made by CBETA (http://www.cbeta.org).
|
14
14
|
email: zhoubx@gmail.com
|