From 7711a9596cef191757d7b41b402484659a93f408 Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Thu, 11 Apr 2019 12:05:58 +0800 Subject: [PATCH] Remove markdown from client-side Markdown parser takes too much space in the final compressed bundle --- Buildfile | 2 +- packages/common/src/Markdown.test.ts | 23 ----------------------- packages/common/src/Markdown.ts | 19 ------------------- packages/common/src/index.ts | 1 - 4 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 packages/common/src/Markdown.test.ts delete mode 100644 packages/common/src/Markdown.ts diff --git a/Buildfile b/Buildfile index f6d8aa5..4986c0d 100644 --- a/Buildfile +++ b/Buildfile @@ -9,7 +9,7 @@ add: cp -r template/* packages/$(name)/ clean: - rm -rf packages/*/lib + rm -rf packages/*/{lib,esm} sync-esm-config: node scripts/sync-esm-config.js diff --git a/packages/common/src/Markdown.test.ts b/packages/common/src/Markdown.test.ts deleted file mode 100644 index ac3fccc..0000000 --- a/packages/common/src/Markdown.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import {Markdown} from './Markdown' - -describe('Markdown', () => { - - const markdown = new Markdown() - - describe('parse', () => { - it('sanitizes html', () => { - const html = markdown.parse( - `Hey check [this](example.com)! - - -Test -`) - expect(html).toEqual(`

Hey check this!

- -

Test -

-`) - }) - }) - -}) diff --git a/packages/common/src/Markdown.ts b/packages/common/src/Markdown.ts deleted file mode 100644 index a0d43f7..0000000 --- a/packages/common/src/Markdown.ts +++ /dev/null @@ -1,19 +0,0 @@ -import marked from 'marked' -import sanitize from 'sanitize-html' - -const allowedTags = sanitize.defaults.allowedTags.concat(['img']) - -export class Markdown { - protected readonly markdownOptions = { - gfm: true, - } - protected readonly sanitizeOptions = { - allowedTags: sanitize.defaults.allowedTags.concat(['img']), - } - - parse(markdown: string): string { - const dangerousHTML = marked(markdown, this.markdownOptions) - const sanitizedHTML = sanitize(dangerousHTML, this.sanitizeOptions) - return sanitizedHTML.trim() - } -} diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index c45a37b..79af98e 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -9,7 +9,6 @@ export * from './IUser' export * from './IUser' export * from './IUserInTeam' export * from './IUserTeam' -export * from './Markdown' export * from './StringUtils' export * from './URLFormatter' export * from './filterProps'