Эх сурвалжийг харах

Merge pull request #34145 from overleaf/ds-download-html-using-pandoc-clsi-1

[CLSI] Download as HTML feature

GitOrigin-RevId: 374101c1f957a00eda423a6be0363c08b5de7a95
Mathias Jakobsen 2 сар өмнө
parent
commit
fc31a88767

+ 1 - 0
services/clsi/app/js/ConversionController.js

@@ -19,6 +19,7 @@ import { z } from '@overleaf/validation-tools'
 const CONVERSION_CONFIGS = {
 const CONVERSION_CONFIGS = {
   docx: { extension: 'docx' },
   docx: { extension: 'docx' },
   markdown: { extension: 'zip' },
   markdown: { extension: 'zip' },
+  html: { extension: 'zip' },
 }
 }
 
 
 async function convertDocumentToLaTeX(req, res) {
 async function convertDocumentToLaTeX(req, res) {

+ 13 - 0
services/clsi/app/js/ConversionManager.js

@@ -162,6 +162,19 @@ const LATEX_EXPORT_CONFIGS = {
       'markdown',
       'markdown',
     ],
     ],
   },
   },
+  html: {
+    fileExtension: 'html',
+    compressOutput: true,
+    getPandocArgs: ({ outputPath }) => [
+      '--output',
+      outputPath,
+      '--from',
+      'latex',
+      '--to',
+      'html',
+      '--standalone',
+    ],
+  },
 }
 }
 
 
 async function convertLaTeXToDocumentInDirWithLock(
 async function convertLaTeXToDocumentInDirWithLock(

+ 31 - 0
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 () {
     describe('when conversion fails', function () {
       beforeEach(async function (ctx) {
       beforeEach(async function (ctx) {
         ctx.next = sinon.stub()
         ctx.next = sinon.stub()

+ 18 - 0
services/clsi/test/unit/js/ConversionManager.test.js

@@ -77,6 +77,24 @@ const LATEX_TO_DOCUMENT_CASES = [
       '--extract-media=.',
       '--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 () {
 describe('ConversionManager', function () {