Skip to content

Commit cbc6a32

Browse files
committed
fix(NcRichText): start heading from h4
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
1 parent 1b0373b commit cbc6a32

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

cypress/component/richtext.cy.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ describe('NcRichText', () => {
6262
describe('headings', () => {
6363
it('heading (with hash (#) syntax divided with space from text)', () => {
6464
const testCases = [
65-
{ tag: 'h1', input: '# heading 1', output: 'heading 1' },
66-
{ tag: 'h2', input: '## heading 2', output: 'heading 2' },
67-
{ tag: 'h3', input: '### heading 3', output: 'heading 3' },
68-
{ tag: 'h4', input: '#### heading 4', output: 'heading 4' },
69-
{ tag: 'h5', input: '##### heading 5', output: 'heading 5' },
65+
{ tag: 'h4', input: '# heading 1', output: 'heading 1' },
66+
{ tag: 'h5', input: '## heading 2', output: 'heading 2' },
67+
{ tag: 'h6', input: '### heading 3', output: 'heading 3' },
68+
{ tag: 'h6', input: '#### heading 4', output: 'heading 4' },
69+
{ tag: 'h6', input: '##### heading 5', output: 'heading 5' },
7070
{ tag: 'h6', input: '###### heading 6', output: 'heading 6' },
7171
]
7272

@@ -101,7 +101,7 @@ describe('NcRichText', () => {
101101
},
102102
})
103103

104-
cy.get('h1').should('have.text', 'heading 1')
104+
cy.get('h4').should('have.text', 'heading 1')
105105
})
106106

107107
it('heading 2 (with dash (-) syntax on the next line)', () => {
@@ -112,7 +112,7 @@ describe('NcRichText', () => {
112112
},
113113
})
114114

115-
cy.get('h2').should('have.text', 'heading 2')
115+
cy.get('h5').should('have.text', 'heading 2')
116116
})
117117
})
118118

src/components/NcRichText/NcRichText.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,19 @@ export default {
482482
.use(rehype2react, {
483483
createElement: (tag, attrs, children) => {
484484
if (!tag.startsWith('#')) {
485+
// <h1>..<h3> headings are used on the page for semantic structure
486+
// Using them for user content leads to accessibility issues
487+
// Levelling down headings to start from <h4>
488+
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].includes(tag)) {
489+
tag = `h${Math.min(+String(tag)[1] + 3, 6)}`
490+
}
491+
485492
if (this.useExtendedMarkdown) {
486493
if (tag === 'code' && !rehypeHighlight.value
487494
&& attrs?.attrs?.class?.includes('language')) {
488495
importRehypeHighlightLibrary()
489496
}
497+
490498
let nestedNode = null
491499
if (tag === 'li' && Array.isArray(children)
492500
&& children[0].tag === 'input'

src/components/NcRichText/richtext.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@
5252
font-weight: bold;
5353
}
5454

55-
h1 {
56-
font-size: 30px;
55+
h4 {
56+
font-size: 20px;
57+
}
58+
59+
h5 {
60+
font-size: 18px;
61+
}
62+
63+
h6 {
64+
font-size: 15px;
5765
}
5866

5967
ul, ol {

0 commit comments

Comments
 (0)