Skip to content

Commit 2a53497

Browse files
Merge pull request #13 from dvisco/master
Adding Whitelist/Blacklist capabilities
2 parents 59fa3f6 + 60fbe83 commit 2a53497

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

index.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type Props = {
1111
styles: any,
1212
children?: string,
1313
rules: Object,
14+
whitelist: Array,
15+
blacklist: Array,
1416
}
1517

1618
type DefaultProps = Props & {
@@ -25,11 +27,28 @@ class Markdown extends Component {
2527
styles: styles,
2628
children: '',
2729
rules: {},
30+
whitelist: [],
31+
blacklist: [],
32+
}
33+
34+
/** Post processes rules to strip out unwanted styling options
35+
* while keeping the default 'paragraph' and 'text' rules
36+
*/
37+
postProcessRules(preRules){
38+
const defaultRules = ['paragraph', 'text']
39+
if (this.props.whitelist.length){
40+
return _.pick(preRules, _.concat(this.props.whitelist, defaultRules))
41+
} else if (this.props.blacklist.length){
42+
return _.omit(preRules, _.pullAll(this.props.blacklist, defaultRules))
43+
} else {
44+
return preRules
45+
}
2846
}
2947

3048
renderContent = (children: string) => {
3149
const mergedStyles = Object.assign(styles, this.props.styles)
32-
const rules = _.merge({}, SimpleMarkdown.defaultRules, initialRules(mergedStyles), this.props.rules)
50+
51+
const rules = this.postProcessRules(_.merge({}, SimpleMarkdown.defaultRules, initialRules(mergedStyles), this.props.rules))
3352
const child = Array.isArray(this.props.children)
3453
? this.props.children.join('')
3554
: this.props.children

0 commit comments

Comments
 (0)