From c74d6c6fff8f8f8ed9404e3343b7fac9378cf248 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 4 Aug 2021 12:39:35 +0530 Subject: [PATCH] Assign replacements --- src/utils/exportUtils/HtmlExport.tsx | 8 ++++++-- src/utils/exportUtils/exportCSS.ts | 8 +++++--- test/utils/export-test.tsx | 30 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx index 54e21fdf14..124914a210 100644 --- a/src/utils/exportUtils/HtmlExport.tsx +++ b/src/utils/exportUtils/HtmlExport.tsx @@ -36,6 +36,7 @@ import { ExportTypes } from "./exportUtils"; import { IExportOptions } from "./exportUtils"; import MatrixClientContext from "../../contexts/MatrixClientContext"; import getExportCSS from "./exportCSS"; +import { textForEvent } from "../../TextForEvent"; export default class HTMLExporter extends Exporter { protected avatars: Map; @@ -346,13 +347,16 @@ export default class HTMLExporter extends Exporter { ); } } else { - eventTile = await this.getEventTileMarkup(this.createModifiedEvent(this.mediaOmitText, mxEv), joined); + eventTile = await this.getEventTileMarkup( + this.createModifiedEvent(this.mediaOmitText, mxEv), + joined, + ); } } else eventTile = await this.getEventTileMarkup(mxEv, joined); } catch (e) { // TODO: Handle callEvent errors console.error(e); - eventTile = await this.getEventTileMarkup(this.createModifiedEvent("Error parsing HTML", mxEv), joined); + eventTile = await this.getEventTileMarkup(this.createModifiedEvent(textForEvent(mxEv), mxEv), joined); } return eventTile; diff --git a/src/utils/exportUtils/exportCSS.ts b/src/utils/exportUtils/exportCSS.ts index 7079967d93..8ae92b17ee 100644 --- a/src/utils/exportUtils/exportCSS.ts +++ b/src/utils/exportUtils/exportCSS.ts @@ -20,6 +20,7 @@ import ThemeWatcher from "../../settings/watchers/ThemeWatcher"; const getExportCSS = async (): Promise => { const theme = new ThemeWatcher().getEffectiveTheme(); + // eslint-disable-next-line camelcase const hash = __webpack_hash__; const bundle = await fetch(`bundles/${hash}/bundle.css`); const bundleCSS = await bundle.text(); @@ -32,13 +33,14 @@ const getExportCSS = async (): Promise => { themeCSS = await res.text(); } const fontFaceRegex = /@font-face {.*?}/sg; - themeCSS.replace(fontFaceRegex, ''); - themeCSS.replace( + + themeCSS = themeCSS.replace(fontFaceRegex, ''); + themeCSS = themeCSS.replace( /font-family: Inter/g, `font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif`, ); - themeCSS.replace( + themeCSS = themeCSS.replace( /font-family: Inconsolata/g, "font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace", ); diff --git a/test/utils/export-test.tsx b/test/utils/export-test.tsx index 279ebcff59..25bf17d0ea 100644 --- a/test/utils/export-test.tsx +++ b/test/utils/export-test.tsx @@ -37,6 +37,12 @@ describe('export', function() { return MY_USER_ID; }; + const mockExportOptions: IExportOptions = { + numberOfMessages: 5, + maxSize: 100 * 1024 * 1024, + attachmentsIncluded: false, + }; + const invalidExportOptions: IExportOptions[] = [ { numberOfMessages: 10**9, @@ -97,5 +103,29 @@ describe('export', function() { } } }); + + it('tests the file extension splitter', function() { + const exporter = new PlainTextExporter(room, ExportTypes.BEGINNING, mockExportOptions, null); + const fileNameWithExtensions = { + "": ["", ""], + "name": ["name", ""], + "name.txt": ["name", ".txt"], + ".htpasswd": ["", ".htpasswd"], + "name.with.many.dots.myext": ["name.with.many.dots", ".myext"], + }; + for (const fileName in fileNameWithExtensions) { + expect(exporter.splitFileName(fileName)).toStrictEqual(fileNameWithExtensions[fileName]); + } + }); + + // it('checks if the reply regex executes correctly', function() { + // const eventContents = [ + // { + // "msgtype": "m.text", + // "body": "> <@me:here> Testing....\n\nTest", + // "expectedText": "", + // }, + // ]; + // }); });