Module: Asciidoctor::Pdf::Linewrap::Ja::Converter
- Defined in:
- lib/asciidoctor/pdf/linewrap/ja/converter.rb
Constant Summary collapse
- PROHIBIT_LINE_BREAK_BEFORE =
行頭禁則文字
'’”)〕]}〉》」』】⦆〙〗»〟' + # 終わり括弧類(cl-02) '‐〜゠–' + # ハイフン類(cl-03) '!?‼⁇⁈⁉' + # 区切り約物(cl-04) '・:;' + # 中点類(cl-05) '。.' + # 句点類(cl-06) '、,' + # 読点類(cl-07) 'ヽヾゝゞ々〻' + # 繰返し記号(cl-09) 'ー' + # 長音記号(cl-10) 'ぁぃぅぇぉァィゥェォっゃゅょゎゕゖッャュョヮヵヶㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿㇷ゚' + # 小書きの仮名(cl-11) ')〕]'
- PROHIBIT_LINE_BREAK_AFTER =
行末禁則文字
'‘“(〔[{〈《「『【⦅〘〖«〝' + # 始め括弧類(cl-01) '(〔['
- PROHIBIT_DIVIDE =
分離禁止文字
'—…‥〳〴〵'- ZERO_WIDTH_SPACE =
ゼロ幅スペース
'{zwsp}'
Class Method Summary collapse
-
.insert_zero_width_space(line) ⇒ Object
ZERO_WIDTH_SPACE = '★'.
- .insert_zero_width_space?(ch, next_ch) ⇒ Boolean
- .japanese_char?(ch) ⇒ Boolean
- .prohibit_divide?(ch, next_ch) ⇒ Boolean
- .prohibit_line_break?(ch, next_ch) ⇒ Boolean
- .prohibit_line_break_after?(ch) ⇒ Boolean
- .prohibit_line_break_before?(ch) ⇒ Boolean
- .remove_zero_width_space(line) ⇒ Object
Class Method Details
.insert_zero_width_space(line) ⇒ Object
ZERO_WIDTH_SPACE = '★'
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 32 def self.insert_zero_width_space(line) return line if line.nil? new_line = '' line.each_char.with_index do |ch, idx| new_line << ch new_line << ZERO_WIDTH_SPACE if insert_zero_width_space?(ch, line[idx + 1]) end return remove_zero_width_space(new_line) end |
.insert_zero_width_space?(ch, next_ch) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 47 def self.insert_zero_width_space?(ch, next_ch) if japanese_char?(ch) return !prohibit_line_break?(ch, next_ch) elsif next_ch != nil && japanese_char?(next_ch) return !prohibit_line_break_before?(next_ch) end return false end |
.japanese_char?(ch) ⇒ Boolean
64 65 66 67 68 69 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 64 def self.japanese_char?(ch) (/[\p{Han}\p{Hiragana}\p{Katakana}ー]/ === ch) \ || PROHIBIT_LINE_BREAK_BEFORE.include?(ch) \ || PROHIBIT_LINE_BREAK_AFTER.include?(ch) \ || PROHIBIT_DIVIDE.include?(ch) end |
.prohibit_divide?(ch, next_ch) ⇒ Boolean
83 84 85 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 83 def self.prohibit_divide?(ch, next_ch) next_ch == nil || (PROHIBIT_DIVIDE.include?(ch) && PROHIBIT_DIVIDE.include?(next_ch)) end |
.prohibit_line_break?(ch, next_ch) ⇒ Boolean
71 72 73 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 71 def self.prohibit_line_break?(ch, next_ch) prohibit_line_break_after?(ch) || prohibit_line_break_before?(next_ch) || prohibit_divide?(ch, next_ch) end |
.prohibit_line_break_after?(ch) ⇒ Boolean
75 76 77 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 75 def self.prohibit_line_break_after?(ch) PROHIBIT_LINE_BREAK_AFTER.include?(ch) end |
.prohibit_line_break_before?(ch) ⇒ Boolean
79 80 81 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 79 def self.prohibit_line_break_before?(ch) ch == nil || PROHIBIT_LINE_BREAK_BEFORE.include?(ch) end |
.remove_zero_width_space(line) ⇒ Object
58 59 60 61 62 |
# File 'lib/asciidoctor/pdf/linewrap/ja/converter.rb', line 58 def self.remove_zero_width_space(line) line.gsub(/http.*?[\]\s]/) do |href| href.gsub(/#{ZERO_WIDTH_SPACE}/, "") end end |