asciidoctor-pdf-linewrap-ja 0.3.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 106b114729d658fe2805aa3dad294cf5f8dbe202
4
- data.tar.gz: e67e9a76a391a44ae716133c6344ddb241248bbf
3
+ metadata.gz: beab95b686c5c3eedfefacf0554aa7199abbf793
4
+ data.tar.gz: ab8b6781990426cecd3bb3869be12c066ecfabc4
5
5
  SHA512:
6
- metadata.gz: 9937982fe7976d50ff05ced68216195082107c38ba654550e32b9c138092221d8c69747ab254944d72fae30d53c502d026ad1c8eb7d063546d3965270ebfab2f
7
- data.tar.gz: b1ad88372d54dc3a7c8e0e3c6b5060a384ddb8952d6bea581d43b6cd3963bc548e08d82eb662ac65cb1783bdfc19c326abcb5833fb320a8b9b5941f6f642924e
6
+ metadata.gz: e9ff04c97eb37c6ef32731e69904d4bc3ec498d6148626f67db3e1b8a47ca4ba25362e85b3c38df2e9fb43484f29d2a8e1d61d1421be94b4173ca96c63427e09
7
+ data.tar.gz: 5d5d6a78325739d19a9e3191d516748ed44653f77f60aed65132fcc9a760b610d85fd734e4e1e13fa3ecda93b6aac3b46d288ed0cf41ff46af32639f84ec04a0
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "asciidoctor-pdf", "~> 1.5.0.alpha.16"
21
21
  spec.add_development_dependency "bundler", "~> 1.16"
22
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rake", ">= 12.3.3"
23
23
  spec.add_development_dependency "minitest", "~> 5.0"
24
24
  end
@@ -1 +1 @@
1
- require_relative 'asciidoctor/pdf/linewrap/ja'
1
+ require_relative 'asciidoctor/pdf/linewrap/ja'
@@ -9,6 +9,31 @@ Extensions.register do
9
9
  treeprocessor do
10
10
 
11
11
  process do |document|
12
+
13
+ tables = document.find_by context: :table
14
+ tables.each do |table|
15
+ table.rows.head.each do |head|
16
+ head.each do |cell|
17
+ raw_text = get_raw_text(cell)
18
+ cell.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
19
+ end
20
+ end
21
+
22
+ table.rows.body.each do |body|
23
+ body.each do |cell|
24
+ raw_text = get_raw_text(cell)
25
+ cell.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
26
+ end
27
+ end
28
+
29
+ table.rows.foot.each do |foot|
30
+ foot.each do |cell|
31
+ raw_text = get_raw_text(cell)
32
+ cell.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
33
+ end
34
+ end
35
+ end
36
+
12
37
  paragraphs = document.find_by context: :paragraph
13
38
  paragraphs.each do |paragraph|
14
39
  paragraph.lines.each_with_index do |line, i|
@@ -18,7 +43,23 @@ Extensions.register do
18
43
 
19
44
  list_items = document.find_by context: :list_item
20
45
  list_items.each do |list_item|
21
- list_item.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(list_item.text)
46
+ raw_text = get_raw_text(list_item)
47
+ list_item.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
48
+ end
49
+
50
+ admonitions = document.find_by context: :admonition
51
+ admonitions.each do |admonition|
52
+ admonition.lines.each_with_index do |line, i|
53
+ admonition.lines[i] = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(line)
54
+ end
55
+ end
56
+ end
57
+
58
+ def get_raw_text(item)
59
+ if item.instance_variable_defined?('@text')
60
+ return item.instance_variable_get('@text')
61
+ else
62
+ return item.text
22
63
  end
23
64
  end
24
65
  end
@@ -6,29 +6,24 @@ module Asciidoctor
6
6
 
7
7
  # 行頭禁則文字
8
8
  PROHIBIT_LINE_BREAK_BEFORE =
