jekyll-toc 0.12.0.rc1 → 0.12.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/jekyll-toc.rb +12 -9
- data/lib/version.rb +1 -1
- data/test/test_jekyll-toc.rb +1 -3
- data/test/test_toc_tag.rb +24 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6912be740161a70021da9fdcfffcc86c1102b47ca0331fb83dd82ac6c3d9ff3a
|
4
|
+
data.tar.gz: b643b75ca33642f66054b52de2d3bc94ef6280277ac1afe91afbc5d0b9096f09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e96485ad84ea72849fde58ff33ced713b3ea962f56dc9ed09caf4ee85c2abff1566994126e0c9cb3f4d56f1d2e7b4638b26ae6e90c0cf9c56405f1b765ef2f
|
7
|
+
data.tar.gz: 714d5b7e4973f32d08e2a8689240ee3f372ca6bb7e983122ffca009db47bf175d8df8e3e21cd6c4a74b225ede5e480c2fe48fbec1cb030a2a3dcee10d04c423a
|
data/README.md
CHANGED
@@ -65,19 +65,34 @@ This filter places the TOC directly above the content.
|
|
65
65
|
|
66
66
|
If you'd like separated TOC and content, you can use `toc_only` and `inject_anchors` filters.
|
67
67
|
|
68
|
-
####
|
68
|
+
#### ~~`toc_only` filter~~
|
69
|
+
|
70
|
+
⚠️ Please use `{% toc %}` instead of `{{ contents | toc_only }}`.
|
69
71
|
|
70
72
|
Generates the TOC itself as described [below](#generated-html).
|
71
73
|
Mostly useful in cases where the TOC should _not_ be placed immediately
|
72
74
|
above the content but at some other place of the page, i.e. an aside.
|
73
75
|
|
76
|
+
#### toc tag
|
77
|
+
|
78
|
+
```html
|
79
|
+
<div>
|
80
|
+
<div id="table-of-contents">
|
81
|
+
{% toc %}
|
82
|
+
</div>
|
83
|
+
<div id="markdown-content">
|
84
|
+
{{ content }}
|
85
|
+
</div>
|
86
|
+
</div>
|
87
|
+
```
|
88
|
+
|
74
89
|
#### `inject_anchors` filter
|
75
90
|
|
76
91
|
Injects HTML anchors into the content without actually outputting the TOC itself.
|
77
92
|
They are of the form:
|
78
93
|
|
79
94
|
```html
|
80
|
-
<a
|
95
|
+
<a class="anchor" href="#heading1-1" aria-hidden="true">
|
81
96
|
<span class="octicon octicon-link"></span>
|
82
97
|
</a>
|
83
98
|
```
|
data/lib/jekyll-toc.rb
CHANGED
@@ -5,18 +5,21 @@ require 'table_of_contents/configuration'
|
|
5
5
|
require 'table_of_contents/parser'
|
6
6
|
|
7
7
|
module Jekyll
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# toc tag for Jekyll
|
9
|
+
class TocTag < Liquid::Tag
|
10
|
+
def render(context)
|
11
|
+
return '' unless context.registers[:page]['toc']
|
12
|
+
|
13
|
+
content_html = context.registers[:page].content
|
14
|
+
::Jekyll::TableOfContents::Parser.new(content_html).build_toc
|
15
|
+
end
|
16
|
+
end
|
16
17
|
|
17
18
|
# Jekyll Table of Contents filter plugin
|
18
19
|
module TableOfContentsFilter
|
19
20
|
def toc_only(html)
|
21
|
+
Jekyll.logger.warn 'Deprecation: toc_only filter is deprecated and will be remove in jekyll-toc v1.0.',
|
22
|
+
'Use `{% toc %}` instead of `{{ contents | toc_only }}`.'
|
20
23
|
return '' unless toc_enabled?
|
21
24
|
|
22
25
|
::Jekyll::TableOfContents::Parser.new(html, toc_config).build_toc
|
@@ -47,4 +50,4 @@ module Jekyll
|
|
47
50
|
end
|
48
51
|
|
49
52
|
Liquid::Template.register_filter(Jekyll::TableOfContentsFilter)
|
50
|
-
|
53
|
+
Liquid::Template.register_tag('toc', Jekyll::TocTag) # will be enabled at v1.0
|
data/lib/version.rb
CHANGED
data/test/test_jekyll-toc.rb
CHANGED
@@ -8,9 +8,7 @@ class TestTableOfContentsFilter < Minitest::Test
|
|
8
8
|
DUMMY_HTML = '<div>Dummy HTML Content</div>'
|
9
9
|
|
10
10
|
def setup
|
11
|
-
|
12
|
-
@context = stubbed_context.new(page: 'xxx')
|
13
|
-
@context
|
11
|
+
@context = Struct.new(:registers).new(page: { "toc" => false })
|
14
12
|
end
|
15
13
|
|
16
14
|
def test_toc_only
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class TestTableOfContentsTag < Minitest::Test
|
6
|
+
include Liquid
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@stubbed_context = Struct.new(:registers)
|
10
|
+
@stubbed_context2 = Struct.new(:toc, :content)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_toc_tag
|
14
|
+
context = @stubbed_context.new(page: @stubbed_context2.new({ 'toc' => false }, '<h1>test</h1>'))
|
15
|
+
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
|
16
|
+
assert_equal tag.render(context), "<ul class=\"section-nav\">\n<li class=\"toc-entry toc-h1\"><a href=\"#test\">test</a></li>\n</ul>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_toc_tag_returns_empty_string
|
20
|
+
context = @stubbed_context.new(page: { 'toc' => false })
|
21
|
+
tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
|
22
|
+
assert_empty tag.render(context)
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-toc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.0.
|
4
|
+
version: 0.12.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshimaru
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-03-
|
12
|
+
date: 2019-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- test/test_helper.rb
|
170
170
|
- test/test_jekyll-toc.rb
|
171
171
|
- test/test_kramdown_list.rb
|
172
|
+
- test/test_toc_tag.rb
|
172
173
|
homepage: https://github.com/toshimaru/jekyll-toc
|
173
174
|
licenses:
|
174
175
|
- MIT
|
@@ -202,3 +203,4 @@ test_files:
|
|
202
203
|
- test/test_helper.rb
|
203
204
|
- test/test_jekyll-toc.rb
|
204
205
|
- test/test_kramdown_list.rb
|
206
|
+
- test/test_toc_tag.rb
|