diff --git a/services/clsi/app/js/ConversionController.js b/services/clsi/app/js/ConversionController.js index 4f79e921c8..1e62cd9873 100644 --- a/services/clsi/app/js/ConversionController.js +++ b/services/clsi/app/js/ConversionController.js @@ -19,6 +19,7 @@ import { z } from '@overleaf/validation-tools' const CONVERSION_CONFIGS = { docx: { extension: 'docx' }, markdown: { extension: 'zip' }, + html: { extension: 'zip' }, } async function convertDocumentToLaTeX(req, res) { diff --git a/services/clsi/app/js/ConversionManager.js b/services/clsi/app/js/ConversionManager.js index d181744878..210f9f57f7 100644 --- a/services/clsi/app/js/ConversionManager.js +++ b/services/clsi/app/js/ConversionManager.js @@ -162,6 +162,19 @@ const LATEX_EXPORT_CONFIGS = { 'markdown', ], }, + html: { + fileExtension: 'html', + compressOutput: true, + getPandocArgs: ({ outputPath }) => [ + '--output', + outputPath, + '--from', + 'latex', + '--to', + 'html', + '--standalone', + ], + }, } async function convertLaTeXToDocumentInDirWithLock( diff --git a/services/clsi/test/unit/js/ConversionController.test.js b/services/clsi/test/unit/js/ConversionController.test.js index 365f07d05a..4ae462a64d 100644 --- a/services/clsi/test/unit/js/ConversionController.test.js +++ b/services/clsi/test/unit/js/ConversionController.test.js @@ -592,6 +592,37 @@ describe('ConversionController', function () { }) }) + describe('with conversionType=html', function () { + beforeEach(async function (ctx) { + ctx.req.query = { type: 'html' } + ctx.fs.stat.resolves(ctx.documentStat) + + await ctx.ConversionController.convertProjectToDocument( + ctx.req, + ctx.res, + sinon.stub() + ) + }) + + it('should call convertLaTeXToDocumentInDirWithLock with type=html', function (ctx) { + sinon.assert.calledWith( + ctx.ConversionManager.promises.convertLaTeXToDocumentInDirWithLock, + sinon.match( + /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ + ), + sinon.match( + /^\/compiles\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ + ), + 'main.tex', + 'html' + ) + }) + + it('should set the attachment filename with .zip extension', function (ctx) { + sinon.assert.calledWith(ctx.res.attachment, 'output.zip') + }) + }) + describe('when conversion fails', function () { beforeEach(async function (ctx) { ctx.next = sinon.stub() diff --git a/services/clsi/test/unit/js/ConversionManager.test.js b/services/clsi/test/unit/js/ConversionManager.test.js index 71d22fb33b..e4b3945720 100644 --- a/services/clsi/test/unit/js/ConversionManager.test.js +++ b/services/clsi/test/unit/js/ConversionManager.test.js @@ -77,6 +77,24 @@ const LATEX_TO_DOCUMENT_CASES = [ '--extract-media=.', ], }, + { + type: 'html', + extension: 'html', + compressOutput: true, + pandocArgs: outputId => [ + 'pandoc', + Path.join('..', 'main.tex'), + '--output', + 'main.html', + '--from', + 'latex', + '--to', + 'html', + '--standalone', + '--resource-path=..', + '--extract-media=.', + ], + }, ] describe('ConversionManager', function () {