<commit_before>
App.require('Article', function() {
	var article = App.Engine('Article');

	var state = 'initialize';

	if (window.location.hash) {
		var article_id = window.location.hash.replace('#', '');
		$('#article_id').val(article_id);
	}

	// Initializing Marked
	var renderer = new marked.Renderer();
	renderer.table = function(header, body) {
		return '<table class=\"ui table segment\">' +
			'<thead>' + header + '</thead>' +
			'<tbody>' + body + '</tbody>' +
			'</table>';
	};

	renderer.hr = function() {
		return '<div class=\"ui divider\"></div>';
	};

	renderer.blockquote = function(content) {
		return '<div class=\"ui message\">' + content + '</div>';
	};

	renderer.code = function(code, lang) {
		return '<div class=\"ui message\"><pre><code class=\"lang-' + lang + '\">' + hljs.highlightAuto(code).value + '</code></pre></div>';
	};

	// Initializing highlight
	hljs.initHighlightingOnLoad();

	// Save
	var saveRequired = false;
	var saveRunner;
	var savingRef = 0;
	function save(callback) {

		savingRef++;
		saveRequired = false;
		state = 'saving';

		// Disable save button
		$('#toolbar_save').addClass('disabled');

		article.updateArticle($('#article_id').val(), {
			subject: $('#article_subject').val(),
			content: editor.getValue()
		}, function(err, doc) {
			if (err) {
				callback(err)
				return;
			}

			if (!$('#article_id').val()) {
				location.href = '#' + doc._id;
			}

			$('#article_id').val(doc._id);

			// Change status back
			savingRef--;
			if (savingRef == 0)
				state = 'ready';

			callback(err, doc);
		});
	}

	// Initializing previewer
	$('#form_content_previewer').css({
		padding: '30px'
	});

	// Initializing editor
	$('#form_content_editor').css({
		height: '100%',
		padding: '0px'
	});

	var editor = CodeMirror(document.getElementById('form_content_editor'), {
		mode: 'markdown',
		theme: 'base16-light',
		lineWrapping: true,
		dragDrop: false
	});

	editor.setSize('100%', '100%');

	editor.on('change', function() {
		if (state == 'ready')
			$('#toolbar_save').removeClass('disabled');

		saveRequired = true;
	});

	// Initializing subject input box
	$('#article_subject').on('input', function() {
		if (state == 'ready')
			$('#toolbar_save').removeClass('disabled');

		saveRequired = true;
	});

	// Side panel
	$('#sidepanel_publish_button').on('click', function() {
		$('#publish_dialog')
			.modal('setting', {
				onApprove: function() {
				}
			})
			.modal('show');
	});

	$('.ui.modal').modal();
	$('.attached.message .header .ui.button').popup();

	// Toolbar
	$('#toolbar_save').on('click', function() {
		if ($('#toolbar_save').hasClass('disabled'))
			return;

		save(function(err, doc) {
			// Saved
			$('#form_content_previewer').html(doc.html);
		});
	});

	function markup(head, end) {
		var orig = editor.getSelection();
		var content = orig.replace(/^\n*(\S*(\n+\S+)*)\n*$/, "$1");
		var prefix = /^\n+/.exec(orig) || '';
		var postfix = /\n+$/.exec(orig) || '';

		editor.replaceSelection(prefix + head + content + end + postfix);
	}

	$('#toolbar_bold').on('click', function() {
		markup('**', '**');
		editor.focus();
	});

	$('#toolbar_italic').on('click', function() {
		markup('*', '*');
		editor.replaceSelection('*' + editor.getSelection() + '*');
		editor.focus();
	});

	$('#toolbar_underline').on('click', function() {
		markup('<u>', '</u>');
		editor.focus();
	});

	$('#toolbar_strikethrough').on('click', function() {
		markup('~~', '~~');
		editor.focus();
	});

	$('#toolbar_link').on('click', function() {
		editor.replaceSelection('[' + editor.getSelection() + '](http://)');
		editor.focus();
	});

	$('#toolbar_blockquote').on('click', function() {
		markup('>', '\n');
		editor.focus();
	});

	$('#toolbar_code').on('click', function() {
		markup('```\n', '\n```');
		editor.focus();
	});<commit_msg>make individual part for blockquote and code<commit_after>
App.require('Article', function() {
	var article = App.Engine('Article');

	var state = 'initialize';

	if (window.location.hash) {
		var article_id = window.location.hash.replace('#', '');
		$('#article_id').val(article_id);
	}

	// Initializing Marked
	var renderer = new marked.Renderer();
	renderer.table = function(header, body) {
		return '<table class=\"ui table segment\">' +
			'<thead>' + header + '</thead>' +
			'<tbody>' + body + '</tbody>' +
			'</table>';
	};

	renderer.hr = function() {
		return '<div class=\"ui divider\"></div>';
	};

	renderer.blockquote = function(content) {
		return '<div class=\"ui message\">' + content + '</div>';
	};

	renderer.code = function(code, lang) {
		return '<div class=\"ui message\"><pre><code class=\"lang-' + lang + '\">' + hljs.highlightAuto(code).value + '</code></pre></div>';
	};

	// Initializing highlight
	hljs.initHighlightingOnLoad();

	// Save
	var saveRequired = false;
	var saveRunner;
	var savingRef = 0;
	function save(callback) {

		savingRef++;
		saveRequired = false;
		state = 'saving';

		// Disable save button
		$('#toolbar_save').addClass('disabled');

		article.updateArticle($('#article_id').val(), {
			subject: $('#article_subject').val(),
			content: editor.getValue()
		}, function(err, doc) {
			if (err) {
				callback(err)
				return;
			}

			if (!$('#article_id').val()) {
				location.href = '#' + doc._id;
			}

			$('#article_id').val(doc._id);

			// Change status back
			savingRef--;
			if (savingRef == 0)
				state = 'ready';

			callback(err, doc);
		});
	}

	// Initializing previewer
	$('#form_content_previewer').css({
		padding: '30px'
	});

	// Initializing editor
	$('#form_content_editor').css({
		height: '100%',
		padding: '0px'
	});

	var editor = CodeMirror(document.getElementById('form_content_editor'), {
		mode: 'markdown',
		theme: 'base16-light',
		lineWrapping: true,
		dragDrop: false
	});

	editor.setSize('100%', '100%');

	editor.on('change', function() {
		if (state == 'ready')
			$('#toolbar_save').removeClass('disabled');

		saveRequired = true;
	});

	// Initializing subject input box
	$('#article_subject').on('input', function() {
		if (state == 'ready')
			$('#toolbar_save').removeClass('disabled');

		saveRequired = true;
	});

	// Side panel
	$('#sidepanel_publish_button').on('click', function() {
		$('#publish_dialog')
			.modal('setting', {
				onApprove: function() {
				}
			})
			.modal('show');
	});

	$('.ui.modal').modal();
	$('.attached.message .header .ui.button').popup();

	// Toolbar
	$('#toolbar_save').on('click', function() {
		if ($('#toolbar_save').hasClass('disabled'))
			return;

		save(function(err, doc) {
			// Saved
			$('#form_content_previewer').html(doc.html);
		});
	});

	function markup(head, end, individual) {
		var orig = editor.getSelection();
		var content = orig.replace(/^\n*(\S*(\n+\S+)*)\n*$/, "$1");
		var prefix = /^\n+/.exec(orig) || '';
		var postfix = /\n+$/.exec(orig) || '';

		if (individual && prefix == '') {
			prefix = '\n';
		}

		if (individual && postfix == '') {
			postfix = '\n';
		}

		editor.replaceSelection(prefix + head + content + end + postfix);
	}

	$('#toolbar_bold').on('click', function() {
		markup('**', '**');
		editor.focus();
	});

	$('#toolbar_italic').on('click', function() {
		markup('*', '*');
		editor.replaceSelection('*' + editor.getSelection() + '*');
		editor.focus();
	});

	$('#toolbar_underline').on('click', function() {
		markup('<u>', '</u>');
		editor.focus();
	});

	$('#toolbar_strikethrough').on('click', function() {
		markup('~~', '~~');
		editor.focus();
	});

	$('#toolbar_link').on('click', function() {
		editor.replaceSelection('[' + editor.getSelection() + '](http://)');
		editor.focus();
	});

	$('#toolbar_blockquote').on('click', function() {
		markup('>', '\n', true);
		editor.focus();
	});

	$('#toolbar_code').on('click', function() {
		markup('```\n', '\n```', true);
		editor.focus();
	});
{'fraction_non_alphanumeric': 0.24178493798746964, 'fraction_numerical': 0.00434727017005498, 'mean_word_length': 3.876558603491272, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2985601', 'n_tokens_mistral': 2970, 'n_tokens_neox': 2657, 'n_words': 489}