All files / src Markup.js

100% Statements 4/4
90.91% Branches 10/11
100% Functions 1/1
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                        7x 7x   7x             1x                
/**
 * @copyright   2016, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
import React, { PropTypes } from 'react';
import Parser from './Parser';
import Element from './components/Element';
 
import type { MarkupProps } from './types';
 
export default function Markup({
  content = '',
  emptyContent,
  disableLineBreaks = false,
  disableWhitelist = false,
  tagName = 'span',
  noHtml = false,
}: MarkupProps) {
  const markup = new Parser(content, { noHtml, disableLineBreaks, disableWhitelist }).parse();
  const className = noHtml ? 'interweave--no-html' : '';
 
  return (
    <Element tagName={tagName} className={className}>
      {markup.length ? markup : (emptyContent || null)}
    </Element>
  );
}
 
Markup.propTypes = {
  content: PropTypes.string,
  emptyContent: PropTypes.node,
  disableLineBreaks: PropTypes.bool,
  disableWhitelist: PropTypes.bool,
  tagName: PropTypes.oneOf(['span', 'div', 'p']),
  noHtml: PropTypes.bool,
};