asciidoctor-pdf-linewrap-ja 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/asciidoctor-pdf-linewrap-ja.gemspec +24 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/asciidoctor-pdf-linewrap-ja.rb +1 -0
- data/lib/asciidoctor/pdf/linewrap/ja.rb +20 -0
- data/lib/asciidoctor/pdf/linewrap/ja/converter.rb +57 -0
- data/lib/asciidoctor/pdf/linewrap/ja/version.rb +9 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eff9aad0fb004903c2916a361ef78281e39523e5
|
4
|
+
data.tar.gz: f276dc36475b598b5676fc6ca825a134416ec59d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2a450f97d4281a2cb7b53bc509cd29885f963fa282122815af75af9ac7d09ee3b5d4b6d8731d70c4a5c3d998bf56d8f790a8b79619457d584f7422ce74e5f35
|
7
|
+
data.tar.gz: '0393658a00ef8eb98e3473427e426c6b93c7b62354806021ece9251e0ee8d485a0fc8e05650214f9c5fd2b8d2d6605907338369259a2e56c0e5e427d3d58a0a6'
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
asciidoctor-pdf-linewrap-ja (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.4.2)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
asciidoctor-pdf-linewrap-ja!
|
17
|
+
bundler (~> 1.16)
|
18
|
+
minitest (~> 5.0)
|
19
|
+
rake (~> 10.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 y.fukazawa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# asciidoctor-pdf-linewrap-ja: Asciidoctor PDF extension for japanese document
|
2
|
+
|
3
|
+
asciidoctor-pdf-linewrap-ja: Asciidoctor PDF extension providing better line wrap for Japanese document.
|
4
|
+
|
5
|
+
## Requrements
|
6
|
+
|
7
|
+
- [Asciidoctor PDF](https://github.com/asciidoctor/asciidoctor-pdf) 1.5.0.alpha.16 (or later)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'asciidoctor-pdf-linewrap-ja'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install asciidoctor-pdf-linewrap-ja
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
$ asciidoctor-pdf -r asciidoctor-pdf-linewrap-ja document.adoc
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fuka/asciidoctor-pdf-linewrap-ja.
|
32
|
+
|
33
|
+
## Special Thanks
|
34
|
+
|
35
|
+
asciidoctor-pdf-linewrap-ja is inspired by asciidoctor\-pdf\-cjk ([chloerei/asciidoctor\-pdf\-cjk](https://github.com/chloerei/asciidoctor-pdf-cjk)).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "asciidoctor/pdf/linewrap/ja/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "asciidoctor-pdf-linewrap-ja"
|
7
|
+
spec.version = Asciidoctor::Pdf::Linewrap::Ja::VERSION
|
8
|
+
spec.authors = ["y.fukazawa"]
|
9
|
+
spec.email = ["fuka@backport.net"]
|
10
|
+
|
11
|
+
spec.summary = %q{Asciidoctor PDF extension providing better line wrap for Japanese document.}
|
12
|
+
spec.homepage = "https://github.com/fuka/asciidoctor-pdf-linewrap-ja"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "asciidoctor-pdf", "~> 1.5.0.alpha.16"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
24
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "asciidoctor/pdf/linewrap/ja"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'asciidoctor/pdf/linewrap/ja'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'ja/version'
|
2
|
+
require_relative 'ja/converter'
|
3
|
+
|
4
|
+
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
5
|
+
|
6
|
+
include Asciidoctor
|
7
|
+
|
8
|
+
Extensions.register do
|
9
|
+
treeprocessor do
|
10
|
+
|
11
|
+
process do |document|
|
12
|
+
paragraphs = document.find_by context: :paragraph
|
13
|
+
paragraphs.each do |paragraph|
|
14
|
+
paragraph.lines.each_with_index do |line, i|
|
15
|
+
paragraph.lines[i] = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(line)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Pdf
|
3
|
+
module Linewrap
|
4
|
+
module Ja
|
5
|
+
module Converter
|
6
|
+
|
7
|
+
# 行頭禁則文字
|
8
|
+
PROHIBIT_LINE_BREAK_BEFORE =
|
9
|
+
'}〕〉》」』】〙〗〟⦆»' +
|
10
|
+
'ゝゞーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇷ゚ㇺㇻㇼㇽㇾㇿ々〻' +
|
11
|
+
'ァィゥェォッャュョ' +
|
12
|
+
'‐゠〜~' +
|
13
|
+
'‼⁇⁈⁉' +
|
14
|
+
'?!' +
|
15
|
+
'・' +
|
16
|
+
'、。'
|
17
|
+
|
18
|
+
# 行末禁則文字
|
19
|
+
PROHIBIT_LINE_BREAK_AFTER = '{〔〈《「『【〘〖〝⦅«'
|
20
|
+
|
21
|
+
# 分離禁止文字
|
22
|
+
PROHIBIT_DIVIDE = '…‥〳〴〵'
|
23
|
+
|
24
|
+
# ゼロ幅スペース
|
25
|
+
ZERO_WIDTH_SPACE = '{zwsp}'
|
26
|
+
|
27
|
+
def self.insert_zero_width_space(line)
|
28
|
+
|
29
|
+
new_line = ''
|
30
|
+
|
31
|
+
line.each_char.with_index do |ch, idx|
|
32
|
+
|
33
|
+
new_line << ch
|
34
|
+
new_line << ZERO_WIDTH_SPACE if insert_zero_width_space?(ch, line[idx + 1])
|
35
|
+
end
|
36
|
+
|
37
|
+
return new_line
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.insert_zero_width_space?(ch, next_ch)
|
41
|
+
japanese_char?(ch) \
|
42
|
+
&& !PROHIBIT_LINE_BREAK_AFTER.include?(ch) \
|
43
|
+
&& next_ch != nil && !PROHIBIT_LINE_BREAK_BEFORE.include?(next_ch) \
|
44
|
+
&& !(PROHIBIT_DIVIDE.include?(ch) && PROHIBIT_DIVIDE.include?(next_ch))
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.japanese_char?(ch)
|
48
|
+
(/[\p{Han}\p{Hiragana}\p{Katakana}ー]/ === ch) \
|
49
|
+
|| PROHIBIT_LINE_BREAK_BEFORE.include?(ch) \
|
50
|
+
|| PROHIBIT_LINE_BREAK_AFTER.include?(ch) \
|
51
|
+
|| PROHIBIT_DIVIDE.include?(ch)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asciidoctor-pdf-linewrap-ja
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- y.fukazawa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: asciidoctor-pdf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.0.alpha.16
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.0.alpha.16
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- fuka@backport.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- asciidoctor-pdf-linewrap-ja.gemspec
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/asciidoctor-pdf-linewrap-ja.rb
|
87
|
+
- lib/asciidoctor/pdf/linewrap/ja.rb
|
88
|
+
- lib/asciidoctor/pdf/linewrap/ja/converter.rb
|
89
|
+
- lib/asciidoctor/pdf/linewrap/ja/version.rb
|
90
|
+
homepage: https://github.com/fuka/asciidoctor-pdf-linewrap-ja
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Asciidoctor PDF extension providing better line wrap for Japanese document.
|
114
|
+
test_files: []
|