<NME> editor.js
<BEF> 

function getSelectedTheme() {
    var theme = null;
    $('.themes input').each(function() {
        if (this.checked) {
            theme = this.value;
            return false;
        }
    });
    return theme;
}


function setPreviewHtml(html) {
	var iframe = $('#browse')[0];
	var doc = iframe.document;
	if (iframe.contentDocument) {
		doc = iframe.contentDocument; // For NS6
	} else if (iframe.contentWindow) {
		doc = iframe.contentWindow.document; // For IE5.5 and IE6
	}
	doc.open();
	doc.writeln(html);
	doc.close();
}

var activeXhr = null;
var lastContent = null;

function genPreview() {
    var self = $('#editor');
	var rstContent = self.val();
    if (activeXhr || lastContent == rstContent) {
        //activeXhr.abort();
		return;
    }
	lastContent = rstContent;
    activeXhr = $.ajax({
        'url': '/srv/rst2html/',
        'data': {'rst': rstContent, 'theme': getSelectedTheme()},
		'type': 'POST',
		'error': function(xhr) {
			setPreviewHtml(xhr.responseText);
		},
        'success': function(response) {
            setPreviewHtml(response);
			activeXhr = null;
        }
    });
}
    doc.writeln(html);
var timerId = null;

function getCurrentLink(res) {
	if (!res) {
		return 'http://' + window.location.host + '/?theme=' + getSelectedTheme();
	}
	return 'http://' + window.location.host + '/?n=' + res + '&theme=' + getSelectedTheme();
}

