@@ -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 ) ;
@@ -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
0 commit comments