Skip to content

Commit

Permalink
Fix PR reviews comment snippets (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck committed Mar 2, 2020
1 parent 4d954ea commit fdc734f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions e2e/automated.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ describe('End to End tests', () => {
);
});
});

it('links commentbox', async () => {
await executeTest(
'https://github.com/OctoLinker/OctoLinker/pull/451/files',
'https://nodejs.org/api/path.html',
'.highlight-source-js .octolinker-link',
);
});
});

describe.skip('expanded blob', () => {
Expand Down
8 changes: 8 additions & 0 deletions e2e/diff-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
{
"url": "https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R42",
"targetUrl": "https://github.com/eslint/eslint"
},
{
"url": "https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-11e9f7f953edc64ba14b0cc350ae7b9dL2",
"targetUrl": "https://github.com/webpack-contrib/copy-webpack-plugin"
},
{
"url": "https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-11e9f7f953edc64ba14b0cc350ae7b9dR2",
"targetUrl": "https://github.com/webpack-contrib/copy-webpack-plugin"
}
]
24 changes: 12 additions & 12 deletions packages/blob-reader/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ function getBlobCodeInner(el) {
}

function getBlobWrapper(rootElement = document) {
let ret = [].slice.call(
rootElement.getElementsByClassName('js-blob-wrapper'),
);

if (!ret.length) {
ret = [].slice.call(rootElement.getElementsByClassName('blob-wrapper'));
}

if (!ret.length) {
ret = [].slice.call(rootElement.getElementsByClassName('highlight'));
}
const ret = [
...[].slice.call(rootElement.getElementsByClassName('blob-wrapper')),
...[].slice.call(rootElement.getElementsByClassName('js-blob-wrapper')),
...[].slice.call(
rootElement.querySelectorAll('[class*="highlight-source-"]'),
),
];

return ret;
}
Expand Down Expand Up @@ -204,7 +200,11 @@ function readLine(el) {
}

function readLines(el) {
if (el.classList.contains('highlight')) {
if (
el.classList.contains('highlight') &&
el.firstElementChild &&
el.firstElementChild.nodeName === 'PRE'
) {
const issueCode = el.getElementsByTagName('pre');
if (issueCode.length) {
return issueCode[0].textContent.split(/\n/).map((line, index) => ({
Expand Down

0 comments on commit fdc734f

Please sign in to comment.