@@ -26,9 +26,10 @@ import { TemplatesOrdering, useTemplates } from '../api/useTemplates';
2626import { docxDocsSchemaMappings } from '../mappingDocx' ;
2727import { odtDocsSchemaMappings } from '../mappingODT' ;
2828import { pdfDocsSchemaMappings } from '../mappingPDF' ;
29- import { downloadFile } from '../utils' ;
29+ import { downloadFile , escapeHtml } from '../utils' ;
3030
3131enum 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 ) ;
@@ -227,16 +248,6 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
227248 < Text $variation = "secondary" $size = "sm" as = "p" >
228249 { t ( 'Download your document in a .docx, .odt or .pdf format.' ) }
229250 </ Text >
230- < Select
231- clearable = { false }
232- fullWidth
233- label = { t ( 'Template' ) }
234- options = { templateOptions }
235- value = { templateSelected }
236- onChange = { ( options ) =>
237- setTemplateSelected ( options . target . value as string )
238- }
239- />
240251 < Select
241252 clearable = { false }
242253 fullWidth
@@ -245,12 +256,24 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
245256 { label : t ( 'Docx' ) , value : DocDownloadFormat . DOCX } ,
246257 { label : t ( 'ODT' ) , value : DocDownloadFormat . ODT } ,
247258 { label : t ( 'PDF' ) , value : DocDownloadFormat . PDF } ,
259+ { label : t ( 'HTML' ) , value : DocDownloadFormat . HTML } ,
248260 ] }
249261 value = { format }
250262 onChange = { ( options ) =>
251263 setFormat ( options . target . value as DocDownloadFormat )
252264 }
253265 />
266+ < Select
267+ clearable = { false }
268+ fullWidth
269+ label = { t ( 'Template' ) }
270+ options = { templateOptions }
271+ value = { templateSelected }
272+ disabled = { format === DocDownloadFormat . HTML }
273+ onChange = { ( options ) =>
274+ setTemplateSelected ( options . target . value as string )
275+ }
276+ />
254277
255278 { isExporting && (
256279 < Box
0 commit comments