cbeta 4.0.0 → 4.1.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/cbeta/p5a_checker.rb +32 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a8826c19847f81602cd7ca3fb1e976fffc20b98976fde5844134b4672d60e63
|
|
4
|
+
data.tar.gz: 06a2dc151b6623439cca6bbbf4a913fb70c1ac1f6fe8a041e8b052471b08c202
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 102a0d53249646d923f2b95c1b5906c23ad6a243b31827e8c663b795448277c1cc4295d9340cdc79f73fc5c29cfc03430c0698cbae69ad4f618d051a0eab8dd4
|
|
7
|
+
data.tar.gz: 48f777330445f72f0e80c8a02c862b05a36e1ba8da6c4509ac81be5a7cab77fed0b71c8dc392b66598f47eaf438e85fe4b44eeb0401e9e6b7571e4ced99501f8
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/cbeta/p5a_checker.rb
CHANGED
|
@@ -21,6 +21,7 @@ require_relative 'cbeta_share'
|
|
|
21
21
|
# * [E14] <anchor type="right"> 不應直接出現在 div 或 body 下
|
|
22
22
|
# * [E15] <note> corresp 無對應的 <note>
|
|
23
23
|
# * [E16] app/@n 與 note/@n 不一致
|
|
24
|
+
# * [E17] list 下沒有任何有內容的 item
|
|
24
25
|
#
|
|
25
26
|
# * 警告類型
|
|
26
27
|
# * [W01] 夾注包夾注
|
|
@@ -29,6 +30,9 @@ require_relative 'cbeta_share'
|
|
|
29
30
|
class CBETA::P5aChecker
|
|
30
31
|
ALLOW_TAB = %w[change]
|
|
31
32
|
|
|
33
|
+
# 判斷 item 是否有內容時,不計入的元素(本身不產生內容,只是標記位置)
|
|
34
|
+
EMPTY_ELEMENTS = %w[lb pb milestone anchor mulu space]
|
|
35
|
+
|
|
32
36
|
# @param xml_root [String] 來源 CBETA XML P5a 路徑
|
|
33
37
|
# @param figures [String] 插圖 路徑 (可由 https://github.com/cbeta-git/CBR2X-figures 取得)
|
|
34
38
|
# @param log [String] Log file path
|
|
@@ -119,6 +123,12 @@ class CBETA::P5aChecker
|
|
|
119
123
|
end
|
|
120
124
|
end
|
|
121
125
|
|
|
126
|
+
# 節點是否有內容(文字,或 EMPTY_ELEMENTS 以外的元素)
|
|
127
|
+
def content?(e)
|
|
128
|
+
return true unless e.text.strip.empty?
|
|
129
|
+
e.xpath('.//*').any? { |d| not EMPTY_ELEMENTS.include?(d.name) }
|
|
130
|
+
end
|
|
131
|
+
|
|
122
132
|
def display_errors
|
|
123
133
|
@g_errors.keys.sort.each do |k|
|
|
124
134
|
s = @g_errors[k].to_a.join(',')
|
|
@@ -230,6 +240,20 @@ class CBETA::P5aChecker
|
|
|
230
240
|
traverse(e)
|
|
231
241
|
end
|
|
232
242
|
|
|
243
|
+
# list 下應該至少有一個 item 是有內容的
|
|
244
|
+
def e_list(e)
|
|
245
|
+
# item 可能包在 app/lem 之類的元素裡,所以用 descendant 找,
|
|
246
|
+
# 但要排除 巢狀 list 底下的 item
|
|
247
|
+
items = e.xpath('.//item').select { |item| nearest_list(item).equal?(e) }
|
|
248
|
+
unless items.any? { |item| content?(item) }
|
|
249
|
+
msg = "[E17] list 下沒有任何有內容的 item"
|
|
250
|
+
head = e.at_xpath('head')
|
|
251
|
+
msg += ", head: #{head.text.gsub(/\s+/, ' ').strip[0, 30]}" unless head.nil?
|
|
252
|
+
error msg
|
|
253
|
+
end
|
|
254
|
+
traverse(e)
|
|
255
|
+
end
|
|
256
|
+
|
|
233
257
|
def e_note(e)
|
|
234
258
|
error "[E11] note 直接出現在 div 下" if e.parent.name == 'div'
|
|
235
259
|
error "[E12] note 直接出現在 lg 下" if e.parent.name == 'lg'
|
|
@@ -342,6 +366,7 @@ class CBETA::P5aChecker
|
|
|
342
366
|
when 'item' then e_item(e)
|
|
343
367
|
when 'lb' then e_lb(e)
|
|
344
368
|
when 'lem' then e_lem(e)
|
|
369
|
+
when 'list' then e_list(e)
|
|
345
370
|
when 'note' then e_note(e)
|
|
346
371
|
when 'p' then e_p(e)
|
|
347
372
|
when 'rdg' then e_rdg(e)
|
|
@@ -360,6 +385,13 @@ class CBETA::P5aChecker
|
|
|
360
385
|
end
|
|
361
386
|
end
|
|
362
387
|
|
|
388
|
+
# 往上找最近的 list 祖先
|
|
389
|
+
def nearest_list(e)
|
|
390
|
+
r = e.parent
|
|
391
|
+
r = r.parent while r.element? and r.name != 'list'
|
|
392
|
+
r
|
|
393
|
+
end
|
|
394
|
+
|
|
363
395
|
def read_notes(doc)
|
|
364
396
|
@notes = Set.new
|
|
365
397
|
doc.xpath('//note').each do |e|
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|