✨(docs) add title metadata to exported docx/pdf for accessibility
ensures document title is preserved in exports to meet accessibility needs Signed-off-by: Cyril <c.gromoff@gmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@ and this project adheres to
|
|||||||
- ♿(frontend) improve accessibility:
|
- ♿(frontend) improve accessibility:
|
||||||
- #1354
|
- #1354
|
||||||
- ♿ improve accessibility by adding landmark roles to layout #1394
|
- ♿ improve accessibility by adding landmark roles to layout #1394
|
||||||
- ✨ add document visible in list and openable via enter key #1365
|
- ♿ add document visible in list and openable via enter key #1365
|
||||||
- ♿ add pdf outline property to enable bookmarks display #1368
|
- ♿ add pdf outline property to enable bookmarks display #1368
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -28,6 +28,8 @@ and this project adheres to
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- ✨(api) add API route to fetch document content #1206
|
- ✨(api) add API route to fetch document content #1206
|
||||||
|
- ♿(frontend) improve accessibility:
|
||||||
|
- #1349
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ test.describe('Doc Export', () => {
|
|||||||
|
|
||||||
expect(pdfData.numpages).toBe(2);
|
expect(pdfData.numpages).toBe(2);
|
||||||
expect(pdfData.text).toContain('\n\nHello\n\nWorld'); // This is the doc text
|
expect(pdfData.text).toContain('\n\nHello\n\nWorld'); // This is the doc text
|
||||||
|
expect(pdfData.info.Title).toBe(randomDoc);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it exports the doc to docx', async ({ page, browserName }) => {
|
test('it exports the doc to docx', async ({ page, browserName }) => {
|
||||||
|
|||||||
@@ -76,12 +76,14 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
|
|||||||
|
|
||||||
setIsExporting(true);
|
setIsExporting(true);
|
||||||
|
|
||||||
const title = (doc.title || untitledDocument)
|
const filename = (doc.title || untitledDocument)
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.normalize('NFD')
|
.normalize('NFD')
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
.replace(/\s/g, '-');
|
.replace(/\s/g, '-');
|
||||||
|
|
||||||
|
const documentTitle = doc.title || untitledDocument;
|
||||||
|
|
||||||
const html = templateSelected;
|
const html = templateSelected;
|
||||||
let exportDocument = editor.document;
|
let exportDocument = editor.document;
|
||||||
if (html) {
|
if (html) {
|
||||||
@@ -98,10 +100,11 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
|
|||||||
exportDocument,
|
exportDocument,
|
||||||
)) as React.ReactElement<DocumentProps>;
|
)) as React.ReactElement<DocumentProps>;
|
||||||
|
|
||||||
// Inject language for screen reader support and enable outlines (bookmarks)
|
// Add language, title and outline properties to improve PDF accessibility and navigation
|
||||||
const pdfDocument = isValidElement(rawPdfDocument)
|
const pdfDocument = isValidElement(rawPdfDocument)
|
||||||
? cloneElement(rawPdfDocument, {
|
? cloneElement(rawPdfDocument, {
|
||||||
language: i18next.language,
|
language: i18next.language,
|
||||||
|
title: documentTitle,
|
||||||
pageMode: 'useOutlines',
|
pageMode: 'useOutlines',
|
||||||
})
|
})
|
||||||
: rawPdfDocument;
|
: rawPdfDocument;
|
||||||
@@ -112,10 +115,13 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
|
|||||||
resolveFileUrl: async (url) => exportCorsResolveFileUrl(doc.id, url),
|
resolveFileUrl: async (url) => exportCorsResolveFileUrl(doc.id, url),
|
||||||
});
|
});
|
||||||
|
|
||||||
blobExport = await exporter.toBlob(exportDocument);
|
blobExport = await exporter.toBlob(exportDocument, {
|
||||||
|
documentOptions: { title: documentTitle },
|
||||||
|
sectionOptions: {},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadFile(blobExport, `${title}.${format}`);
|
downloadFile(blobExport, `${filename}.${format}`);
|
||||||
|
|
||||||
toast(
|
toast(
|
||||||
t('Your {{format}} was downloaded succesfully', {
|
t('Your {{format}} was downloaded succesfully', {
|
||||||
|
|||||||
Reference in New Issue
Block a user