9
- ')}〕〉》」』】〙〗〟⦆»' +
10
- 'ゝゞーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇷ゚ㇺㇻㇼㇽㇾㇿ々〻' +
11
- 'ァィゥェォッャュョ' +
12
- '‐゠〜~' +
13
- '‼⁇⁈⁉' +
14
- '?!' +
15
- '' +
16
- '、。'
17
-
18
- # 行頭禁則文字(半角)
19
- PROHIBIT_LINE_BREAK_BEFORE_HALF_WIDTH =
20
- ')]>}' +
21
- '-=~' +
22
- '?!'
9
+ '’”)〕]}〉》」』】⦆〙〗»〟' + # 終わり括弧類(cl-02)
10
+ '‐〜゠–' + # ハイフン類(cl-03)
11
+ '!?‼⁇⁈⁉' + # 区切り約物(cl-04)
12
+ '・:;' + # 中点類(cl-05)
13
+ '。.' + # 句点類(cl-06)
14
+ '、,' + # 読点類(cl-07)
15
+ 'ヽヾゝゞ々〻' + # 繰返し記号(cl-09)
16
+ '' + # 長音記号(cl-10)
17
+ 'ぁぃぅぇぉァィゥェォっゃゅょゎゕゖッャュョヮヵヶㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿㇷ゚' + # 小書きの仮名(cl-11)
18
+ ')〕]' # 割注終わり括弧類(cl-29)
23
19
 
24
20
  # 行末禁則文字
25
- PROHIBIT_LINE_BREAK_AFTER = '({〔〈《「『【〘〖〝⦅«'
26
-
27
- # 行末禁則文字(半角)
28
- PROHIBIT_LINE_BREAK_AFTER_HALF_WIDTH = '([<{'
21
+ PROHIBIT_LINE_BREAK_AFTER =
22
+ '‘“(〔[{〈《「『【⦅〘〖«〝' + # 始め括弧類(cl-01)
23
+ '(〔[' # 割注始め括弧類(cl-28)
29
24
 
30
25
  # 分離禁止文字
31
- PROHIBIT_DIVIDE = '…‥〳〴〵'
26
+ PROHIBIT_DIVIDE = '—…‥〳〴〵' # 分離禁止文字(cl-08)
32
27
 
33
28
  # ゼロ幅スペース
34
29
  ZERO_WIDTH_SPACE = '{zwsp}'
@@ -36,6 +31,8 @@ module Asciidoctor
36
31
 
37
32
  def self.insert_zero_width_space(line)
38
33
 
34
+ return line if line.nil?
35
+
39
36
  new_line = ''
40
37
 
41
38
  line.each_char.with_index do |ch, idx|
@@ -44,7 +41,7 @@ module Asciidoctor
44
41
  new_line << ZERO_WIDTH_SPACE if insert_zero_width_space?(ch, line[idx + 1])
45
42
  end
46
43
 
47
- return new_line
44
+ return remove_zero_width_space(new_line)
48
45
  end
49
46
 
50
47
  def self.insert_zero_width_space?(ch, next_ch)
@@ -58,6 +55,16 @@ module Asciidoctor
58
55
  return false
59
56
  end
60
57
 
58
+ def self.remove_zero_width_space(line)
59
+ line = line.gsub(/http.*?[\]\s]/) do |href|
60
+ href.gsub(/#{ZERO_WIDTH_SPACE}/, "")
61
+ end
62
+
63
+ line.gsub(/image:.*?\]/) do |image|
64
+ image.gsub(/#{ZERO_WIDTH_SPACE}/, "")
65
+ end
66
+ end
67
+
61
68
  def self.japanese_char?(ch)
62
69
  (/[\p{Han}\p{Hiragana}\p{Katakana}ー]/ === ch) \
63
70
  || PROHIBIT_LINE_BREAK_BEFORE.include?(ch) \
@@ -70,11 +77,11 @@ module Asciidoctor
70
77
  end
71
78
 
72
79
  def self.prohibit_line_break_after?(ch)
73
- PROHIBIT_LINE_BREAK_AFTER.include?(ch) || PROHIBIT_LINE_BREAK_AFTER_HALF_WIDTH.include?(ch)
80
+ PROHIBIT_LINE_BREAK_AFTER.include?(ch)
74
81
  end
75
82
 
76
83
  def self.prohibit_line_break_before?(ch)
77
- ch == nil || PROHIBIT_LINE_BREAK_BEFORE.include?(ch) || PROHIBIT_LINE_BREAK_BEFORE_HALF_WIDTH.include?(ch)
84
+ ch == nil || PROHIBIT_LINE_BREAK_BEFORE.include?(ch)
78
85
  end
79
86
 
80
87
  def self.prohibit_divide?(ch, next_ch)
@@ -2,7 +2,7 @@ module Asciidoctor
2
2
  module Pdf
3
3
  module Linewrap
4
4
  module Ja
5
- VERSION = "0.3.0"
5
+ VERSION = "0.7.1"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-pdf-linewrap-ja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - y.fukazawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor-pdf
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.5.2.2
109
+ rubygems_version: 2.6.8
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Asciidoctor PDF extension providing better line wrap for Japanese document.