<commit_before>/*
*  The "codemirror" plugin. It's indented to enhance the
*  "sourcearea" editing mode, which displays the xhtml source code with
*  syntax highlight and line numbers.
* Licensed under the MIT license
* CodeMirror Plugin: http://codemirror.net/ (MIT License)
*/

(function() {
    CKEDITOR.plugins.add('codemirror', {
        icons: 'AutoFormat,CommentSelectedRange,UncommentSelectedRange',
        lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en-au,en-ca,en-gb,en,eo,es,et,eu,fa,fi,fo,fr-ca,fr,gl,gu,he,hi,hr,hu,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt-br,pt,ro,ru,sk,sl,sr-latn,sr,sv,th,tr,ug,uk,vi,zh-cn,zh',
        init: function(editor) {
			var rootPath = this.path;
            // Default Config
            var defaultConfig = {
                theme: 'default',
                matchBrackets: true,
                lineNumbers: true,
                lineWrapping: true,
                autoCloseTags: true,
				autoCloseBrackets: true,
                enableSearchTools: true,
                enableCodeFolding: true,
                enableCodeFormatting: true,
                autoFormatOnStart: false,
                autoFormatOnModeChange: true,
                autoFormatOnUncomment: true,
                highlightActiveLine: true,
                highlightMatches: true,
                showFormatButton: true,
                showCommentButton: true,
                showUncommentButton: true
            };
            // Get Config & Lang
            var config = CKEDITOR.tools.extend(defaultConfig, editor.config.codemirror || {}, true);
            var lang = editor.lang.codemirror;
            // check for old config settings for legacy support
            if (editor.config.codemirror_theme) {
                config.theme = editor.config.codemirror_theme;
            }
            if (editor.config.codemirror_autoFormatOnStart) {
                config.autoFormatOnStart = editor.config.codemirror_autoFormatOnStart;
            }
            CKEDITOR.document.appendStyleSheet(rootPath + 'css/codemirror.min.css');

            if (config.theme.length && config.theme != 'default') {
                CKEDITOR.document.appendStyleSheet(rootPath + 'theme/' + config.theme + '.css');
            }
            CKEDITOR.scriptLoader.load(rootPath + 'js/codemirror.min.js', function() {
                CKEDITOR.scriptLoader.load(getCodeMirrorScripts());
            });
            // Source mode isn't available in inline mode yet.
            if (editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE) {
                return;
            }
            var sourcearea = CKEDITOR.plugins.sourcearea;
            editor.addMode('source', function(callback) {
                if (typeof(CodeMirror) == 'undefined') {
                    CKEDITOR.scriptLoader.load([rootPath + 'js/codemirror.min.js'].concat(getCodeMirrorScripts()), function() {
                        loadCodeMirror(editor);
                        callback();
                    });
                } else {
                    loadCodeMirror(editor);
                    callback();
                }
            });

            function getCodeMirrorScripts() {
                var scriptFiles = [rootPath + 'js/codemirror.modes.min.js', rootPath + 'js/codemirror.addons.min.js'];
				
				if (config.enableSearchTools) {
                    scriptFiles.push(rootPath + 'js/codemirror.search-addons.min.js');
                }
                return scriptFiles;
            }

            function loadCodeMirror(editor) {
                var contentsSpace = editor.ui.space('contents'),
                    textarea = contentsSpace.getDocument().createElement('textarea');
                textarea.setStyles(
                    CKEDITOR.tools.extend({
                            // IE7 has overflow the <textarea> from wrapping table cell.<commit_msg>Add autoLoadCodeMirror config variable (defaults to true). This allows disabling CodeMirror js/css autoloading in case if it's loaded manually.<commit_after>/*
*  The "codemirror" plugin. It's indented to enhance the
*  "sourcearea" editing mode, which displays the xhtml source code with
*  syntax highlight and line numbers.
* Licensed under the MIT license
* CodeMirror Plugin: http://codemirror.net/ (MIT License)
*/

(function() {
    CKEDITOR.plugins.add('codemirror', {
        icons: 'AutoFormat,CommentSelectedRange,UncommentSelectedRange',
        lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en-au,en-ca,en-gb,en,eo,es,et,eu,fa,fi,fo,fr-ca,fr,gl,gu,he,hi,hr,hu,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt-br,pt,ro,ru,sk,sl,sr-latn,sr,sv,th,tr,ug,uk,vi,zh-cn,zh',
        init: function(editor) {
			var rootPath = this.path;
            // Default Config
            var defaultConfig = {
                theme: 'default',
                autoLoadCodeMirror: true,
                matchBrackets: true,
                lineNumbers: true,
                lineWrapping: true,
                autoCloseTags: true,
				autoCloseBrackets: true,
                enableSearchTools: true,
                enableCodeFolding: true,
                enableCodeFormatting: true,
                autoFormatOnStart: false,
                autoFormatOnModeChange: true,
                autoFormatOnUncomment: true,
                highlightActiveLine: true,
                highlightMatches: true,
                showFormatButton: true,
                showCommentButton: true,
                showUncommentButton: true
            };
            // Get Config & Lang
            var config = CKEDITOR.tools.extend(defaultConfig, editor.config.codemirror || {}, true);
            var lang = editor.lang.codemirror;
            // check for old config settings for legacy support
            if (editor.config.codemirror_theme) {
                config.theme = editor.config.codemirror_theme;
            }
            if (editor.config.codemirror_autoFormatOnStart) {
                config.autoFormatOnStart = editor.config.codemirror_autoFormatOnStart;
            }

            // Source mode isn't available in inline mode yet.
            if (editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE) {
                return;
            }

            // Load CodeMirror
            if (config.autoLoadCodeMirror) {
                CKEDITOR.document.appendStyleSheet(rootPath + 'css/codemirror.min.css');
                if (config.theme.length && config.theme != 'default') {
                    CKEDITOR.document.appendStyleSheet(rootPath + 'theme/' + config.theme + '.css');
                }
                CKEDITOR.scriptLoader.load(rootPath + 'js/codemirror.min.js', function() {
                    CKEDITOR.scriptLoader.load(getCodeMirrorScripts());
                });
            }

            var sourcearea = CKEDITOR.plugins.sourcearea;
            editor.addMode('source', function(callback) {
                if (typeof(CodeMirror) == 'undefined') {
                    // Ignoring config.autoLoadCodeMirror here. If CodeMirror isn't loaded at this point, we need to load it.
                    // It is assumed that either config.autoLoadCodeMirror is true or all css files are loaded manually.
                    CKEDITOR.scriptLoader.load([rootPath + 'js/codemirror.min.js'].concat(getCodeMirrorScripts()), function() {
                        loadCodeMirror(editor);
                        callback();
                    });
                } else {
                    loadCodeMirror(editor);
                    callback();
                }
            });

            function getCodeMirrorScripts() {
                var scriptFiles = [rootPath + 'js/codemirror.modes.min.js', rootPath + 'js/codemirror.addons.min.js'];
				
				if (config.enableSearchTools) {
                    scriptFiles.push(rootPath + 'js/codemirror.search-addons.min.js');
                }
                return scriptFiles;
            }

            function loadCodeMirror(editor) {
                var contentsSpace = editor.ui.space('contents'),
                    textarea = contentsSpace.getDocument().createElement('textarea');
                textarea.setStyles(
                    CKEDITOR.tools.extend({
                            // IE7 has overflow the <textarea> from wrapping table cell.
{'fraction_non_alphanumeric': 0.10450102570290817, 'fraction_numerical': 0.00024134186074574636, 'mean_word_length': 1.8066373179817135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2183600', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2198, 'n_words': 421}