Remove markdown from client-side

Markdown parser takes too much space in the final compressed bundle
This commit is contained in:
Jerko Steiner 2019-04-11 12:05:58 +08:00
parent 9d282b278d
commit 7711a9596c
4 changed files with 1 additions and 44 deletions

View File

@ -9,7 +9,7 @@ add:
cp -r template/* packages/$(name)/ cp -r template/* packages/$(name)/
clean: clean:
rm -rf packages/*/lib rm -rf packages/*/{lib,esm}
sync-esm-config: sync-esm-config:
node scripts/sync-esm-config.js node scripts/sync-esm-config.js

View File

@ -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)!
<script>alert(2)</script>
<a href='mailto:test@test.com'>Test</a>
<img src="/my/image" onerror="javascript:alert(1)">`)
expect(html).toEqual(`<p>Hey check <a href="example.com">this</a>!</p>
<p><a href="mailto:test@test.com">Test</a>
<img src="/my/image" /></p>
`)
})
})
})

View File

@ -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()
}
}

View File

@ -9,7 +9,6 @@ export * from './IUser'
export * from './IUser' export * from './IUser'
export * from './IUserInTeam' export * from './IUserInTeam'
export * from './IUserTeam' export * from './IUserTeam'
export * from './Markdown'
export * from './StringUtils' export * from './StringUtils'
export * from './URLFormatter' export * from './URLFormatter'
export * from './filterProps' export * from './filterProps'