Skip to content

Commit 864361e

Browse files
authored
Respect formatting of links to symbols using custom titles (#647)
**Example:** ```markdown /// Default, should use code voice: ``StringBuilder`` /// /// Custom title, should use code voice: [`custom text`](doc:StringBuilder) /// /// Custom title, should not use code voice: [custom text](doc:StringBuilder) /// /// Custom title, should use italics and bold: [_**custom text**_](doc:StringBuilder) ``` Resolves: #632 Resolves: rdar://108515663
1 parent 61d1ef6 commit 864361e

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/components/ContentNode.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ function renderNode(createElement, references) {
438438
isActive: node.isActive,
439439
ideTitle: reference.ideTitle,
440440
titleStyle: reference.titleStyle,
441+
hasInlineFormatting: !!titleInlineContent,
441442
},
442443
}, (
443444
titleInlineContent ? renderChildren(titleInlineContent) : titlePlainText

src/components/ContentNode/Reference.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
return name !== notFoundRouteName;
4444
},
4545
isSymbolReference() {
46-
return this.kind === 'symbol'
46+
return this.kind === 'symbol' && !this.hasInlineFormatting
4747
&& (this.role === TopicRole.symbol || this.role === TopicRole.dictionarySymbol);
4848
},
4949
isDisplaySymbol({ isSymbolReference, titleStyle, ideTitle }) {
@@ -91,6 +91,10 @@ export default {
9191
type: String,
9292
required: false,
9393
},
94+
hasInlineFormatting: {
95+
type: Boolean,
96+
default: false,
97+
},
9498
},
9599
};
96100
</script>

tests/unit/components/ContentNode.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ describe('ContentNode', () => {
10271027
expect(reference.props('url')).toBe('/foo/bar');
10281028
expect(reference.props('ideTitle')).toBe('IDETitle');
10291029
expect(reference.props('titleStyle')).toBe('symbol');
1030+
expect(reference.props('hasInlineFormatting')).toBe(false);
10301031
expect(reference.isEmpty()).toBe(false);
10311032
expect(reference.text()).toBe('FooBar');
10321033
});
@@ -1119,6 +1120,7 @@ describe('ContentNode', () => {
11191120
const reference = wrapper.find('.content').find(Reference);
11201121
expect(reference.exists()).toBe(true);
11211122
expect(reference.props('url')).toBe('/foo/bar');
1123+
expect(reference.props('hasInlineFormatting')).toBe(true);
11221124

11231125
const emphasis = reference.find('em');
11241126
expect(emphasis.exists()).toBe(true);

tests/unit/components/ContentNode/Reference.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ describe('Reference', () => {
112112
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
113113
});
114114

115+
it('renders a `ReferenceInternal` for a symbol with its own inline formatting', () => {
116+
const wrapper = shallowMount(Reference, {
117+
localVue,
118+
router,
119+
propsData: {
120+
url: '/documentation/uikit/uiview',
121+
kind: 'symbol',
122+
role: TopicRole.symbol,
123+
hasInlineFormatting: true,
124+
},
125+
slots: { default: 'custom text for UIView symbol' },
126+
});
127+
const ref = wrapper.find(ReferenceInternal);
128+
expect(ref.exists()).toBe(true);
129+
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
130+
expect(wrapper.find(ReferenceInternalSymbol).exists()).toBe(false);
131+
});
132+
115133
it('renders a `ReferenceInternal` for external "dictionarySymbol" kind references with a human readable name', () => {
116134
const wrapper = shallowMount(Reference, {
117135
localVue,

0 commit comments

Comments
 (0)