Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
056158ef
Commit
056158ef
authored
Sep 01, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor table of contents building
parent
3b017a36
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
19 deletions
+11
-19
lib/banzai/filter/table_of_contents_filter.rb
lib/banzai/filter/table_of_contents_filter.rb
+11
-19
No files found.
lib/banzai/filter/table_of_contents_filter.rb
View file @
056158ef
...
@@ -43,15 +43,7 @@ module Banzai
...
@@ -43,15 +43,7 @@ module Banzai
end
end
end
end
if
header_root
.
children
.
length
>
0
push_toc
(
header_root
.
children
,
root:
true
)
result
[
:toc
]
=
%q{<ul class="section-nav">}
header_root
.
children
.
each
do
|
child
|
push_toc
(
child
)
end
result
[
:toc
]
<<
'</ul>'
end
doc
doc
end
end
...
@@ -62,19 +54,19 @@ module Banzai
...
@@ -62,19 +54,19 @@ module Banzai
%Q{<a id="user-content-
#{
href
}
" class="anchor" href="#
#{
href
}
" aria-hidden="true"></a>}
%Q{<a id="user-content-
#{
href
}
" class="anchor" href="#
#{
href
}
" aria-hidden="true"></a>}
end
end
def
push_toc
(
header_node
)
def
push_toc
(
children
,
root:
false
)
result
[
:toc
]
<<
%Q{<li><a href="#
#{
header_node
.
href
}
">
#{
header_node
.
text
}
</a>}
return
if
children
.
empty?
if
header_node
.
children
.
length
>
0
result
[
:toc
]
<<
'<ul>'
header_node
.
children
.
each
do
|
child
|
klass
=
' class="section-nav"'
if
root
push_toc
(
child
)
end
result
[
:toc
]
<<
'</ul>'
result
[
:toc
]
<<
"<ul
#{
klass
}
>"
end
children
.
each
{
|
child
|
push_anchor
(
child
)
}
result
[
:toc
]
<<
'</ul>'
end
def
push_anchor
(
header_node
)
result
[
:toc
]
<<
%Q{<li><a href="#
#{
header_node
.
href
}
">
#{
header_node
.
text
}
</a>}
push_toc
(
header_node
.
children
)
result
[
:toc
]
<<
'</li>'
result
[
:toc
]
<<
'</li>'
end
end
...
...
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