function showLinkDialog(url) {
    var showLinker = $('.showLinkDialog');
            
    var self = $('#show_link');
    var offs = self.offset();
    showLinker.find('input').val(url);
function getScrollHeight($prevFrame) {
    // Different browsers attach the scrollHeight of a document to different
    // elements, so handle that here.
    if ($prevFrame[0].scrollHeight !== undefined) {
        return $prevFrame[0].scrollHeight;


$(function() {
	//$('<button>Conver!</button>').click(genPreview).appendTo($('body'));
	$('#editor').bind('change', genPreview).markItUp(mySettings);
	timerId = window.setInterval(genPreview, 900);
	window.setTimeout(function() {
		$('#editor-td > div').css({'width': '100%', 'height': '96%'});
	}, 200);
	
	$('.themes input').bind('change', function() {
		lastContent = null;
		genPreview()
	});
	
	$('.showLinkDialog .hider').click(function() {
		$('.showLinkDialog').hide('slow');
	});
	
	
	$('#show_link').click(function(e) {
		
        $.ajax({
            'url': '/srv/save_rst/',
            'type': 'POST',

    // Set the scroll position of the preview pane to match.  jQuery will
                showLinkDialog(getCurrentLink(response + ''));
            }

		});
		
		e.preventDefault();
		return false;
	});

    $('#as_pdf').click(function(e) {
        var form = $('#save_as_pdf');
    if (activeXhr || lastContent == rstContent) {
        //activeXhr.abort();
        return;
    }
    syncHashAndUpdate();
}

function genPreview() {
    var self = $('#editor');
    var rstContent = self.val();

    lastContent = rstContent;
    activeXhr = $.ajax({
        'url': script_root + '/srv/rst2html/',
        'data': {'rst': rstContent, 'theme': getSelectedTheme()},
        'type': 'POST',
        'error': function(xhr) {
            setPreviewHtml(xhr.responseText);
            activeXhr = null;
        },
        'success': function(response) {
            setPreviewHtml(response);
            syncScrollPosition();
            activeXhr = null;
        }
    });
}

var timerId = null;

function syncState(rst) {
    location.hash = '#' + b64EncodeUnicode(rst);
}

function syncHashAndUpdate() {
    var self = $('#editor');
    var rstContent = self.val();
    syncState(rstContent);
    genPreview();
}

function getDecodedHash() {
    return b64DecodeUnicode(location.hash.substr(1));
}

window.onhashchange = function(ev) {
    $('textarea#editor').val(getDecodedHash());
}

function reactForTheme(theme) {
    $('.themes input[value='+ theme + ']')[0].checked = true;
    $('#as_pdf_theme').attr('value', getSelectedTheme());
}

function reactForRst(rst) {
    $('#editor').val(rst)
}

window.onpopstate = function(ev) {
    var doUpdate = false;
    var stateTheme = getQueryArgs()['theme'] || 'basic';
    if (stateTheme != getSelectedTheme()) {
        reactForTheme(stateTheme)
        doUpdate = true;
    }
    if (getDecodedHash() != lastContent) {
        reactForRst(getDecodedHash())
        doUpdate = true;
    }

    if (doUpdate) {
        genPreview();
    }
}

function adjustBrowse() {
    var h = $('body').height() - $('#browse').offset().top - $('#footer').outerHeight() - 7;
    $('#browse').height(h);
    h -= 12;
    $('#editor').height(h).css('max-height', h + 'px');
}


$(function() {
    window.baseTitle = $('head title').text();

    $('textarea#editor').bind('change', probablyChanged).markItUp(mySettings);
    timerId = window.setInterval(probablyChanged, 900);
    window.setTimeout(function() {
        $('#editor-td > div').css({'width': '100%', 'height': '96%'});
    }, 200);

    $('textarea#editor').scroll(syncScrollPosition);

    $('.themes input').bind('change', function() {
        history.pushState({theme: getSelectedTheme()}, document.title, '/?theme=' + getSelectedTheme() + location.hash);
        genPreview();
    });

    adjustBrowse();

    $(window).bind('resize', adjustBrowse);
});

<MSG> tab2spaces and more strict css find of textarea

<DFF> @@ -13,39 +13,39 @@ function getSelectedTheme() {
 
 
 function setPreviewHtml(html) {
-	var iframe = $('#browse')[0];
-	var doc = iframe.document;
-	if (iframe.contentDocument) {
-		doc = iframe.contentDocument; // For NS6
-	} else if (iframe.contentWindow) {
-		doc = iframe.contentWindow.document; // For IE5.5 and IE6
-	}
-	doc.open();
-	doc.writeln(html);
-	doc.close();
+    var iframe = $('#browse')[0];
+    var doc = iframe.document;
+    if (iframe.contentDocument) {
+        doc = iframe.contentDocument; // For NS6
+    } else if (iframe.contentWindow) {
+        doc = iframe.contentWindow.document; // For IE5.5 and IE6
+    }
+    doc.open();
+    doc.writeln(html);
+    doc.close();
 }
 
 var activeXhr = null;
 var lastContent = null;
 
 function genPreview() {
-    var self = $('#editor');
-	var rstContent = self.val();
+    var self = $('textarea#editor');
+    var rstContent = self.val();
     if (activeXhr || lastContent == rstContent) {
         //activeXhr.abort();
-		return;
+        return;
     }
-	lastContent = rstContent;
+    lastContent = rstContent;
     activeXhr = $.ajax({
         'url': '/srv/rst2html/',
         'data': {'rst': rstContent, 'theme': getSelectedTheme()},
-		'type': 'POST',
-		'error': function(xhr) {
-			setPreviewHtml(xhr.responseText);
-		},
+        'type': 'POST',
+        'error': function(xhr) {
+            setPreviewHtml(xhr.responseText);
+        },
         'success': function(response) {
             setPreviewHtml(response);
-			activeXhr = null;
+            activeXhr = null;
         }
     });
 }
@@ -53,15 +53,15 @@ function genPreview() {
 var timerId = null;
 
 function getCurrentLink(res) {
-	if (!res) {
-		return 'http://' + window.location.host + '/?theme=' + getSelectedTheme();
-	}
-	return 'http://' + window.location.host + '/?n=' + res + '&theme=' + getSelectedTheme();
+    if (!res) {
+        return 'http://' + window.location.host + '/?theme=' + getSelectedTheme();
+    }
+    return 'http://' + window.location.host + '/?n=' + res + '&theme=' + getSelectedTheme();
 }
 
 function showLinkDialog(url) {
     var showLinker = $('.showLinkDialog');
-            
+
     var self = $('#show_link');
     var offs = self.offset();
     showLinker.find('input').val(url);
@@ -73,25 +73,26 @@ function showLinkDialog(url) {
 
 
 $(function() {
-	//$('<button>Conver!</button>').click(genPreview).appendTo($('body'));
-	$('#editor').bind('change', genPreview).markItUp(mySettings);
-	timerId = window.setInterval(genPreview, 900);
-	window.setTimeout(function() {
-		$('#editor-td > div').css({'width': '100%', 'height': '96%'});
-	}, 200);
-	
-	$('.themes input').bind('change', function() {
-		lastContent = null;
-		genPreview()
-	});
-	
-	$('.showLinkDialog .hider').click(function() {
-		$('.showLinkDialog').hide('slow');
-	});
-	
-	
-	$('#show_link').click(function(e) {
-		
+    //$('<button>Conver!</button>').click(genPreview).appendTo($('body'));
+
+    $('textarea#editor').bind('change', genPreview).markItUp(mySettings);
+    timerId = window.setInterval(genPreview, 900);
+    window.setTimeout(function() {
+        $('#editor-td > div').css({'width': '100%', 'height': '96%'});
+    }, 200);
+
+    $('.themes input').bind('change', function() {
+        lastContent = null;
+        genPreview()
+    });
+
+    $('.showLinkDialog .hider').click(function() {
+        $('.showLinkDialog').hide('slow');
+    });
+
+
+    $('#show_link').click(function(e) {
+
         $.ajax({
             'url': '/srv/save_rst/',
             'type': 'POST',
@@ -100,11 +101,11 @@ $(function() {
                 showLinkDialog(getCurrentLink(response + ''));
             }
 
-		});
-		
-		e.preventDefault();
-		return false;
-	});
+        });
+
+        e.preventDefault();
+        return false;
+    });
 
     $('#as_pdf').click(function(e) {
         var form = $('#save_as_pdf');

tab2spaces and more strict css find of textarea