Skip to content

Commit 2dfbf67

Browse files
committed
✨(frontend) move html option to downloads section
makes the option less visible as it's not useful to most users Signed-off-by: Cyril <c.gromoff@gmail.com>
1 parent 3fee1f2 commit 2dfbf67

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

src/frontend/apps/impress/src/features/docs/doc-export/components/ModalExport.tsx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import { TemplatesOrdering, useTemplates } from '../api/useTemplates';
2626
import { docxDocsSchemaMappings } from '../mappingDocx';
2727
import { odtDocsSchemaMappings } from '../mappingODT';
2828
import { pdfDocsSchemaMappings } from '../mappingPDF';
29-
import { downloadFile } from '../utils';
29+
import { downloadFile, escapeHtml } from '../utils';
3030

3131
enum DocDownloadFormat {
32+
HTML = 'html',
3233
PDF = 'pdf',
3334
DOCX = 'docx',
3435
ODT = 'odt',
@@ -142,6 +143,26 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
142143
});
143144

144145
blobExport = await exporter.toODTDocument(exportDocument);
146+
} else if (format === DocDownloadFormat.HTML) {
147+
const editorHtml = await editor.blocksToHTMLLossy();
148+
const lang = i18next.language || 'fr';
149+
150+
const htmlContent = `<!DOCTYPE html>
151+
<html lang="${lang}">
152+
<head>
153+
<meta charset="utf-8" />
154+
<title>${escapeHtml(documentTitle)}</title>
155+
</head>
156+
<body>
157+
<main role="main">
158+
${editorHtml}
159+
</main>
160+
</body>
161+
</html>`;
162+
163+
blobExport = new Blob([htmlContent], {
164+
type: 'text/html;charset=utf-8',
165+
});
145166
} else {
146167
toast(t('The export failed'), VariantType.ERROR);
147168
setIsExporting(false);
@@ -228,16 +249,6 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
228249
<Text $variation="600" $size="sm" as="p">
229250
{t('Download your document in a .docx, .odt or .pdf format.')}
230251
</Text>
231-
<Select
232-
clearable={false}
233-
fullWidth
234-
label={t('Template')}
235-
options={templateOptions}
236-
value={templateSelected}
237-
onChange={(options) =>
238-
setTemplateSelected(options.target.value as string)
239-
}
240-
/>
241252
<Select
242253
clearable={false}
243254
fullWidth
@@ -246,12 +257,24 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
246257
{ label: t('Docx'), value: DocDownloadFormat.DOCX },
247258
{ label: t('ODT'), value: DocDownloadFormat.ODT },
248259
{ label: t('PDF'), value: DocDownloadFormat.PDF },
260+
{ label: t('HTML'), value: DocDownloadFormat.HTML },
249261
]}
250262
value={format}
251263
onChange={(options) =>
252264
setFormat(options.target.value as DocDownloadFormat)
253265
}
254266
/>
267+
<Select
268+
clearable={false}
269+
fullWidth
270+
label={t('Template')}
271+
options={templateOptions}
272+
value={templateSelected}
273+
disabled={format === DocDownloadFormat.HTML}
274+
onChange={(options) =>
275+
setTemplateSelected(options.target.value as string)
276+
}
277+
/>
255278

256279
{isExporting && (
257280
<Box

src/frontend/apps/impress/src/features/docs/doc-export/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,12 @@ export function odtRegisterParagraphStyleForBlock(
179179

180180
return styleName;
181181
}
182+
183+
// Escape user-provided text before injecting it into the exported HTML document.
184+
export const escapeHtml = (value: string): string =>
185+
value
186+
.replace(/&/g, '&amp;')
187+
.replace(/</g, '&lt;')
188+
.replace(/>/g, '&gt;')
189+
.replace(/"/g, '&quot;')
190+
.replace(/'/g, '&#39;');

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
KEY_LIST_DOC_VERSIONS,
3434
ModalSelectVersion,
3535
} from '@/docs/doc-versioning';
36-
import { useAnalytics } from '@/libs';
3736
import { useResponsiveStore } from '@/stores';
3837

3938
import { useCopyCurrentEditorToClipboard } from '../hooks/useCopyCurrentEditorToClipboard';
@@ -67,7 +66,6 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
6766
void router.push(`/docs/${data.id}`);
6867
},
6968
});
70-
const { isFeatureFlagActivated } = useAnalytics();
7169
const removeFavoriteDoc = useDeleteFavoriteDoc({
7270
listInvalidQueries: [KEY_LIST_DOC, KEY_DOC],
7371
});
@@ -155,14 +153,6 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
155153
callback: () => {
156154
void copyCurrentEditorToClipboard('markdown');
157155
},
158-
},
159-
{
160-
label: t('Copy as {{format}}', { format: 'HTML' }),
161-
icon: 'content_copy',
162-
callback: () => {
163-
void copyCurrentEditorToClipboard('html');
164-
},
165-
show: isFeatureFlagActivated('CopyAsHTML'),
166156
showSeparator: true,
167157
},
168158
{

0 commit comments

Comments
 (0)