Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
docs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
docs
Commits
4110cb88
Commit
4110cb88
authored
Jan 20, 2016
by
Tobias Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add table of contents filter
parent
ccc3d974
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
0 deletions
+72
-0
Rules
Rules
+1
-0
faq.md
content/docs/introduction/faq.md
+1
-0
toc.rb
lib/filters/toc.rb
+49
-0
docs.css
static/docs.css
+21
-0
No files found.
Rules
View file @
4110cb88
...
@@ -46,6 +46,7 @@ compile '*' do
...
@@ -46,6 +46,7 @@ compile '*' do
filter
:bootstrappify
filter
:bootstrappify
filter
:admonition
filter
:admonition
filter
:colorize_syntax
,
:default_colorizer
=>
:pygmentsrb
filter
:colorize_syntax
,
:default_colorizer
=>
:pygmentsrb
filter
:toc
,
style:
item
[
:toc
]
if
item
[
:kind
]
==
'article'
if
item
[
:kind
]
==
'article'
layout
'blog'
layout
'blog'
else
else
...
...
content/docs/introduction/faq.md
View file @
4110cb88
---
---
title
:
FAQ
title
:
FAQ
sort_rank
:
5
sort_rank
:
5
toc
:
full-width
---
---
# Frequently Asked Questions
# Frequently Asked Questions
...
...
lib/filters/toc.rb
0 → 100644
View file @
4110cb88
# encoding: utf-8
require
'nokogiri'
class
TocFilter
<
::
Nanoc
::
Filter
identifier
:toc
# Number of items required to render a table of contents.
TOC_MINIMUM
=
2
def
run
(
content
,
params
=
{})
doc
=
Nokogiri
::
HTML
(
content
)
titles
=
doc
.
xpath
(
'//h1'
)
headers
=
doc
.
xpath
(
'//h2|//h3'
)
if
titles
.
empty?
||
headers
.
length
<
TOC_MINIMUM
return
content
end
style
=
params
[
:style
]
||
'right'
items
=
headers
.
map
do
|
header
|
title
=
header
.
inner_html
.
sub
(
/^(.*)<a .*$/
,
'\1'
)
{
:level
=>
header
.
name
,
:title
=>
title
,
:id
=>
header
[
'id'
]
}
end
titles
.
first
.
after
(
%(<div class="toc toc-#{style}">#{toc(items)}</div>)
)
doc
.
to_s
end
def
toc
(
items
)
return
''
if
items
.
empty?
level
=
''
table
=
[]
items
.
each
do
|
item
|
if
item
[
:level
]
>
level
table
<<
'<ul>'
elsif
item
[
:level
]
<
level
table
<<
'</ul>'
end
level
=
item
[
:level
]
table
<<
%(<li><a href="##{item[:id]}">#{item[:title]}</a></li>)
end
table
<<
'</ul>'
table
.
join
(
''
)
end
end
static/docs.css
View file @
4110cb88
...
@@ -201,6 +201,27 @@ a.sc-logo img {
...
@@ -201,6 +201,27 @@ a.sc-logo img {
display
:
block
;
display
:
block
;
}
}
.toc
{
padding
:
1em
;
background-color
:
#eee
;
}
.toc-right
{
float
:
right
;
width
:
40%
;
margin
:
0
0
0.5em
0.5em
;
}
.toc
ul
{
padding
:
0
0
0
1.5em
;
margin
:
0
;
}
.toc
a
code
{
color
:
#337ab7
;
background-color
:
transparent
;
}
pre
{
pre
{
font-family
:
"Courier New"
,
Monaco
,
Menlo
,
Consolas
,
monospace
;
font-family
:
"Courier New"
,
Monaco
,
Menlo
,
Consolas
,
monospace
;
background-color
:
#444
;
background-color
:
#444
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment