<commit_before>/*
            Syntax Core Plugin

	     XWiki WYSIWYG Syntax Editor
	Created by <NAME> for XWiki.org
	under the Google Summer of Code 2005 program.
*/

WikiEditor.prototype.initCorePlugin = function() {

	// External/Internal conversion setup
    this.addExternalProcessor((/^\s*(1(\.1)*)\s+([^\r\n]*)$/im), 'convertHeadingExternal');
	this.addInternalProcessor((/\s*<h3\s*([^>]*)>([\s\S]+?)<\/h3>/i), 'convertHeadingInternal');

    this.addInternalProcessor((/<p[^>]*>&nbsp;<\/p>/gi), "");

    this.addExternalProcessor((/^\s*((\*+)|#|(1\.))\s+([^\r\n]+)$/im), 'convertListExternal');
	this.addInternalProcessor((/\s*<(ul|ol)\s*([^>]*)>/i), 'convertListInternal');

	this.addExternalProcessor((/^s*----(\-)*\s*$/gim), '<hr class="line" \/>');
	this.addInternalProcessor((/<hr[^>]*>/gi), '----');

    // Must remove the html tag format so it won't interfere with paragraph conversion
	this.addExternalProcessor((/<%([\s\S]+?)%>/ig), '&lt;%$1%&gt;');

    this.addExternalProcessor((/((\s|\S)*)/i), 'convertParagraphExternal');
	this.addInternalProcessor((/<\s*p\s*([^>]*)>(.*?)<\s*\/\s*p\s*>/gi), '\r\n$2\r\n');

    this.addExternalProcessor((/\[(.*?)(>(.*?))?(>(.*?))?\]/i), 'convertLinkExternal');
	this.addInternalProcessor((/<a\s*([^>]*)(class=\"wikiexternallink\"|class=\"wikilink\")\s*([^>]*)>(.*?)<\/a>/i), 'convertLinkInternal');

    this.addExternalProcessor((/\{table\}([\s\S]+?)\{table\}/i), 'convertTableExternal');
    this.addInternalProcessor((/<table\s*([^>]*)class=\"wiki-table\"\s*([^>]*)>([\s\S]+?)<\/table>/i), 'convertTableInternal');

    this.addExternalProcessor((/\*(.+?)\*/gi), '<b class="bold">$1<\/b>');
    this.addExternalProcessor((/__(.+?)__/gi), '<b class="bold">$1<\/b>');
    this.addInternalProcessor((/<strong[^>]*>(.*?)<\/strong>/gi), '*$1*');

	this.addExternalProcessor((/~~(.+?)~~/gi), '<i class="italic">$1<\/i>');
	this.addInternalProcessor((/<em[^>]*>(.*?)<\/em>/gi), '~~$1~~');

	this.addExternalProcessor((/--(.+?)--/gi),  '<strike class="strike">$1<\/strike>');
	this.addInternalProcessor((/<strike[^>]*>(.*?)<\/strike>/gi), '--$1--');

	this.addInternalProcessor((/[#$][a-zA-Z0-9-_.]+\(([^&)]*&quot;[^)]*)+?\)/i), 'convertVelocityScriptsInternal');

    this.addInternalProcessor((/&lt;%([\s\S]+?)%&gt;/i), 'convertGroovyScriptsInternal');

    this.addExternalProcessor((/##([^\r\n]*)$|(#\*([\s\S]+?)\*#)/im), 'convertVelocityCommentExternal');
    this.addInternalProcessorBefore('convertStyleInternal', (/<span\s*([^>]*)class=\"vcomment\"\s*([^>]*)>([\s\S]+?)<\/span>/i), 'convertVelocityCommentInternal');

    this.addExternalProcessorBefore('convertTableExternal', (/\{style:\s*(.*?)\}([\s\S]+?)\{style\}/i), 'convertStyleExternal');
    this.addInternalProcessorBefore('convertTableInternal', (/<(font|span|div)\s*(.*?)>([\s\S]+?)<\/(font|span|div)>/i), 'convertStyleInternal');

    //this.addInternalProcessor((/&nbsp;(?!\|)/gi), "");
    this.setHtmlTagRemover('removeHtmlTags_Groovy');
    this.setHtmlTagRemover('removeSpecialHtmlTags');

    // Toolbar handlers
	this.addToolbarHandler('handleTextButtons');
	this.addToolbarHandler('handleListButtons');
    this.addToolbarHandler('handleIndentButtons');
    this.addToolbarHandler('handleUndoButtons');
	this.addToolbarHandler('handleTitlesList');
	this.addToolbarHandler('handleLinkButtons');
    this.addToolbarHandler('handleTableButtons');

    // Add Comands and Fix Commands(workarounds)
	this.addCommand('Title', 'titleCommand');
	this.addFixCommand('Title', 'fixTitle');

	this.addFixCommand("InsertUnorderedList", 'fixInsertUnorderedList');
	this.addFixCommand("Indent", 'fixInsertUnorderedList');
}

wikiEditor.initCorePlugin();

// This function will not strip groovy tags
WikiEditor.prototype.removeHtmlTags_Groovy = function(str) {
	var remove_html_tags_regexp = /<[^%][^>]*>/i;
    return str.replace(remove_html_tags_regexp, "");
}

//  This will remove some special Html tags to fix some bugs when switch between text and wysiwyg editor
//  We will replace or remove this method in future when find out the better solutions.
WikiEditor.prototype.removeSpecialHtmlTags = function(str) {
    str = str.replace(/<div class="paragraph">([\s\S]+?)<\/div>/g,'$1');
    str = str.replace(/<p class="paragraph">\s*([\s\S]+?)<\/p>/g,'$1');
    str = str.replace(/<span class="wikilink">\s*([\s\S]+?)<\/span>/g,'$1');
    str = str.replace(/<span class="wikiexternallink">\s*([\s\S]+?)<\/span>/g,'$1');
    str = str.replace(/<span class="bold">([\s\S]+?)<\/span>/g,'$1');
    str = str.replace(/<span class="italic">([\s\S]+?)<\/span>/g,'$1');
    str = str.replace(/<span class="strike">([\s\S]+?)<\/span>/g,'$1');    
    str = str.replace(/<\/?p[^>]*>/gi, "");
    str = str.replace(/<br \/>/g, '\r\n');
    return str;
}

WikiEditor.prototype.convertVelocityScriptsInternal = function(regexp, result, content) {
	var r = /&quot;/gi;
	return content.replace(regexp, result[0].replace(r, '"'));<commit_msg>Fixed bug XWIKI-609: Bold should be coded as *text* and not as <strong>text</strong><commit_after>/*
            Syntax Core Plugin

	     XWiki WYSIWYG Syntax Editor
	Created by <NAME> for XWiki.org
	under the Google Summer of Code 2005 program.
*/

WikiEditor.prototype.initCorePlugin = function() {

	// External/Internal conversion setup
    this.addExternalProcessor((/^\s*(1(\.1)*)\s+([^\r\n]*)$/im), 'convertHeadingExternal');
	this.addInternalProcessor((/\s*<h3\s*([^>]*)>([\s\S]+?)<\/h3>/i), 'convertHeadingInternal');

    this.addInternalProcessor((/<p[^>]*>&nbsp;<\/p>/gi), "");

    this.addExternalProcessor((/^\s*((\*+)|#|(1\.))\s+([^\r\n]+)$/im), 'convertListExternal');
	this.addInternalProcessor((/\s*<(ul|ol)\s*([^>]*)>/i), 'convertListInternal');

	this.addExternalProcessor((/^s*----(\-)*\s*$/gim), '<hr class="line" \/>');
	this.addInternalProcessor((/<hr[^>]*>/gi), '----');

    // Must remove the html tag format so it won't interfere with paragraph conversion
	this.addExternalProcessor((/<%([\s\S]+?)%>/ig), '&lt;%$1%&gt;');

    this.addExternalProcessor((/((\s|\S)*)/i), 'convertParagraphExternal');
	this.addInternalProcessor((/<\s*p\s*([^>]*)>(.*?)<\s*\/\s*p\s*>/gi), '\r\n$2\r\n');

    this.addExternalProcessor((/\[(.*?)(>(.*?))?(>(.*?))?\]/i), 'convertLinkExternal');
	this.addInternalProcessor((/<a\s*([^>]*)(class=\"wikiexternallink\"|class=\"wikilink\")\s*([^>]*)>(.*?)<\/a>/i), 'convertLinkInternal');

    this.addExternalProcessor((/\{table\}([\s\S]+?)\{table\}/i), 'convertTableExternal');
    this.addInternalProcessor((/<table\s*([^>]*)class=\"wiki-table\"\s*([^>]*)>([\s\S]+?)<\/table>/i), 'convertTableInternal');

    this.addExternalProcessor((/\*(.+?)\*/gi), '<b class="bold">$1<\/b>');
    this.addExternalProcessor((/__(.+?)__/gi), '<b class="bold">$1<\/b>');
    this.addInternalProcessor((/<strong[^>]*>(\n?)(.*?)(\n?)<\/strong>/gi), '$1*$2*$3');

	this.addExternalProcessor((/~~(.+?)~~/gi), '<i class="italic">$1<\/i>');
	this.addInternalProcessor((/<em[^>]*>(\n?)(.*?)(\n?)<\/em>/gi), '$1~~$2~~$3');

	this.addExternalProcessor((/--(.+?)--/gi),  '<strike class="strike">$1<\/strike>');
	this.addInternalProcessor((/<strike[^>]*>(\n?)(.*?)(\n?)<\/strike>/gi), '$1--$2--$3');

	this.addInternalProcessor((/[#$][a-zA-Z0-9-_.]+\(([^&)]*&quot;[^)]*)+?\)/i), 'convertVelocityScriptsInternal');

    this.addInternalProcessor((/&lt;%([\s\S]+?)%&gt;/i), 'convertGroovyScriptsInternal');

    this.addExternalProcessor((/##([^\r\n]*)$|(#\*([\s\S]+?)\*#)/im), 'convertVelocityCommentExternal');
    this.addInternalProcessorBefore('convertStyleInternal', (/<span\s*([^>]*)class=\"vcomment\"\s*([^>]*)>([\s\S]+?)<\/span>/i), 'convertVelocityCommentInternal');

    this.addExternalProcessorBefore('convertTableExternal', (/\{style:\s*(.*?)\}([\s\S]+?)\{style\}/i), 'convertStyleExternal');
    this.addInternalProcessorBefore('convertTableInternal', (/<(font|span|div)\s*(.*?)>([\s\S]+?)<\/(font|span|div)>/i), 'convertStyleInternal');

    //this.addInternalProcessor((/&nbsp;(?!\|)/gi), "");
    this.setHtmlTagRemover('removeHtmlTags_Groovy');
    this.setHtmlTagRemover('removeSpecialHtmlTags');

    // Toolbar handlers
	this.addToolbarHandler('handleTextButtons');
	this.addToolbarHandler('handleListButtons');
    this.addToolbarHandler('handleIndentButtons');
    this.addToolbarHandler('handleUndoButtons');
	this.addToolbarHandler('handleTitlesList');
	this.addToolbarHandler('handleLinkButtons');
    this.addToolbarHandler('handleTableButtons');

    // Add Comands and Fix Commands(workarounds)
	this.addCommand('Title', 'titleCommand');
	this.addFixCommand('Title', 'fixTitle');

	this.addFixCommand("InsertUnorderedList", 'fixInsertUnorderedList');
	this.addFixCommand("Indent", 'fixInsertUnorderedList');
}

wikiEditor.initCorePlugin();

// This function will not strip groovy tags
WikiEditor.prototype.removeHtmlTags_Groovy = function(str) {
	var remove_html_tags_regexp = /<[^%][^>]*>/i;
    return str.replace(remove_html_tags_regexp, "");
}

//  This will remove some special Html tags to fix some bugs when switch between text and wysiwyg editor
//  We will replace or remove this method in future when find out the better solutions.
WikiEditor.prototype.removeSpecialHtmlTags = function(str) {
    str = str.replace(/<div class="paragraph">([\s\S]+?)<\/div>/g,'$1');
    str = str.replace(/<p class="paragraph">\s*([\s\S]+?)<\/p>/g,'$1');
    str = str.replace(/<span class="(wikilink|wikiexternallink)">\s*([\s\S]+?)<\/span>/g,'$2');
    str = str.replace(/<span class="(bold|italic|strike)">([\s\S]+?)<\/span>/g,'$2');
    str = str.replace(/<\/?p[^>]*>/gi, "");
    str = str.replace(/<br \/>/g, '\r\n');
    return str;
}

WikiEditor.prototype.convertVelocityScriptsInternal = function(regexp, result, content) {
	var r = /&quot;/gi;
	return content.replace(regexp, result[0].replace(r, '"'));
{'fraction_non_alphanumeric': 0.2766282743858934, 'fraction_numerical': 0.0063194373662215884, 'mean_word_length': 5.136335209505941, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 135, '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': '7251817', 'n_tokens_mistral': 3668, 'n_tokens_neox': 3515, 'n_words': 429}