BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ff2026f4
Commit
ff2026f4
authored
Nov 21, 2016
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add transparent namespace to all user-generated anchors in GitLab flavored markdown
parent
ffd28232
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+17
-2
table_of_contents_filter.rb
lib/banzai/filter/table_of_contents_filter.rb
+5
-3
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
ff2026f4
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, no-unused-expressions, no-param-reassign, no-else-return, quotes, object-shorthand, comma-dangle, camelcase, one-var, vars-on-top, one-var-declaration-per-line, no-return-assign, consistent-return, padded-blocks, max-len */
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, no-unused-expressions, no-param-reassign, no-else-return, quotes, object-shorthand, comma-dangle, camelcase, one-var, vars-on-top, one-var-declaration-per-line, no-return-assign, consistent-return, padded-blocks, max-len
, prefer-template
*/
(
function
()
{
(
function
()
{
(
function
(
w
)
{
(
function
(
w
)
{
var
base
;
var
base
;
...
@@ -97,6 +97,9 @@
...
@@ -97,6 +97,9 @@
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// https://github.com/twitter/bootstrap/issues/1768
// https://github.com/twitter/bootstrap/issues/1768
w
.
gl
.
utils
.
handleLocationHash
=
function
()
{
w
.
gl
.
utils
.
handleLocationHash
=
function
()
{
var
hash
=
w
.
gl
.
utils
.
getLocationHash
();
if
(
!
hash
)
return
;
var
navbar
=
document
.
querySelector
(
'.navbar-gitlab'
);
var
navbar
=
document
.
querySelector
(
'.navbar-gitlab'
);
var
subnav
=
document
.
querySelector
(
'.layout-nav'
);
var
subnav
=
document
.
querySelector
(
'.layout-nav'
);
var
fixedTabs
=
document
.
querySelector
(
'.js-tabs-affix'
);
var
fixedTabs
=
document
.
querySelector
(
'.js-tabs-affix'
);
...
@@ -104,9 +107,21 @@
...
@@ -104,9 +107,21 @@
var
adjustment
=
0
;
var
adjustment
=
0
;
if
(
navbar
)
adjustment
-=
navbar
.
offsetHeight
;
if
(
navbar
)
adjustment
-=
navbar
.
offsetHeight
;
if
(
subnav
)
adjustment
-=
subnav
.
offsetHeight
;
if
(
subnav
)
adjustment
-=
subnav
.
offsetHeight
;
if
(
fixedTabs
)
adjustment
-=
fixedTabs
.
offsetHeight
;
// scroll to user-generated markdown anchor if we cannot find a match
if
(
document
.
getElementById
(
hash
)
===
null
)
{
var
target
=
document
.
getElementById
(
'user-content_'
+
hash
);
if
(
target
&&
target
.
scrollIntoView
)
{
target
.
scrollIntoView
(
true
);
window
.
scrollBy
(
0
,
adjustment
);
}
}
else
{
// only adjust for fixedTabs when not targeting user-generated content
if
(
fixedTabs
)
{
adjustment
-=
fixedTabs
.
offsetHeight
;
}
window
.
scrollBy
(
0
,
adjustment
);
window
.
scrollBy
(
0
,
adjustment
);
}
};
};
gl
.
utils
.
updateTooltipTitle
=
function
(
$tooltipEl
,
newTitle
)
{
gl
.
utils
.
updateTooltipTitle
=
function
(
$tooltipEl
,
newTitle
)
{
...
...
lib/banzai/filter/table_of_contents_filter.rb
View file @
ff2026f4
...
@@ -35,9 +35,11 @@ module Banzai
...
@@ -35,9 +35,11 @@ module Banzai
headers
[
id
]
+=
1
headers
[
id
]
+=
1
if
header_content
=
node
.
children
.
first
if
header_content
=
node
.
children
.
first
# namespace detection will be automatically handled via javascript (see issue #22781)
namespace
=
"user-content_"
href
=
"
#{
id
}#{
uniq
}
"
href
=
"
#{
id
}#{
uniq
}
"
push_toc
(
href
,
text
)
push_toc
(
href
,
text
)
header_content
.
add_previous_sibling
(
anchor_tag
(
href
))
header_content
.
add_previous_sibling
(
anchor_tag
(
"
#{
namespace
}#{
href
}
"
,
href
))
end
end
end
end
...
@@ -48,8 +50,8 @@ module Banzai
...
@@ -48,8 +50,8 @@ module Banzai
private
private
def
anchor_tag
(
href
)
def
anchor_tag
(
id
,
href
)
%Q{<a id="
#{
href
}
" class="anchor" href="#
#{
href
}
" aria-hidden="true"></a>}
%Q{<a id="
#{
id
}
" class="anchor" href="#
#{
href
}
" aria-hidden="true"></a>}
end
end
def
push_toc
(
href
,
text
)
def
push_toc
(
href
,
text
)
...
...
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