'use strict';

var React = require('react');
var Parser = require('commonmark').Parser;
var ReactRenderer = require('commonmark-react-renderer');

var parser = new Parser();

var ReactMarkdown = React.createClass({
    displayName: 'ReactMarkdown',

    propTypes: {
        className: React.PropTypes.string,
        source: React.PropTypes.string.isRequired,
        containerTagName: React.PropTypes.string,
        sourcePos: React.PropTypes.bool,
        escapeHtml: React.PropTypes.bool,
        skipHtml: React.PropTypes.bool,
        softBreak: React.PropTypes.string,
        highlight: React.PropTypes.func
    },

    getDefaultProps: function() {
        return {
            containerTagName: 'div'
        };
    },

    render: function() {
        var containerProps = {};
        var renderer = new ReactRenderer(this.props);
        var ast = parser.parse(this.props.source || '');

        if (this.props.className) {
            containerProps.className = this.props.className;
        }

        return React.createElement.apply(React,
            [this.props.containerTagName, containerProps]
                .concat(renderer.render(ast))
        );
    }
});

module.exports = ReactMarkdown;

@@ -42,22 +42,26 @@
 ');%0Avar 
-Parser
+commonmark
  = requi
@@ -80,101 +80,398 @@
 rk')
-.Parser;%0Avar ReactRenderer = require('commonmark-react-renderer');%0A%0Avar parser = new Parser()
+;%0A%0A// ignoring keys in (b) that are not found in (a)%0Avar srcEquals = function srcEquals(a, b) %7B%0A    for (var k in a) %7B%0A        if (a%5Bk%5D !== b%5Bk%5D) %7B%0A            return false;%0A        %7D%0A    %7D%0A%0A    return true;%0A%7D;%0A%0Avar copyKeys = function copyKeys(keys, b) %7B%0A    var obj = %7B%7D;%0A    for (var i = 0; i %3C keys.length; i++) %7B%0A        var k = keys%5Bi%5D;%0A        obj%5Bk%5D = b%5Bk%5D;%0A    %7D%0A%0A    return obj;%0A%7D
 ;%0A%0Av
@@ -612,21 +612,31 @@
         
-sourc
+containerTagNam
 e: React
@@ -656,44 +656,23 @@
 ring
-.isRequired,%0A        containerTagNam
+,%0A        sourc
 e: R
@@ -684,32 +684,43 @@
 PropTypes.string
+.isRequired
 ,%0A        source
@@ -940,32 +940,48 @@
 tProps: function
+ getDefaultProps
 () %7B%0A        ret
@@ -1025,53 +1025,103 @@
 div'
-%0A        %7D;%0A    %7D,%0A%0A    render: function
+,%0A            source: ''%0A        %7D;%0A    %7D,%0A%0A    getInitialState: function getInitialState
 () %7B%0A
+%0A
     
@@ -1132,82 +1132,390 @@
 var 
-containerProps = %7B%7D;%0A        var renderer = new ReactRenderer(this.p
+state = %7B%0A            source: this.props.source %7C%7C '',%0A            sourcePos: undefined,%0A            escapeHtml: undefined,%0A            skipHtml: undefined,%0A            softBreak: undefined,%0A            highlight: undefined%0A        %7D;%0A%0A        this.stateKeys = Object.keys(state);%0A%0A        return state;%0A    %7D,%0A%0A    shouldComponentUpdate: function shouldComponentUpdate(nextP
 rops)
-;
+ %7B
 %0A   
@@ -1523,37 +1523,190 @@
     
-var ast = parser.parse(this.p
+if (this.props.containerTagName !== nextProps.containerTagName %7C%7C this.props.className !== nextProps.className) %7B%0A            return true;%0A        %7D%0A%0A        nextProps.source = nextP
 rops
@@ -1718,17 +1718,16 @@
 ce %7C%7C ''
-)
 ;%0A%0A     
@@ -1737,174 +1737,489 @@
 if (
-this.props.className) %7B%0A            containerProps.className = this.props.className;%0A        %7D%0A%0A        return React.createElement.apply(React,%0A            %5B
+!srcEquals(this.state, nextProps)) %7B%0A            this.setState(copyKeys(this.stateKeys, nextProps));%0A            this._setMarkdown(this.state.source, this.state);%0A        %7D%0A%0A        return false;%0A    %7D,%0A%0A    _setMarkdown: function _setMarkdown(text, opts) %7B%0A        var reader = new commonmark.Parser(opts);%0A        var writer = new commonmark.HtmlRenderer(opts);%0A        var parsed = reader.parse(text);%0A        var html = writer.parse(parsed);%0A%0A        React.findDOMNode(
 this.
-prop
+ref
 s.co
@@ -2229,87 +2229,469 @@
 iner
-TagName, containerProps%5D%0A                .concat(renderer.render(ast))%0A        
+).innerHTML = html;%0A    %7D,%0A%0A    componentDidUpdate: function componentDidUpdate() %7B%0A        this._setMarkdown(this.state.source, this.state);%0A    %7D,%0A%0A    componentDidMount: function componentDidMount() %7B%0A        this._setMarkdown(this.state.source, this.state);%0A    %7D,%0A%0A    render: function render() %7B%0A        var Container = this.props.containerTagName;%0A%0A        return React.createElement(Container, %7B ref: 'container', className: this.props.className %7C%7C '' %7D
 );%0A 

Update react-markdown.js