-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Translations): add sanitized formatted html
- Loading branch information
plondon
committed
May 30, 2018
1 parent
bc802e9
commit 0ae3a1b
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/blockchain-wallet-v4-frontend/src/components/SanitizedFormattedHTMLMessage/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { FormattedHTMLMessage } from 'react-intl' | ||
import sanitizeHtml from 'sanitize-html' | ||
|
||
class SanitizedFormattedHTMLMessage extends React.Component { | ||
clean (dirty) { | ||
return sanitizeHtml(dirty, { allowedTags: ['span', 'a'] }) | ||
} | ||
|
||
render () { | ||
const { id, defaultMessage } = this.props | ||
const clean = this.clean(defaultMessage) | ||
return clean ? <FormattedHTMLMessage id={id} defaultMessage={clean} /> : null | ||
} | ||
} | ||
|
||
SanitizedFormattedHTMLMessage.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
defaultMessage: PropTypes.string.isRequired | ||
} | ||
|
||
export default SanitizedFormattedHTMLMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters