Skip to content

Commit e8142b2

Browse files
authored
Merge pull request #7748 from nextcloud-libraries/fix/NcRichText--h4
fix(NcRichText): start heading from h4
2 parents e945848 + abdc336 commit e8142b2

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/components/NcRichText/NcRichText.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,13 @@ export default {
546546
delete props.children
547547
548548
if (!String(type).startsWith('#')) {
549+
// <h1>..<h3> headings are used on the page for semantic structure
550+
// Using them for user content leads to accessibility issues
551+
// Levelling down headings to start from <h4>
552+
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].includes(String(type))) {
553+
type = `h${Math.min(+String(type)[1] + 3, 6)}`
554+
}
555+
549556
let nestedNode = null
550557
if (this.useExtendedMarkdown) {
551558
if (String(type) === 'code' && !rehypeHighlight.value
@@ -681,8 +688,16 @@ export default {
681688
font-weight: bold;
682689
}
683690
684-
h1 {
685-
font-size: 30px;
691+
h4 {
692+
font-size: 20px;
693+
}
694+
695+
h5 {
696+
font-size: 18px;
697+
}
698+
699+
h6 {
700+
font-size: 15px;
686701
}
687702
688703
ul, ol {

tests/component/components/NcRichText/markown-rendering.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ test.describe('headings', () => {
110110
},
111111
})
112112

113-
await expect(component.getByRole('heading', { level: 1 })).toHaveText('heading 1')
114-
await expect(component.getByRole('heading', { level: 2 })).toHaveText('heading 2')
115-
await expect(component.getByRole('heading', { level: 3 })).toHaveText('heading 3')
116-
await expect(component.getByRole('heading', { level: 4 })).toHaveText('heading 4')
117-
await expect(component.getByRole('heading', { level: 5 })).toHaveText('heading 5')
118-
await expect(component.getByRole('heading', { level: 6 })).toHaveText('heading 6')
113+
await expect(component.getByText('heading 1')).toHaveJSProperty('tagName', 'H4')
114+
await expect(component.getByText('heading 2')).toHaveJSProperty('tagName', 'H5')
115+
await expect(component.getByText('heading 3')).toHaveJSProperty('tagName', 'H6')
116+
await expect(component.getByText('heading 4')).toHaveJSProperty('tagName', 'H6')
117+
await expect(component.getByText('heading 5')).toHaveJSProperty('tagName', 'H6')
118+
await expect(component.getByText('heading 6')).toHaveJSProperty('tagName', 'H6')
119119
})
120120

121121
test('ignore heading (with hash (#) syntax padded to the text)', async ({ mount }) => {
@@ -138,7 +138,7 @@ test.describe('headings', () => {
138138
},
139139
})
140140

141-
await expect(component.getByRole('heading', { level: 1 })).toHaveText('heading 1')
141+
await expect(component.getByText('heading 1')).toHaveJSProperty('tagName', 'H4')
142142
})
143143

144144
test('render heading 2 (with dash (-) syntax on the next line)', async ({ mount }) => {
@@ -149,7 +149,7 @@ test.describe('headings', () => {
149149
},
150150
})
151151

152-
await expect(component.getByRole('heading', { level: 2 })).toHaveText('heading 2')
152+
await expect(component.getByText('heading 2')).toHaveJSProperty('tagName', 'H5')
153153
})
154154
})
155155

0 commit comments

Comments
 (0)