page-toc-filter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +11 -0
- data/lib/page-toc-filter.rb +28 -0
- data/page-toc-filter.gemspec +25 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86b76a41f01bb806ec13216e76bd748af27c77b2
|
4
|
+
data.tar.gz: ce2f03b1fec1676acc1ca6728d3618e47906c2f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 192a85e15ead4dfb0646a2626bf1a4cf947691d9a992877c3343c626a289c73bcd41c3c501e79310c17c72f7a93eb75aefcb609cf31e32f3a11d59944c89234e
|
7
|
+
data.tar.gz: f748bdb2e314294e80ee052ff83860851e448529fbd63cf6c43e83f7e9cd33655c2bebdf461eafff3667721634108c054129c7965bed2933f1f067e615fdb742
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Garen Torikian
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# PageTocFilter
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
gem 'page-toc-filter'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install page-toc-filter
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The simplest way to do this is
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
require 'page-toc-filter'
|
25
|
+
```
|
26
|
+
|
27
|
+
Then, place this filter *after* you've rendered your content through the Markdown and TOC filters:
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
pipeline = HTML::Pipeline.new([
|
31
|
+
HTML::Pipeline::MarkdownFilter,
|
32
|
+
HTML::Pipeline::TableOfContentsFilter,
|
33
|
+
HTML::Pipeline::PageTocFilter
|
34
|
+
])
|
35
|
+
```
|
36
|
+
|
37
|
+
By default, only `h2` headings will be converted into a table of contents. You can change this with the optional `toc_levels` setting, which should be a comma-separated string of heading levels. For example:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
pipeline = HTML::Pipeline.new([
|
41
|
+
HTML::Pipeline::MarkdownFilter,
|
42
|
+
HTML::Pipeline::TableOfContentsFilter,
|
43
|
+
HTML::Pipeline::PageTocFilter
|
44
|
+
], { :toc_levels => 'h2, h3' })
|
45
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'html/pipeline'
|
2
|
+
|
3
|
+
class PageTocFilter < HTML::Pipeline::Filter
|
4
|
+
|
5
|
+
def call
|
6
|
+
doc.search('p').each do |node|
|
7
|
+
content = node.to_html
|
8
|
+
next unless content == '<p>{:toc}</p>'
|
9
|
+
html = page_toc_filter(doc)
|
10
|
+
node.replace(html)
|
11
|
+
end
|
12
|
+
|
13
|
+
doc
|
14
|
+
end
|
15
|
+
|
16
|
+
def page_toc_filter(doc)
|
17
|
+
toc = ''
|
18
|
+
levels = context[:toc_levels] || 'h2'
|
19
|
+
|
20
|
+
doc.search(levels).each do |node|
|
21
|
+
text = node.text
|
22
|
+
id = node.child['id']
|
23
|
+
toc << %(<li><a href="##{id}" id="markdown-toc-#{id}">#{text}</a></li>\n)
|
24
|
+
end
|
25
|
+
toc = %(<ul id="markdown-toc">\n#{toc}</ul>) unless toc.empty?
|
26
|
+
toc
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'page-toc-filter'
|
6
|
+
spec.version = '0.0.1'
|
7
|
+
spec.authors = ['Garen Torikian']
|
8
|
+
spec.email = ['gjtorikian@gmail.com']
|
9
|
+
|
10
|
+
spec.summary = 'Generates a table of contents for a single page, via HTML::Pipeline.'
|
11
|
+
spec.homepage = 'https://github.com/gjtorikian/page-toc-filter'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = 'exe'
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'html-pipeline', '~> 2.0'
|
20
|
+
spec.add_dependency 'nokogiri', '~> 1.6.4'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
24
|
+
spec.add_development_dependency 'github-markdown', '~> 0.6.3'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: page-toc-filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Garen Torikian
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: html-pipeline
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: github-markdown
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.3
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- gjtorikian@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/page-toc-filter.rb
|
97
|
+
- page-toc-filter.gemspec
|
98
|
+
homepage: https://github.com/gjtorikian/page-toc-filter
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.5.1
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Generates a table of contents for a single page, via HTML::Pipeline.
|
122
|
+
test_files: []
|