Skip to content

Commit 3343e95

Browse files
authored
Support thematic breaks (#791)
Add support for "thematic breaks" using `<hr>`. Resolves: rdar://125507297
1 parent 2e11342 commit 3343e95

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/components/ContentNode.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
This source file is part of the Swift.org open source project
33
4-
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
77
See https://swift.org/LICENSE.txt for license information
@@ -30,6 +30,7 @@ import TabNavigator from './ContentNode/TabNavigator.vue';
3030
import TaskList from './ContentNode/TaskList.vue';
3131
import LinksBlock from './ContentNode/LinksBlock.vue';
3232
import DeviceFrame from './ContentNode/DeviceFrame.vue';
33+
import ThematicBreak from './ContentNode/ThematicBreak.vue';
3334
3435
const { CaptionPosition, CaptionTag } = Caption.constants;
3536
@@ -49,6 +50,7 @@ export const BlockType = {
4950
row: 'row',
5051
tabNavigator: 'tabNavigator',
5152
links: 'links',
53+
thematicBreak: 'thematicBreak',
5254
};
5355
5456
const InlineType = {
@@ -421,6 +423,8 @@ function renderNode(createElement, references) {
421423
},
422424
});
423425
}
426+
case BlockType.thematicBreak:
427+
return createElement(ThematicBreak);
424428
case InlineType.codeVoice:
425429
return createElement(CodeVoice, {}, (
426430
node.code
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 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+
<template>
11+
<hr class="thematic-break" />
12+
</template>
13+
14+
<style scoped lang="scss">
15+
@import 'docc-render/styles/_core.scss';
16+
17+
.thematic-break {
18+
@include space-out-between-siblings(var(--spacing-stacked-margin-xlarge));
19+
border-top-color: var(--color-grid, currentColor);
20+
border-top-style: solid;
21+
border-width: 1px 0 0 0;
22+
}
23+
</style>

tests/unit/components/ContentNode.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This source file is part of the Swift.org open source project
33
*
4-
* Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
4+
* Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
* Licensed under Apache License v2.0 with Runtime Library Exception
66
*
77
* See https://swift.org/LICENSE.txt for license information
@@ -31,6 +31,7 @@ import TaskList from 'docc-render/components/ContentNode/TaskList.vue';
3131
import { TopicSectionsStyle } from '@/constants/TopicSectionsStyle';
3232
import LinksBlock from '@/components/ContentNode/LinksBlock.vue';
3333
import DeviceFrame from '@/components/ContentNode/DeviceFrame.vue';
34+
import ThematicBreak from 'docc-render/components/ContentNode/ThematicBreak.vue';
3435

3536
const { TableHeaderStyle, TableColumnAlignments } = ContentNode.constants;
3637

@@ -1820,6 +1821,14 @@ describe('ContentNode', () => {
18201821
});
18211822
});
18221823

1824+
describe('with type="thematicBreak"', () => {
1825+
it('renders a `ThematicBreak`', () => {
1826+
const wrapper = mountWithItem({ type: ContentNode.BlockType.thematicBreak });
1827+
const tbreak = wrapper.find(ThematicBreak);
1828+
expect(tbreak.exists()).toBe(true);
1829+
});
1830+
});
1831+
18231832
describe('with type="superscript"', () => {
18241833
it('renders superscript tag', () => {
18251834
const wrapper = mountWithItem({
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* This source file is part of the Swift.org open source project
3+
*
4+
* Copyright (c) 2024 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+
import { shallowMount } from '@vue/test-utils';
11+
import ThematicBreak from 'docc-render/components/ContentNode/ThematicBreak.vue';
12+
13+
describe('ThematicBreak', () => {
14+
it('renders an <hr> element', () => {
15+
const wrapper = shallowMount(ThematicBreak);
16+
const hr = wrapper.find('hr');
17+
expect(hr.exists()).toBe(true);
18+
expect(hr.classes('thematic-break')).toBe(true);
19+
});
20+
});

0 commit comments

Comments
 (0)