Commit 46b23aa5 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch 'pedropombeiro/335194-allow-github-source-highlight-format' into 'master'

Accept GitHub source highlight URL argument format

See merge request gitlab-org/gitlab!65453
parents 595e094b 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;
......
......@@ -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' });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment