Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ and this project adheres to
- ♿(frontend) improve accessibility:
- ✨ add document visible in list and openable via enter key #1365

### Changed

- ♿(frontend) improve accessibility:
- ♿ add pdf outline property to enable bookmarks display #1368

## [3.7.0] - 2025-09-12

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,45 @@ import { Text } from '@react-pdf/renderer';

import { DocsExporterPDF } from '../types';

// Helper function to extract plain text from block content
function extractTextFromBlockContent(content: unknown[]): string {
return content
.map((item) => {
if (
typeof item === 'object' &&
item !== null &&
'type' in item &&
'text' in item
) {
if (item.type === 'text' && typeof item.text === 'string') {
return item.text;
}
}
return '';
})
.join('')
.trim();
}

export const blockMappingHeadingPDF: DocsExporterPDF['mappings']['blockMapping']['heading'] =
(block, exporter) => {
const PIXELS_PER_POINT = 0.75;
const MERGE_RATIO = 7.5;
const FONT_SIZE = 16;
const fontSizeEM =
block.props.level === 1 ? 2 : block.props.level === 2 ? 1.5 : 1.17;

// Extract plain text for bookmark title
const bookmarkTitle =
extractTextFromBlockContent(block.content) || 'Untitled';

return (
<Text
key={block.id}
// @ts-expect-error: bookmark is supported by react-pdf but not typed
bookmark={{
title: bookmarkTitle,
}}
style={{
fontSize: fontSizeEM * FONT_SIZE * PIXELS_PER_POINT,
fontWeight: 700,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
exportDocument,
)) as React.ReactElement<DocumentProps>;

// Inject language for screen reader support
// Inject language for screen reader support and enable outlines (bookmarks)
const pdfDocument = isValidElement(rawPdfDocument)
? cloneElement(rawPdfDocument, { language: i18next.language })
? cloneElement(rawPdfDocument, {
language: i18next.language,
pageMode: 'useOutlines',
})
: rawPdfDocument;

blobExport = await pdf(pdfDocument).toBlob();
Expand Down
Loading