(function( $ ) {

    $.fn.markdownPreview = function( options ) {
        
        var settings = {
            'insert-preview-div': true,
            'location': 'below',
            'preview-class-name': 'preview',
            'preview-element': null
        };
        
        if( options ) {
            $.extend( settings, options );
        }
        
        return this.each(function() {
            if(!settings['insert-preview-div'] && $(settings['preview-element']).length == 0) {
                throw "Either insert preview div should be set to true or an existing preview element needs to be provided";
            }
            
            $this = $(this);
            var previewElement = $(settings['preview-element']);
            
            if(settings['insert-preview-div']) {
                var previewElementHtml = '<div class="' + settings['preview-class-name'] + '" />';
                switch(settings['location']) {
                    case 'below':
                        $this.after(previewElementHtml);
                        previewElement = $this.next();
                        break;
                    case 'above':
                        $this.before(previewElementHtml);
                        previewElement = $this.prev();
                        break;
                    default:
                        throw settings['location'] + " is not a valid option for location";
                }
            }
            
            var converter = new Showdown.converter();
            var updatePreview = function() {
                previewElement.html(converter.makeHtml($(this).val()));
            };
            updatePreview();
            $this.bind('keyup.markdown-preview', updatePreview);
            $this.bind('change.markdown-preview', updatePreview);
        });
        
    };

})( jQuery );

(function( $ ) {

    $.fn.markdownPreview = function( options ) {
        
        var settings = {
            'insert-preview-div': true,
            'location': 'below',
            'preview-class-name': 'preview',
            'preview-element': null
        };
        
        if( options ) {
            $.extend( settings, options );
        }
        
        return this.each(function() {
            if(!settings['insert-preview-div'] && $(settings['preview-element']).length == 0) {
                throw "Either insert preview div should be set to true or an existing preview element needs to be provided";
            }
            
            $this = $(this);
            var previewElement = $(settings['preview-element']);
            
            if(settings['insert-preview-div']) {
                var previewElementHtml = '<div class="' + settings['preview-class-name'] + '" />';
                switch(settings['location']) {
                    case 'below':
                        $this.after(previewElementHtml);
                        previewElement = $this.next();
                        break;
                    case 'above':
                        $this.before(previewElementHtml);
                        previewElement = $this.prev();
                        break;
                    default:
                        throw settings['location'] + " is not a valid option for location";
                }
            }
            
            var converter = new Showdown.converter();
            var updatePreview = function() {
                if(this.nodeName !== undefined) {
                    previewElement.html(converter.makeHtml($(this).val()));
                } else {
                    previewElement.html(converter.makeHtml($this.val()));
                }
            };
            updatePreview();
            $this.bind('keyup.markdown-preview', updatePreview);
            $this.bind('change.markdown-preview', updatePreview);
        });
        
    };

})( jQuery );

Fix bug with Markdown Previewer where it wouldn't load up correct data initially
Fix bug with Markdown Previewer where it wouldn't load up correct data initially
