<commit_before>define([
    'jquery',
    'underscore',
    'knockout',
    'summernote'
], function ($, _, ko) {
    /**
    * A knockout.js binding for the "summernote" rich text editor widget
    * - pass options to summernote using the following syntax in the knockout
    * data-bind attribute
    * @example
    * summernote: {height: 250}
    * @constructor
    * @name summernote
    */
    ko.bindingHandlers.summernote = {
        init: function(element, valueAccessor, allBindings, viewModel, bindingContext){
            var $element = $(element);
            var options = ko.unwrap(valueAccessor());
            $('.note-codable').on( "keyup", function(text){
                text.currentTarget.value = text.currentTarget.value.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
                console.log(text.currentTarget.value)
            })
            $('.note-codable').on( "paste", function(text){
                text.currentTarget.value = text.currentTarget.value.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
                console.log(text.currentTarget.value)
            })
            options = (typeof options === 'object') ? options : {};
            options = _.defaults(options, {
                height: 150,
                value: ko.observable('')
            });

            options.callbacks = options.callbacks ? options.callbacks : {};
            var userChange = options.callbacks.onChange ? options.callbacks.onChange : null;
            options.callbacks.onChange = function(value) {
                if (ko.isObservable(options.value)) {
                    options.value(value);
                } else {
                    options.value = value;
                }
                if (userChange && typeof userChange === 'function') {
                    userChange.apply($element, arguments);
                }
            };

            $element.summernote(options);

            if (ko.isObservable(options.value)) {
                options.value.subscribe(function(value) {
                    var currentContent = $element.summernote('code');
                    if (value !== currentContent) {
                        $element.summernote('code', value);<commit_msg>Added regex in summernote binding handler to clear script tags from the code editor, re #1837<commit_after>define([
    'jquery',
    'underscore',
    'knockout',
    'summernote'
], function ($, _, ko) {
    /**
    * A knockout.js binding for the "summernote" rich text editor widget
    * - pass options to summernote using the following syntax in the knockout
    * data-bind attribute
    * @example
    * summernote: {height: 250}
    * @constructor
    * @name summernote
    */
    ko.bindingHandlers.summernote = {
        init: function(element, valueAccessor, allBindings, viewModel, bindingContext){
            console.log('initing')
            var $element = $(element);
            var options = ko.unwrap(valueAccessor());
            options = (typeof options === 'object') ? options : {};
            options = _.defaults(options, {
                height: 150,
                value: ko.observable('')
            });

            options.callbacks = options.callbacks ? options.callbacks : {};
            var userChange = options.callbacks.onChange ? options.callbacks.onChange : null;
            options.callbacks.onChange = function(value) {
                if (ko.isObservable(options.value)) {
                    options.value(value);
                } else {
                    options.value = value;
                }
                if (userChange && typeof userChange === 'function') {
                    userChange.apply($element, arguments);
                }
            };

            $element.summernote(options);

            function clearScriptTags(){
                var noteCodable = $('textarea.note-codable')
                noteCodable.val(noteCodable.val().replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, ''))
                console.log('Script tags are not permitted in the code editor')
            }

            $('.btn-codeview').on( "mousedown", clearScriptTags)
            $('textarea.note-codable').on( "keypress", clearScriptTags)

            if (ko.isObservable(options.value)) {
                options.value.subscribe(function(value) {
                    var currentContent = $element.summernote('code');
                    if (value !== currentContent) {
                        $element.summernote('code', value);
{'fraction_non_alphanumeric': 0.13743139407244787, 'fraction_numerical': 0.003512623490669594, 'mean_word_length': 1.863607793840352, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 9, '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': '921314', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1154, 'n_words': 240}