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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
c87dfa3f
Commit
c87dfa3f
authored
Jul 05, 2021
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept GitHub source highlight URL argument format
Changelog: added
parent
84dd0ca0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
app/assets/javascripts/line_highlighter.js
app/assets/javascripts/line_highlighter.js
+2
-2
spec/frontend/line_highlighter_spec.js
spec/frontend/line_highlighter_spec.js
+9
-0
No files found.
app/assets/javascripts/line_highlighter.js
View file @
c87dfa3f
...
...
@@ -117,8 +117,8 @@ LineHighlighter.prototype.clearHighlight = function () {
//
// Returns an Array
LineHighlighter
.
prototype
.
hashToRange
=
function
(
hash
)
{
// ?L(\d+)(?:-(\d+))?$/)
const
matches
=
hash
.
match
(
/^#
?
L
(\d
+
)(?:
-
(\d
+
))?
$/
);
// ?L(\d+)(?:-
L?
(\d+))?$/)
const
matches
=
hash
.
match
(
/^#
?
L
(\d
+
)(?:
-
L
?
(\d
+
))?
$/
);
if
(
matches
&&
matches
.
length
)
{
const
first
=
parseInt
(
matches
[
1
],
10
);
const
last
=
matches
[
2
]
?
parseInt
(
matches
[
2
],
10
)
:
null
;
...
...
spec/frontend/line_highlighter_spec.js
View file @
c87dfa3f
...
...
@@ -49,6 +49,15 @@ describe('LineHighlighter', () => {
}
});
it
(
'
highlights a range of lines given in the URL hash using GitHub format
'
,
()
=>
{
new
LineHighlighter
({
hash
:
'
#L5-L25
'
});
expect
(
$
(
`.
${
testContext
.
css
}
`
).
length
).
toBe
(
21
);
for
(
let
line
=
5
;
line
<=
25
;
line
+=
1
)
{
expect
(
$
(
`#LC
${
line
}
`
)).
toHaveClass
(
testContext
.
css
);
}
});
it
(
'
scrolls to the first highlighted line on initial load
'
,
()
=>
{
jest
.
spyOn
(
utils
,
'
scrollToElement
'
);
new
LineHighlighter
({
hash
:
'
#L5-25
'
});
...
...
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