Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Community Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bio-IT
Community Documentation
Commits
fb897d92
Verified
Commit
fb897d92
authored
4 years ago
by
Toby Hodges
Browse files
Options
Downloads
Patches
Plain Diff
use toc.html from the amazing
https://github.com/allejo/jekyll-toc
parent
9ee7be11
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_includes/page_toc.html
+136
-0
136 additions, 0 deletions
_includes/page_toc.html
_layouts/page.html
+2
-0
2 additions, 0 deletions
_layouts/page.html
with
138 additions
and
0 deletions
_includes/page_toc.html
0 → 100644
+
136
−
0
View file @
fb897d92
{% capture tocWorkspace %}
{% comment %}
Copyright (c) 2017 Vladimir "allejo" Jimenez
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
{% endcomment %}
{% comment %}
Version 1.0.12
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
* skipNoIDs (bool) : false - skip headers that do not have an `id` attribute
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 skipNoIDs = include.skipNoIDs | 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
%}
{%
if
skipNoIDs =
=
true
%}
{%
unless
node
contains
"
id=
" %}
{% continue %}
{% endunless %}
{% endif %}
{% assign headerLevel = node | replace: '"
',
''
|
slice:
0,
1
|
times:
1
%}
{%
if
headerLevel
<
minHeader
or
headerLevel
>
maxHeader %}
{% continue %}
{% endif %}
{% 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
%}
{%
if
firstHeader
%}
{%
assign
firstHeader
=
false
%}
{%
assign
minHeader
=
headerLevel
%}
{%
endif
%}
{%
capture
_hAttrToStrip
%}{{
_workspace[0]
|
split:
'
>
' | first }}>{% endcapture %}
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
{% assign indentAmount = headerLevel | minus: minHeader %}
{% assign space = '' %}
{% for i in (1..indentAmount) %}
{% assign space = space | prepend: ' ' %}
{% endfor %}
{% if include.item_class and include.item_class != blank %}
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
{% endif %}
{% capture anchor_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
{% capture anchor_body %}{{ anchor_body | replace: "|", "\|" }}{% endcapture %}
{% if html_id %}
{% capture list_item %}[{{ anchor_body }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% endcapture %}
{% else %}
{% capture list_item %}{{ anchor_body }}{% endcapture %}
{% endif %}
{% capture my_toc %}{{ my_toc }}
{{ space }}{{ listModifier }} {{ listItemClass }} {{ list_item }}{% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %}
{% endfor %}
{% if include.class and include.class != blank %}
{% 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 diff is collapsed.
Click to expand it.
_layouts/page.html
+
2
−
0
View file @
fb897d92
...
...
@@ -4,4 +4,6 @@ layout: default
<h1
id=
"title-heading"
class=
"page-title"
>
{{ page.title }}
</h1>
{% include page_toc.html html=content %}
{{ content }}
This diff is collapsed.
Click to expand it.
Toby Hodges
@stamper
mentioned in issue
#9 (closed)
·
4 years ago
mentioned in issue
#9 (closed)
mentioned in issue #9
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment