jekyll-toc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 550d71ff0726c66bf79b2055447cd73ad9c69937
4
+ data.tar.gz: c178210e74ae1baa792df21e9cbecdd029b48730
5
+ SHA512:
6
+ metadata.gz: 50ac825bc691c394b110167aa9600a41ad633f08e2b9bb3d617608ace9782da0f5d4c68f26fa5c319a54060fba7618afdba63f4cdeb84ca96a20ab10ea01da38
7
+ data.tar.gz: 016084fe682cc1a117f5315b90432352a4ec6789d71deeb0a46c7e1af4af480d71761cb1bf97fdabc391a9e839fc0ed5642cf84b0c7dfd6bee8dee4ad35e1547
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) {{{year}}} {{{fullname}}}
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # WIP
2
+
3
+ * Gem badge
4
+ * Travis CI
5
+ * (Coverall)
6
+ * Test
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:test]
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'jekyll-toc'
3
+ spec.version = '0.0.1'
4
+ spec.date = '2015-01-04'
5
+ spec.summary = "Jekyll Table of Contents plugin"
6
+ spec.description = "Jekyll plugin which generates a table of contents at the top of the content"
7
+ spec.authors = ["Toshimaru"]
8
+ spec.email = 'me@toshimaru.net'
9
+ spec.files = `git ls-files -z`.split("\x0")
10
+ spec.homepage = 'https://github.com/toshimaru/jekyll-toc'
11
+ spec.license = 'MIT'
12
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
13
+
14
+ spec.add_runtime_dependency "nokogiri", "~> 1.6"
15
+ spec.add_development_dependency 'minitest', "~> 5.0"
16
+ spec.add_development_dependency "jekyll", "~> 2.0"
17
+ spec.add_development_dependency "rake"
18
+ end
data/lib/jekyll-toc.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'nokogiri'
2
+
3
+ module Jekyll
4
+ # parse logic is from html-pipeline toc_filter
5
+ # https://github.com/jch/html-pipeline/blob/v1.1.0/lib/html/pipeline/toc_filter.rb
6
+ module TableOfContentsFilter
7
+ PUNCTUATION_REGEXP = RUBY_VERSION > "1.9" ? /[^\p{Word}\- ]/u : /[^\w\- ]/
8
+
9
+ def toc(html)
10
+ toc = ""
11
+ doc = Nokogiri::HTML::DocumentFragment.parse(html)
12
+ headers = Hash.new(0)
13
+
14
+ doc.css('h1, h2, h3, h4, h5, h6').each do |node|
15
+ text = node.text
16
+ id = text.downcase
17
+ id.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation
18
+ id.gsub!(' ', '-') # replace spaces with dash
19
+
20
+ uniq = (headers[id] > 0) ? "-#{headers[id]}" : ''
21
+ headers[id] += 1
22
+ if header_content = node.children.first
23
+ toc << %Q{<li><a href="##{id}#{uniq}">#{text}</a></li>\n}
24
+ header_content.add_previous_sibling(%Q{<a id="#{id}#{uniq}" class="anchor" href="##{id}#{uniq}" aria-hidden="true"><span class="octicon octicon-link"></span></a>})
25
+ end
26
+ end
27
+ toc = %Q{<ul class="section-nav">\n#{toc}</ul>} unless toc.empty?
28
+
29
+ toc + doc.inner_html
30
+ end
31
+ end
32
+ end
33
+
34
+ Liquid::Template.register_filter(Jekyll::TableOfContentsFilter)
@@ -0,0 +1,2 @@
1
+ require 'jekyll'
2
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-toc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Toshimaru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jekyll
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Jekyll plugin which generates a table of contents at the top of the content
70
+ email: me@toshimaru.net
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - Gemfile
77
+ - LICENSE.md
78
+ - README.md
79
+ - Rakefile
80
+ - jekyll-toc.gemspec
81
+ - lib/jekyll-toc.rb
82
+ - test/test_helper.rb
83
+ homepage: https://github.com/toshimaru/jekyll-toc
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.4
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Jekyll Table of Contents plugin
107
+ test_files:
108
+ - test/test_helper.rb