<commit_before>(function (Q, $, window, document, undefined) {

/**
 * Streams Tools
 * @module Streams-tools
 */

/**
 * Inplace text editor tool to edit the content or attribute of a stream
 * @class Streams inplace
 * @constructor
 * @param {Object} [options] used to pass options
 *   @param {String} options.inplaceType Required. The type of the fieldInput. Can be "textarea", "text" or "select"
 *   @param {Array} [options.convert] The characters to convert to HTML. Pass an array containing zero or more of "\n", " "
 *   @param {String} [options.publisherId] Required if stream option is empty. The publisher's user id.
 *   @param {String} [options.streamName] Required if stream option is empty. The stream's name.
 *   @param {Stream} [options.stream] Optionally pass a Streams.Stream object here if you have it already
 *   @param {String} [options.field] Optional, name of a field to change instead of the content of the stream
 *   @param {String} [options.attribute] Optional, name of an attribute to change instead of a field.
 *   @param {Object} [options.inplace] Additional fields to pass to the child Q/inplace tool, if any
 *   @param {boolean} [options.URLtoLink=false] If true, replace all URLs with links.
 *   @param {Function} [options.create] Optional. You can pass a function here, which takes the tool as "this"
 *     and a callback as the first parameter, is supposed to create a stream and
 *     call the callback with (err, stream). If omitted, then the tool doesn't render.
 *   @param {Q.Event} [options.onLoad]
 *   @param {Q.Event} [options.onUpdate]
 *   @param {Q.Event} [options.onError]
 */
Q.Tool.define("Streams/inplace", function (options) {
	var tool = this;
	var state = tool.state;
	var $te = $(tool.element);
	var $container = $('.Q_inplace_tool_container', $te);
	
	// if activated with JS should have following options:
	//  - stream: a Streams.Stream object that was already constructed
	//  - publisherId, streamName: alternative to stream
	//  - field: the name of the field to bind to, defaults to "content"
	//  - attribute: alternatively, the name of an attribute to bind to

	function _construct(err) {
		if (err) {
			return tool.state.onError.handle(err);
		}
		var stream = this;
		state.publisherId = stream.fields.publisherId;
		state.streamName = stream.fields.name;
		
		var currentContent = null;
		var currentHtml = null;

		function _setContent(content) {
			if (tool.inplace = tool.sibling('Q/inplace') || tool.child('', 'Q/inplace')) {
				tool.$static = tool.inplace.$static;
				tool.inplace.state.onLoad.add(state.onLoad.handle.bind(tool));
			} else if (!tool.$static) {
				tool.$static = tool.$('.Q_inplace_tool_static, .Q_inplace_tool_blockstatic');
			}

			// replace URLs with links
			if (state.URLtoLink) {
				var contentWithLinks = content;
				var aURLs = contentWithLinks.matchTypes("url");
				if (!Q.isEmpty(aURLs)) {
					var oURLs = {};
					Q.each(aURLs, function (i, url) {
						var parsedUrl = url;
						if (!/^(?:f|ht)tps?\:\/\//.test(url)) {
							parsedUrl = "http://" + url;
						}
						oURLs[url] = '<a href="' + parsedUrl + '" target="_blank">' + url + '</a>';
					});
					contentWithLinks = contentWithLinks.replaceAll(oURLs);
				}
			}

			var placeholder = tool.inplace && tool.inplace.state.placeholder
				&& String(tool.inplace.state.placeholder).encodeHTML();
			var $e, html = (
				(state.inplaceType === 'select')
				?  String(state.inplace.options[content] || '').encodeHTML()
				: state.URLtoLink ? String(contentWithLinks || '') : String(content || '').encodeHTML()
			) || '<span class="Q_placeholder">'+placeholder+'</div>';

			if (state.inplaceType === 'textarea') {
				var convert = {};
				if (content) {
					var replacements = {
						"\n": '<br>',
						' ': '&nbsp;'
					};
					if (state.convert) {
						for (var i=0, l=state.convert.length; i<l; ++i) {
							var c = state.convert[i];
							convert[c] = replacements[c];
						}
					}
				}
				var toSet = html.replaceAll(convert);
			}
			if (tool.inplace) {<commit_msg>Fixed Streams/inplace tool to parse content for URLs after HTML encoded.<commit_after>(function (Q, $, window, document, undefined) {

/**
 * Streams Tools
 * @module Streams-tools
 */

/**
 * Inplace text editor tool to edit the content or attribute of a stream
 * @class Streams inplace
 * @constructor
 * @param {Object} [options] used to pass options
 *   @param {String} options.inplaceType Required. The type of the fieldInput. Can be "textarea", "text" or "select"
 *   @param {Array} [options.convert] The characters to convert to HTML. Pass an array containing zero or more of "\n", " "
 *   @param {String} [options.publisherId] Required if stream option is empty. The publisher's user id.
 *   @param {String} [options.streamName] Required if stream option is empty. The stream's name.
 *   @param {Stream} [options.stream] Optionally pass a Streams.Stream object here if you have it already
 *   @param {String} [options.field] Optional, name of a field to change instead of the content of the stream
 *   @param {String} [options.attribute] Optional, name of an attribute to change instead of a field.
 *   @param {Object} [options.inplace] Additional fields to pass to the child Q/inplace tool, if any
 *   @param {boolean} [options.URLtoLink=false] If true, replace all URLs with links.
 *   @param {Function} [options.create] Optional. You can pass a function here, which takes the tool as "this"
 *     and a callback as the first parameter, is supposed to create a stream and
 *     call the callback with (err, stream). If omitted, then the tool doesn't render.
 *   @param {Q.Event} [options.onLoad]
 *   @param {Q.Event} [options.onUpdate]
 *   @param {Q.Event} [options.onError]
 */
Q.Tool.define("Streams/inplace", function (options) {
	var tool = this;
	var state = tool.state;
	var $te = $(tool.element);
	var $container = $('.Q_inplace_tool_container', $te);
	
	// if activated with JS should have following options:
	//  - stream: a Streams.Stream object that was already constructed
	//  - publisherId, streamName: alternative to stream
	//  - field: the name of the field to bind to, defaults to "content"
	//  - attribute: alternatively, the name of an attribute to bind to

	function _construct(err) {
		if (err) {
			return tool.state.onError.handle(err);
		}
		var stream = this;
		state.publisherId = stream.fields.publisherId;
		state.streamName = stream.fields.name;
		
		var currentContent = null;
		var currentHtml = null;

		function _setContent(content) {
			if (tool.inplace = tool.sibling('Q/inplace') || tool.child('', 'Q/inplace')) {
				tool.$static = tool.inplace.$static;
				tool.inplace.state.onLoad.add(state.onLoad.handle.bind(tool));
			} else if (!tool.$static) {
				tool.$static = tool.$('.Q_inplace_tool_static, .Q_inplace_tool_blockstatic');
			}

			var placeholder = tool.inplace && tool.inplace.state.placeholder
				&& String(tool.inplace.state.placeholder).encodeHTML();
			var $e, html = (
				(state.inplaceType === 'select')
				? String(state.inplace.options[content] || '').encodeHTML()
				: String(content || '').encodeHTML()
			) || '<span class="Q_placeholder">'+placeholder+'</div>';

			// replace URLs with links
			if (state.URLtoLink) {
				var aURLs = html.matchTypes("url");
				if (!Q.isEmpty(aURLs)) {
					var oURLs = {};
					Q.each(aURLs, function (i, url) {
						var parsedUrl = url;
						if (!/^(?:f|ht)tps?\:\/\//.test(url)) {
							parsedUrl = "http://" + url;
						}
						oURLs[url] = '<a href="' + parsedUrl + '" target="_blank">' + url + '</a>';
					});
					html = html.replaceAll(oURLs);
				}
			}

			if (state.inplaceType === 'textarea') {
				var convert = {};
				if (content) {
					var replacements = {
						"\n": '<br>',
						' ': '&nbsp;'
					};
					if (state.convert) {
						for (var i=0, l=state.convert.length; i<l; ++i) {
							var c = state.convert[i];
							convert[c] = replacements[c];
						}
					}
				}
				var toSet = html.replaceAll(convert);
			}
			if (tool.inplace) {
{'fraction_non_alphanumeric': 0.14402679568291776, 'fraction_numerical': 0.00024810817516437165, 'mean_word_length': 3.276923076923077, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 13, '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': '7582427', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2514, 'n_words': 787}