Remove markdown from client-side
Markdown parser takes too much space in the final compressed bundle
This commit is contained in:
parent
9d282b278d
commit
7711a9596c
@ -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
|
||||||
|
|||||||
@ -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>
|
|
||||||
`)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user