This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds table of contents when width permits
- Loading branch information
Showing
7 changed files
with
333 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{% capture tocWorkspace %} | ||
{% comment %} | ||
Version 1.0.8 | ||
https://github.com/allejo/jekyll-toc | ||
|
||
"...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe | ||
|
||
Usage: | ||
{% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %} | ||
|
||
Parameters: | ||
* html (string) - the HTML of compiled markdown generated by kramdown in Jekyll | ||
|
||
Optional Parameters: | ||
* sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC | ||
* class (string) : '' - a CSS class assigned to the TOC | ||
* id (string) : '' - an ID to assigned to the TOC | ||
* h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored | ||
* h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored | ||
* ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list | ||
* item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level | ||
* baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content | ||
* anchor_class (string) : '' - add custom class(es) for each anchor element | ||
|
||
Output: | ||
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only | ||
generate the table of contents and will NOT output the markdown given to it | ||
{% endcomment %} | ||
|
||
{% capture my_toc %}{% endcapture %} | ||
{% assign orderedList = include.ordered | default: false %} | ||
{% assign minHeader = include.h_min | default: 1 %} | ||
{% assign maxHeader = include.h_max | default: 6 %} | ||
{% assign nodes = include.html | split: '<h' %} | ||
{% assign firstHeader = true %} | ||
|
||
{% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %} | ||
|
||
{% for node in nodes %} | ||
{% if node == "" %} | ||
{% continue %} | ||
{% endif %} | ||
|
||
{% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %} | ||
|
||
{% if headerLevel < minHeader or headerLevel > maxHeader %} | ||
{% continue %} | ||
{% endif %} | ||
|
||
{% if firstHeader %} | ||
{% assign firstHeader = false %} | ||
{% assign minHeader = headerLevel %} | ||
{% endif %} | ||
|
||
{% assign indentAmount = headerLevel | minus: minHeader %} | ||
{% assign _workspace = node | split: '</h' %} | ||
|
||
{% assign _idWorkspace = _workspace[0] | split: 'id="' %} | ||
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %} | ||
{% assign html_id = _idWorkspace[0] %} | ||
|
||
{% assign _classWorkspace = _workspace[0] | split: 'class="' %} | ||
{% assign _classWorkspace = _classWorkspace[1] | split: '"' %} | ||
{% assign html_class = _classWorkspace[0] %} | ||
|
||
{% if html_class contains "no_toc" %} | ||
{% continue %} | ||
{% endif %} | ||
|
||
{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %} | ||
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} | ||
|
||
{% assign space = '' %} | ||
{% for i in (1..indentAmount) %} | ||
{% assign space = space | prepend: ' ' %} | ||
{% endfor %} | ||
|
||
{% unless include.item_class == blank %} | ||
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %} | ||
{% endunless %} | ||
|
||
{% capture heading_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} | ||
{% capture my_toc %}{{ my_toc }} | ||
{{ space }}{{ listModifier }} {{ listItemClass }} [{{ heading_body | replace: "|", "\|" }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %} | ||
{% endfor %} | ||
|
||
{% if include.class %} | ||
{% capture my_toc %}{:.{{ include.class }}} | ||
{{ my_toc | lstrip }}{% endcapture %} | ||
{% endif %} | ||
|
||
{% if include.id %} | ||
{% capture my_toc %}{: #{{ include.id }}} | ||
{{ my_toc | lstrip }}{% endcapture %} | ||
{% endif %} | ||
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }} |
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,155 +1 @@ | ||
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,400i,600,700'); | ||
|
||
body { | ||
padding-bottom: 6rem; | ||
font-family: 'Open Sans', sans-serif; | ||
@include mq(md) { | ||
padding-bottom: 0; | ||
} | ||
} | ||
|
||
.page-content { | ||
ol { | ||
> li { | ||
&:before { | ||
color: $grey-dk-100; | ||
} | ||
} | ||
} | ||
ul { | ||
> li { | ||
&:before { | ||
color: $grey-dk-100; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.site-title { | ||
@include mq(md) { | ||
padding-top: 0; | ||
padding-bottom: 0; | ||
padding-left: $sp-5; | ||
} | ||
img { | ||
height: 100%; | ||
max-width: 208px; | ||
} | ||
} | ||
|
||
.navigation-list-toggle { | ||
top: $sp-5; | ||
} | ||
|
||
h1, h2, h3, h4, h5, h6 { | ||
margin-top: 2.4rem; | ||
} | ||
|
||
.img-border { | ||
border: 1px solid $grey-lt-200; | ||
} | ||
|
||
// Note, tip, and warning blocks | ||
|
||
%callout { | ||
border: 1px solid $grey-lt-200; | ||
border-radius: 5px; | ||
margin: 1rem 0; | ||
padding: 1rem; | ||
position: relative; | ||
} | ||
|
||
.note { | ||
@extend %callout; | ||
border-left: 5px solid $blue-300; | ||
} | ||
|
||
.tip { | ||
@extend %callout; | ||
border-left: 5px solid $green-300; | ||
} | ||
|
||
.warning { | ||
@extend %callout; | ||
border-left: 5px solid $red-300; | ||
} | ||
|
||
// Labels | ||
|
||
.label, | ||
.label-blue { | ||
background-color: $blue-300; | ||
} | ||
|
||
.label-green { | ||
background-color: $green-300; | ||
} | ||
|
||
.label-purple { | ||
background-color: $purple-300; | ||
} | ||
|
||
.label-red { | ||
background-color: $red-300; | ||
} | ||
|
||
.label-yellow { | ||
color: $grey-dk-200; | ||
background-color: $yellow-300; | ||
} | ||
|
||
// Buttons | ||
|
||
.btn-primary { | ||
@include btn-color($white, $btn-primary-color); | ||
} | ||
|
||
.btn-purple { | ||
@include btn-color($white, $purple-dk-100); | ||
} | ||
|
||
.btn-blue { | ||
@include btn-color($white, $blue-300); | ||
} | ||
|
||
.btn-green { | ||
@include btn-color($white, $green-300); | ||
} | ||
|
||
// Tables | ||
|
||
th, | ||
td { | ||
border-bottom: $border rgba($table-border-color, 0.5); | ||
border-left: $border $table-border-color; | ||
} | ||
|
||
thead { | ||
th { | ||
border-bottom: 1px solid $table-border-color; | ||
} | ||
} | ||
td { | ||
pre { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
// Keeps labels high and tight next to headers | ||
|
||
h1 + p.label { | ||
margin: -46px 0 0 0; | ||
} | ||
h2 + p.label { | ||
margin: -30px 0 0 0; | ||
} | ||
h3 + p.label { | ||
margin: -20px 0 0 0; | ||
} | ||
h4 + p.label, | ||
h6 + p.label { | ||
margin: -14px 0 0 0; | ||
} | ||
h5 + p.label { | ||
margin: -15px 0 0 0; | ||
} | ||
$toc-width: 200px !default; |
Oops, something went wrong.