function InitMarked()
{
	var renderer = new Markdown.marked.Renderer();
	renderer.listitem = function(text) {
		if (/^ *\[[xX ]\]\s*/.test(text)) {
			text = text
				.replace(/^\s*\[ \] */, '<input type="checkbox" disabled> ')
				.replace(/^\s*\[[xX]\] */, '<input type="checkbox" checked disabled> ');
			return '<li style="list-style: none">' + text + '</li>';
		} else {
			return '<li>' + text + '</li>';
		}
	};

	renderer.code = function(code, language){
		code = code.replace(/</g, '&lt;').replace(/>/g, '&gt;');
		if(language=='' || language==undefined)
			return '<pre class="prettyprint">'+code+'</pre>';
		return '<pre class="prettyprint lang-'+ language +'">'+code+'</pre>';
	};

	Markdown.marked.setOptions({
		renderer: renderer,
		footnotes : true
	});
}

InitMarked();

var css_preview=SCRIPT_PATH+"\\preview.css";
var css_code=SCRIPT_PATH+"\\prettify.css";
var js_highlight=SCRIPT_PATH+"\\prettify.js";
var js_toc=SCRIPT_PATH+"\\toc.js";
var js_query=SCRIPT_PATH+"\\jquery-1.11.3.min.js";

var doc = App.ActiveDoc;
var rs = Markdown.marked( doc.Text );

var content="\
<!doctype html>\n\
<html>\n\
<head>\n\
<meta charset='utf-8'/>\n\
<link href='" + css_preview + "' rel='stylesheet'></link>\n\
<link href='" + css_code + "' rel='stylesheet'></link>\n\
<title>Markdown Preview</title>\n\
<script type='text/javascript' src='" + js_highlight + "'></script>\n\
<script type='text/javascript' src='" + js_toc + "'></script>\n\
<script type='text/javascript' src='" + js_query + "'></script>\n\
</head>\n\
<body>\n\
<div id='content'>\n" + rs + "</div>\n\
<script>\n\
var tocs=$(\"*[name='toc']\");\n\
if( tocs.length ){\n\
	var toc=generated_toc.generate('content');\n\
	tocs.each(function(){\n\
		$(this).html( toc );\n\
	});\n\
}\n\
prettyPrint()\n\
</script>\n\
</body>\n\
</html>";
