-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration to enable ordered list
* Created new configuration option to enable ordered list through use_ordered_list input * Default behaviour is false so users will continue to have ul tags * Using existing class configuration, user can change styling on top ol tag and sub listing ol tags separately * No ability to update styling on sub-nested ol tags separately but code is open to this change * Added tests for new logic * Update README with example of usage and render
- Loading branch information
Showing
6 changed files
with
136 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class TestOrderedList < Minitest::Test | ||
include TestHelpers | ||
|
||
def test_default_configuration | ||
configuration = Jekyll::TableOfContents::Configuration.new({}) | ||
|
||
assert_equal configuration.use_ordered_list, false | ||
end | ||
|
||
def test_disabled_ordered_list | ||
configuration = Jekyll::TableOfContents::Configuration.new('use_ordered_list' => false) | ||
|
||
assert_equal configuration.use_ordered_list, false | ||
end | ||
|
||
def test_enabled_ordered_list | ||
configuration = Jekyll::TableOfContents::Configuration.new('use_ordered_list' => true) | ||
|
||
assert_equal configuration.use_ordered_list, true | ||
end | ||
|
||
def test_basic_ordered_list_top_heading | ||
parse_with_ordered_list | ||
html = @parser.toc | ||
|
||
assert_match(/^<ol class="section-nav">/, html) | ||
end | ||
|
||
def test_ordered_list_sub_headings | ||
parse_with_ordered_list | ||
html = @parser.toc | ||
|
||
assert_match(/<ol>\n<li class="toc-entry/, html) | ||
end | ||
|
||
def test_ordered_list_top_heading_with_classes | ||
parse_with_ordered_list_and_classes | ||
html = @parser.toc | ||
|
||
assert_match(/^<ol class="top-list-class">/, html) | ||
end | ||
|
||
def test_ordered_list_sub_headings_with_classes | ||
parse_with_ordered_list_and_classes | ||
html = @parser.toc | ||
|
||
assert_match(/<ol class="sublist-class">/, html) | ||
end | ||
|
||
def test_ordered_list_subheadings_with_classes_nested_structure | ||
parse_with_ordered_list_and_classes | ||
html = @parser.toc | ||
|
||
occurrences = html.scan(/<ol class="sublist-class">/).count | ||
|
||
assert_equal occurrences, 5 | ||
end | ||
|
||
private | ||
|
||
def parse_with_ordered_list | ||
read_html_and_create_parser('use_ordered_list' => true) | ||
end | ||
|
||
def parse_with_ordered_list_and_classes | ||
read_html_and_create_parser( | ||
'use_ordered_list' => true, | ||
'list_class' => 'top-list-class', | ||
'sublist_class' => 'sublist-class' | ||
) | ||
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
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