-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from torbjoernk/feature/separate-filters
Add new filters `toc_only` and `inject_anchors` to split up existing filter
- Loading branch information
Showing
8 changed files
with
231 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec| | |
spec.version = JekyllToc::VERSION | ||
spec.summary = "Jekyll Table of Contents plugin" | ||
spec.description = "A liquid filter plugin for Jekyll which generates a table of contents." | ||
spec.authors = ["Toshimaru"] | ||
spec.authors = ["Toshimaru", 'torbjoernk'] | ||
spec.email = '[email protected]' | ||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.homepage = 'https://github.com/toshimaru/jekyll-toc' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module JekyllToc | ||
VERSION = "0.0.4" | ||
VERSION = '0.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
require 'jekyll' | ||
require 'minitest/autorun' | ||
|
||
SIMPLE_HTML = <<EOL | ||
<h1>Simple H1</h1> | ||
<h2>Simple H2</h2> | ||
<h3>Simple H3</h3> | ||
<h4>Simple H4</h4> | ||
<h5>Simple H5</h5> | ||
<h6>Simple H6</h6> | ||
EOL | ||
|
||
module TestHelpers | ||
def read_html_and_create_parser | ||
@parser = Jekyll::TableOfContents::Parser.new(SIMPLE_HTML) | ||
assert_match /Simple H1/, @parser.doc.inner_html | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
require_relative '../lib/jekyll-toc' | ||
|
||
|
||
class TestTOCOnlyFilter < Minitest::Test | ||
include TestHelpers | ||
|
||
def setup | ||
read_html_and_create_parser | ||
end | ||
|
||
def test_injects_anchors_into_content | ||
html = @parser.inject_anchors_into_html | ||
|
||
assert_match /<a id="simple\-h1" class="anchor" href="#simple\-h1" aria\-hidden="true"><span.*span><\/a>Simple H1/, html | ||
end | ||
|
||
def test_does_not_inject_toc | ||
html = @parser.inject_anchors_into_html | ||
|
||
assert_nil /<ul class="section-nav">/ =~ html | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
require_relative '../lib/jekyll-toc' | ||
|
||
|
||
class TestTOCFilter < Minitest::Test | ||
include TestHelpers | ||
|
||
def setup | ||
read_html_and_create_parser | ||
end | ||
|
||
def test_injects_anchors | ||
html = @parser.toc | ||
|
||
assert_match /<a id="simple\-h1" class="anchor" href="#simple\-h1" aria\-hidden="true"><span.*span><\/a>Simple H1/, html | ||
end | ||
|
||
def test_injects_toc_container | ||
html = @parser.toc | ||
|
||
assert_match /<ul class="section-nav">/, html | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
require_relative '../lib/jekyll-toc' | ||
|
||
|
||
class TestTOCOnlyFilter < Minitest::Test | ||
include TestHelpers | ||
|
||
def setup | ||
read_html_and_create_parser | ||
end | ||
|
||
def test_injects_toc_container | ||
html = @parser.build_toc | ||
|
||
assert_match /<ul class="section-nav">/, html | ||
end | ||
|
||
def test_does_not_return_content | ||
html = @parser.build_toc | ||
|
||
assert_nil /<h1>Simple H1<\/h1>/ =~ html | ||
end | ||
end |