Skip to content

Commit aa103cd

Browse files
committed
fix(headings): skip headings in blockquotes in table of contents
Signed-off-by: Jonas <jonas@freesources.org>
1 parent f33c131 commit aa103cd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/plugins/extractHeadings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default function extractHeadings(doc: Node) {
3131
}
3232

3333
doc.descendants((node, offset) => {
34-
// Don't descent into detials blocks - their headings are hidden
35-
if (node.type.name === 'details') {
34+
// Don't descent into details/blockquote nodes - their headings are hidden
35+
if (node.type.name === 'details' || node.type.name === 'blockquote') {
3636
return false
3737
}
3838
if (node.type.name !== 'heading') {

src/tests/plugins/extractHeadings.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import Blockquote from '@tiptap/extension-blockquote'
67
import Details from '../../nodes/Details.js'
78
import Heading from '../../nodes/Heading.js'
89
import extractHeadings from '../../plugins/extractHeadings.ts'
@@ -50,6 +51,19 @@ describe('extractHeadings', () => {
5051
expect(headings[0].text).toBe('Visible heading')
5152
})
5253

54+
it('ignores headings inside a block quote block', () => {
55+
const content = `
56+
<h1>Visible heading</h1>
57+
<blockquote>
58+
<h1>Quoted heading</h1>
59+
</blockquote>
60+
`
61+
const doc = prepareDoc(content, [Blockquote])
62+
const headings = extractHeadings(doc)
63+
expect(headings).toHaveLength(1)
64+
expect(headings[0].text).toBe('Visible heading')
65+
})
66+
5367
it('creates unique ids with a counter', () => {
5468
const content = `
5569
<h1>Level 1 heading</h1>

0 commit comments

Comments
 (0)