jekyll-pangu 1.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a2ca0d3d71ab23ab9d35ab15a30e51524be5bf1
4
+ data.tar.gz: 077d8b3c2765047fa412c4b7c13414644b47f26c
5
+ SHA512:
6
+ metadata.gz: b6462b6f845354654c7b5253fbaf9b03b555173812d7e91889299ac230e2fc3fc1161d8307b9cf3119f797b14e8629eb16196a1911c7b7b42384232d25cc9d4f
7
+ data.tar.gz: 778e95e54e4fe1cd1e636bc996fbb89973831caf317c977de1bc09c0d2d02f9714fc4eb6e346bf3b18b2e817fdd9ad3287a0b92027daeeaecd055504e7455d20
data/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby
3
+
4
+ ### Ruby ###
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /spec/examples.txt
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ # Used by dotenv library to load environment variables.
18
+ # .env
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+ *.bridgesupport
25
+ build-iPhoneOS/
26
+ build-iPhoneSimulator/
27
+
28
+ ## Specific to RubyMotion (use of CocoaPods):
29
+ #
30
+ # We recommend against adding the Pods directory to your .gitignore. However
31
+ # you should judge for yourself, the pros and cons are mentioned at:
32
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
33
+ #
34
+ # vendor/Pods/
35
+
36
+ ## Documentation cache and generated files:
37
+ /.yardoc/
38
+ /_yardoc/
39
+ /doc/
40
+ /rdoc/
41
+
42
+ ## Environment normalization:
43
+ /.bundle/
44
+ /vendor/bundle
45
+ /lib/bundler/man/
46
+
47
+ # for a library or gem, you might want to ignore these files since the code is
48
+ # intended to run in multiple environments; otherwise, check them in:
49
+ # Gemfile.lock
50
+ # .ruby-version
51
+ # .ruby-gemset
52
+
53
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
+ .rvmrc
55
+
56
+
57
+ # End of https://www.gitignore.io/api/ruby
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Inflation
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.
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'jekyll-pangu/version'
5
+ Gem::Specification.new do |s|
6
+ s.name = 'jekyll-pangu'
7
+ s.version = Jekyll::Pangu::VERSION
8
+ s.date = '2018-02-26'
9
+ s.summary = 'Integration of Pangu with Jekyll'
10
+ s.description = 'Automatically add spacing between CJK and ' \
11
+ 'other characters for all your Jekyll posts'
12
+ s.authors = ['Inflation']
13
+ s.email = ['hypernovagama@gmail.com']
14
+ s.homepage = 'https://github.com/inflation/jekyll-pangu'
15
+ s.licenses = ['MIT']
16
+ s.files = `git ls-files -z`
17
+ .split("\x0")
18
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ s.require_paths = ['lib']
20
+ s.add_dependency 'jekyll', '~> 3.0'
21
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ require 'jekyll'
4
+ require 'jekyll-pangu/pangu'
5
+
6
+ =begin
7
+ Add a hook to automatically convert posts, pages and documents with their 'page.lang' setting to CJK, i.e., starting with zh, jp, or ko.
8
+ TODO: Give an option to enable globally
9
+
10
+ Also provide a filter to manually call the function in templates.
11
+ =end
12
+
13
+ module JekyllPangu
14
+ module PanguFilter
15
+ def pangu(input)
16
+ Pangu.spacing(input)
17
+ end
18
+ end
19
+
20
+ Jekyll::Hooks.register [:posts, :pages, :documents], :pre_render do |post|
21
+ if post.data['lang'] =~ /^(zh|jp|ko)/
22
+ post.data['title'] = spacing(post.data['title'])
23
+ post.data['excerpt'].output = spacing(post.data['excerpt'].to_s)
24
+ post.content = spacing(post.to_s)
25
+ end
26
+ end
27
+ end
28
+
29
+ Liquid::Template.register_filter(JekyllPangu::PanguFilter)
@@ -0,0 +1,47 @@
1
+ =begin
2
+ The module Pangu is copied from the repo: https://github.com/dlackty/pangu.rb under MIT License. Then modified to use unicode '\u2006', i.e., "SIX-PER-EM SPACE" for better looking, as well as ignoring backquote '`' since it will be handled by <code> tags.
3
+ =end
4
+
5
+ module JekyllPangu
6
+ CJK_QUOTE_L_RE = /([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])(["\'])/i
7
+ CJK_QUOTE_R_RE = /(["\'])([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])/i
8
+ CJK_QUOTE_FIX_RE = /(["\']+)(\s*)(.+?)(\s*)(["\']+)/i
9
+
10
+ CJK_BRACKET_RE = /([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])([<\[\{\(]+(.*?)[>\]\}\)]+)([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])/i
11
+ CJK_BRACKETFIX_RE = /([<\[\{\(]+)(\s*)(.+?)(\s*)([>\]\}\)]+)/i
12
+ CJK_BRACKET_L_RE = /([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])([<>\[\]\{\}\(\)])/i
13
+ CJK_BRACKET_R_RE = /([<>\[\]\{\}\(\)])([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])/i
14
+
15
+ CJK_HASH_L_RE = /([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])(#(\S+))/i
16
+ CJK_HASH_R_RE = /((\S+)#)([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])/i
17
+
18
+ CJK_L_RE = /([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])([a-z0-9@&%=\$\^\*\-\+\|\/\\])/i
19
+ CJK_R_RE = /([a-z0-9~!%&=;\|\,\.\:\?\$\^\*\-\+\/\\])([\u3040-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff])/i
20
+
21
+ def self.spacing(text)
22
+ text = text.dup
23
+
24
+ text.gsub!(CJK_QUOTE_L_RE, "\\1\u2006\\2")
25
+ text.gsub!(CJK_QUOTE_R_RE, "\\1\u2006\\2")
26
+ text.gsub!(CJK_QUOTE_FIX_RE, "\\1\\3\\5")
27
+
28
+ old_text = text
29
+ new_text = old_text.gsub(CJK_BRACKET_RE, "\\1\u2006\\2\u2006\\4")
30
+ text = new_text
31
+
32
+ if old_text == new_text
33
+ text.gsub!(CJK_BRACKET_L_RE, "\\1\u2006\\2")
34
+ text.gsub!(CJK_BRACKET_R_RE, "\\1\u2006\\2")
35
+ end
36
+
37
+ text.gsub!(CJK_BRACKETFIX_RE, "\\1\\3\\5")
38
+
39
+ text.gsub!(CJK_HASH_L_RE, "\\1\u2006\\2")
40
+ text.gsub!(CJK_HASH_R_RE, "\\1\u2006\\3")
41
+
42
+ text.gsub!(CJK_L_RE, "\\1\u2006\\2")
43
+ text.gsub!(CJK_R_RE, "\\1\u2006\\2")
44
+
45
+ text
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Pangu
3
+ VERSION = '1.0.1'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-pangu
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Inflation
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Automatically add spacing between CJK and other characters for all your
28
+ Jekyll posts
29
+ email:
30
+ - hypernovagama@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - LICENSE
37
+ - jekyll-pangu.gemspec
38
+ - lib/jekyll-pangu.rb
39
+ - lib/jekyll-pangu/pangu.rb
40
+ - lib/jekyll-pangu/version.rb
41
+ homepage: https://github.com/inflation/jekyll-pangu
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.5.2.1
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Integration of Pangu with Jekyll
65
+ test_files: []