Skip to content

Commit e842ae8

Browse files
committed
✨(frontend) exclude h4-h6 headings from table of contents
filters out h4-h6 so they no longer appear in the document outline Signed-off-by: Cyril <[email protected]>
1 parent 6cc4263 commit e842ae8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ and this project adheres to
3333
- 🐛(frontend) fix 404 page when reload 403 page #1402
3434
- 🐛(frontend) fix legacy role computation #1376
3535
- 🐛(frontend) scroll back to top when navigate to a document #1406
36+
- 🐛(frontend) exclude h4-h6 headings from table of contents #1441
37+
3638

3739
### Changed
3840

src/frontend/apps/impress/src/features/docs/doc-table-content/components/TableContent.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ export const TableContent = () => {
1919
const { t } = useTranslation();
2020
const [isHover, setIsHover] = useState(false);
2121

22+
// Filter headings to only show h1, h2, h3 (levels 1-3)
23+
const filteredHeadings = headings?.filter(
24+
(heading) => heading.props.level >= 1 && heading.props.level <= 3,
25+
);
26+
2227
useEffect(() => {
2328
const handleScroll = () => {
24-
if (!headings) {
29+
if (!filteredHeadings) {
2530
return;
2631
}
2732

28-
for (const heading of headings) {
33+
for (const heading of filteredHeadings) {
2934
const elHeading = document.body.querySelector(
3035
`.bn-block-outer[data-id="${heading.id}"] [data-content-type="heading"]:first-child`,
3136
);
@@ -69,7 +74,7 @@ export const TableContent = () => {
6974
.getElementById(MAIN_LAYOUT_ID)
7075
?.removeEventListener('scroll', scrollFn);
7176
};
72-
}, [headings, setHeadingIdHighlight]);
77+
}, [filteredHeadings, setHeadingIdHighlight]);
7378

7479
const onOpen = () => {
7580
setIsHover(true);
@@ -88,12 +93,13 @@ export const TableContent = () => {
8893
setIsHover(false);
8994
};
9095

91-
if (
96+
const shouldHideTableContent =
9297
!editor ||
93-
!headings ||
94-
headings.length === 0 ||
95-
(headings.length === 1 && !headings[0].contentText)
96-
) {
98+
!filteredHeadings ||
99+
filteredHeadings.length === 0 ||
100+
(filteredHeadings.length === 1 && !filteredHeadings[0].contentText);
101+
102+
if (shouldHideTableContent) {
97103
return null;
98104
}
99105

@@ -162,7 +168,7 @@ export const TableContent = () => {
162168
overflow-y: auto;
163169
`}
164170
>
165-
{headings?.map(
171+
{filteredHeadings?.map(
166172
(heading) =>
167173
heading.contentText && (
168174
<Heading

0 commit comments

Comments
 (0)