Skip to content

Commit 253803a

Browse files
authored
[6.0] Fix regression where external links are rendering as plaintext (#887)
Resolves: rdar://133479034
1 parent 49d5bcd commit 253803a

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/mixins/referencesProvider.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
import AppStore from 'docc-render/stores/AppStore';
1111

12+
const TopicReferenceTypes = new Set([
13+
'section',
14+
'topic',
15+
]);
16+
1217
export default {
1318
// inject the `store`
1419
inject: {
@@ -32,14 +37,18 @@ export default {
3237
state: { references: originalRefs = {} },
3338
},
3439
} = this;
35-
// strip the `url` key from refs if their identifier comes from an
36-
// archive that hasn't been included by DocC
40+
// strip the `url` key from "topic"/"section" refs if their identifier
41+
// comes from an archive that hasn't been included by DocC
3742
return Object.keys(originalRefs).reduce((newRefs, id) => {
38-
const { url, ...refWithoutUrl } = originalRefs[id];
39-
return {
43+
const originalRef = originalRefs[id];
44+
const { url, ...refWithoutUrl } = originalRef;
45+
return TopicReferenceTypes.has(originalRef.type) ? ({
4046
...newRefs,
4147
[id]: isFromIncludedArchive(id) ? originalRefs[id] : refWithoutUrl,
42-
};
48+
}) : ({
49+
...newRefs,
50+
[id]: originalRef,
51+
});
4352
}, {});
4453
},
4554
},

tests/unit/mixins/referencesProvider.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,39 @@ const aa = {
3434
identifier: 'doc://A/documentation/A/a',
3535
url: '/documentation/A/a',
3636
title: 'A.A',
37+
type: 'topic',
3738
};
3839
const ab = {
3940
identifier: 'doc://A/documentation/A/b',
4041
url: '/documentation/A/b',
4142
title: 'A.B',
43+
type: 'topic',
4244
};
4345
const bb = {
4446
identifier: 'doc://B/documentation/B/b',
4547
url: '/documentation/B/b',
4648
title: 'B.B',
49+
type: 'topic',
4750
};
4851
const bbb = {
4952
identifier: 'doc://BB/documentation/BB/b',
50-
url: '/documentation/BB/b',
53+
url: '/documentation/BB/b#b',
5154
title: 'BB.B',
55+
type: 'section',
56+
};
57+
const c = {
58+
identifier: 'https://abc.dev',
59+
url: 'https://abc.dev',
60+
title: 'C',
61+
type: 'link',
5262
};
5363

5464
const references = {
5565
[aa.identifier]: aa,
5666
[ab.identifier]: ab,
5767
[bb.identifier]: bb,
5868
[bbb.identifier]: bbb,
69+
[c.identifier]: c,
5970
};
6071

6172
const provide = {
@@ -117,5 +128,6 @@ describe('referencesProvider', () => {
117128
expect(refs3[bb.identifier].url).toBe(bb.url); // bb still has `url`
118129
expect(refs3[bbb.identifier].title).toBe(bbb.title);
119130
expect(refs3[bbb.identifier].url).toBeFalsy(); // bbb `url` is gone now
131+
expect(refs3[c.identifier].url).toBe(c.url); // external link untouched
120132
});
121133
});

0 commit comments

Comments
 (0)