Skip to content

Commit fdc734f

Browse files
authored
Fix PR reviews comment snippets (OctoLinker#829)
1 parent 4d954ea commit fdc734f

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

e2e/automated.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ describe('End to End tests', () => {
7272
);
7373
});
7474
});
75+
76+
it('links commentbox', async () => {
77+
await executeTest(
78+
'https://github.com/OctoLinker/OctoLinker/pull/451/files',
79+
'https://nodejs.org/api/path.html',
80+
'.highlight-source-js .octolinker-link',
81+
);
82+
});
7583
});
7684

7785
describe.skip('expanded blob', () => {

e2e/diff-fixtures.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@
1414
{
1515
"url": "https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R42",
1616
"targetUrl": "https://github.com/eslint/eslint"
17+
},
18+
{
19+
"url": "https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-11e9f7f953edc64ba14b0cc350ae7b9dL2",
20+
"targetUrl": "https://github.com/webpack-contrib/copy-webpack-plugin"
21+
},
22+
{
23+
"url": "https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-11e9f7f953edc64ba14b0cc350ae7b9dR2",
24+
"targetUrl": "https://github.com/webpack-contrib/copy-webpack-plugin"
1725
}
1826
]

packages/blob-reader/helper.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ function getBlobCodeInner(el) {
55
}
66

77
function getBlobWrapper(rootElement = document) {
8-
let ret = [].slice.call(
9-
rootElement.getElementsByClassName('js-blob-wrapper'),
10-
);
11-
12-
if (!ret.length) {
13-
ret = [].slice.call(rootElement.getElementsByClassName('blob-wrapper'));
14-
}
15-
16-
if (!ret.length) {
17-
ret = [].slice.call(rootElement.getElementsByClassName('highlight'));
18-
}
8+
const ret = [
9+
...[].slice.call(rootElement.getElementsByClassName('blob-wrapper')),
10+
...[].slice.call(rootElement.getElementsByClassName('js-blob-wrapper')),
11+
...[].slice.call(
12+
rootElement.querySelectorAll('[class*="highlight-source-"]'),
13+
),
14+
];
1915

2016
return ret;
2117
}
@@ -204,7 +200,11 @@ function readLine(el) {
204200
}
205201

206202
function readLines(el) {
207-
if (el.classList.contains('highlight')) {
203+
if (
204+
el.classList.contains('highlight') &&
205+
el.firstElementChild &&
206+
el.firstElementChild.nodeName === 'PRE'
207+
) {
208208
const issueCode = el.getElementsByTagName('pre');
209209
if (issueCode.length) {
210210
return issueCode[0].textContent.split(/\n/).map((line, index) => ({

0 commit comments

Comments
 (0)