Skip to content

Commit 009f87b

Browse files
author
Dobromir Hristov
authored
Add support for @Small directive (#405)
closes rdar://97717135
1 parent 7821ca6 commit 009f87b

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/components/ContentNode.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import InlineImage from './ContentNode/InlineImage.vue';
2020
import Reference from './ContentNode/Reference.vue';
2121
import Table from './ContentNode/Table.vue';
2222
import StrikeThrough from './ContentNode/StrikeThrough.vue';
23+
import Small from './ContentNode/Small.vue';
2324

2425
const BlockType = {
2526
aside: 'aside',
@@ -32,6 +33,7 @@ const BlockType = {
3233
termList: 'termList',
3334
unorderedList: 'unorderedList',
3435
dictionaryExample: 'dictionaryExample',
36+
small: 'small',
3537
};
3638

3739
const InlineType = {
@@ -275,6 +277,11 @@ function renderNode(createElement, references) {
275277
};
276278
return createElement(DictionaryExample, { props }, renderChildren(node.summary || []));
277279
}
280+
case BlockType.small: {
281+
return createElement('p', {}, [
282+
createElement(Small, {}, renderChildren(node.inlineContent)),
283+
]);
284+
}
278285
case InlineType.codeVoice:
279286
return createElement(CodeVoice, {}, (
280287
node.code
@@ -310,7 +317,7 @@ function renderNode(createElement, references) {
310317
const reference = references[node.identifier];
311318
if (!reference) return null;
312319
const titleInlineContent = node.overridingTitleInlineContent
313-
|| reference.titleInlineContent;
320+
|| reference.titleInlineContent;
314321
const titlePlainText = node.overridingTitle || reference.title;
315322
return createElement(Reference, {
316323
props: {

src/components/ContentNode/Small.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
-->
10+
11+
<template>
12+
<small>
13+
<slot />
14+
</small>
15+
</template>
16+
17+
<script>
18+
export default {
19+
name: 'Small',
20+
};
21+
</script>
22+
23+
<style scoped lang='scss'>
24+
@import 'docc-render/styles/_core.scss';
25+
26+
small {
27+
@include font-styles(body-reduced-tight);
28+
color: var(--color-figure-gray);
29+
}
30+
</style>

src/styles/core/typography/_font-styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,5 @@ $font-styles: (
194194
),
195195
nav-menu-collapsible: (
196196
large: (nav_14_14, nav)
197-
)
197+
),
198198
) !default;

tests/unit/components/ContentNode.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import InlineImage from 'docc-render/components/ContentNode/InlineImage.vue';
2121
import Reference from 'docc-render/components/ContentNode/Reference.vue';
2222
import Table from 'docc-render/components/ContentNode/Table.vue';
2323
import StrikeThrough from 'docc-render/components/ContentNode/StrikeThrough.vue';
24+
import Small from '@/components/ContentNode/Small.vue';
2425

2526
const { TableHeaderStyle } = ContentNode.constants;
2627

@@ -320,6 +321,24 @@ describe('ContentNode', () => {
320321
});
321322
});
322323

324+
describe('with type="small"', () => {
325+
it('renders a `<Small>`', () => {
326+
const wrapper = mountWithItem({
327+
type: 'small',
328+
inlineContent: [
329+
{
330+
type: 'text',
331+
text: 'foo',
332+
},
333+
],
334+
});
335+
const paragraph = wrapper.find('p');
336+
const small = paragraph.find(Small);
337+
expect(small.exists()).toBe(true);
338+
expect(small.text()).toBe('foo');
339+
});
340+
});
341+
323342
describe('with type="codeVoice"', () => {
324343
it('renders a `CodeVoice`', () => {
325344
const wrapper = mountWithItem({

0 commit comments

Comments
 (0)