<commit_before><!DOCTYPE html>
<html lang="en" class="no-js">
  <head>
    <meta charset="utf-8" />
    <title>Page Editor</title>
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/style.css" type="text/css" />
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/editor/paper.css" type="text/css" />
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/editor/editor.css" type="text/css" />
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/icomoon/style.css" type="text/css" />
    <meta name="robots" content="noindex, nofollow" />
  </head>
  <body>
    <div id="saving"><span class="text">Saving...</span></div>
    <div id="error">{{ error }}</div>
    <div class="editorwrap">
      <span class="title">{{ base_url ~ url }}</span>
      <textarea>{{ content }}</textarea>
    </div>

    <script type="text/javascript">
      var current_url = '{{ base_url ~ url }}';
    </script>
    <script src="{{ base_url }}/{{ editor_path }}/js/jquery.min.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/marked.min.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/codemirror.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/continuelist.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/markdown.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/xml.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/src/intro.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/src/editor.js"></script>
    <script type="text/javascript">
    // @see http://stackoverflow.com/questions/784586/convert-special-characters-to-html-in-javascript
    function htmlentities(s) {
        var el = document.createElement("div");
        el.innerText = el.textContent = s;
        s = el.innerHTML;
        return s;
    }
    // main function
    function updateFunction(params){
        return function(editor){
            $('#saving').addClass('active').find('.text').text(params.loadingText || 'Updating ...');
            var content = params.content || editor.codemirror.getValue();
            content = htmlentities(content);
            console.log('%o', content);
            $.post(current_url, { edit: true, content: content }, function(data){
                console.log('%o', data);
                if(data.error !== ''){
                    $('#error').addClass('active').text(data.error || data);
                    $('#saving').removeClass('active');
                    setTimeout(function(){
                        $('#error').removeClass('active');
                    }, 1000);
                } else {
                    $('#saving .text').text(params.loadedText || 'Updated');
                    document.title = document.title.replace(' *', '');
                    setTimeout(function(){
                        $('#saving').removeClass('active');
                        if(params.callback)
                            params.callback();
                    }, 1000);
                }
            }, 'json');
        };
    }
    var saveFile = updateFunction({
        loadingText: 'Saving...',
        loadedText: 'Saved',
    });
    var deleteFile = updateFunction({
        loadingText: 'Deleting...',
        loadedText: 'Deleted'
    });
    function safeDeleteFile(editor){
        var ok = confirm('Do you really want to delete this page?');
        if(!ok) return;
        deleteFile(editor);
    }

    var saveAndBrowse = updateFunction({
        loadingText: 'Saving...',
        loadedText: 'Saved',
        callback: function(){
            window.location = current_url;
        }
    });

    $(function() {
        // add the save and delete actions
        var saveIdx = Editor.toolbar.length - 1;
        Editor.toolbar.splice(saveIdx, 0,
            { name: 'save', action: saveFile },
            { name: 'delete', action: safeDeleteFile },
            '|',
            { name: 'save', shortcut: 'Ctrl-S', action: saveAndBrowse }
        );

        var editor = new Editor();
        editor.render();
        $('.editorwrap').data('editor', editor);
    });
    </script>

  </body>
</html>
<commit_msg>Minor comment<commit_after><!DOCTYPE html>
<html lang="en" class="no-js">
  <head>
    <meta charset="utf-8" />
    <title>Page Editor</title>
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/style.css" type="text/css" />
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/editor/paper.css" type="text/css" />
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/editor/editor.css" type="text/css" />
    <link rel="stylesheet" href="{{ base_url }}/{{ editor_path }}/icomoon/style.css" type="text/css" />
    <meta name="robots" content="noindex, nofollow" />
  </head>
  <body>
    <div id="saving"><span class="text">Saving...</span></div>
    <div id="error">{{ error }}</div>
    <div class="editorwrap">
      <span class="title">{{ base_url ~ url }}</span>
      <textarea>{{ content }}</textarea>
    </div>

    <script type="text/javascript">
      var current_url = '{{ base_url ~ url }}';
    </script>
    <script src="{{ base_url }}/{{ editor_path }}/js/jquery.min.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/marked.min.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/codemirror.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/continuelist.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/markdown.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/vendor/xml.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/src/intro.js"></script>
    <script src="{{ base_url }}/{{ editor_path }}/editor/src/editor.js"></script>
    <script type="text/javascript">
    // @see http://stackoverflow.com/questions/784586/convert-special-characters-to-html-in-javascript
    function htmlentities(s) {
        var el = document.createElement("div");
        el.innerText = el.textContent = s;
        s = el.innerHTML;
        return s;
    }
    // main function
    function updateFunction(params){
        return function(editor){
            $('#saving').addClass('active').find('.text').text(params.loadingText || 'Updating ...');
            var content = params.content || editor.codemirror.getValue();
            content = htmlentities(content);
            // console.log('%o', content);
            $.post(current_url, { edit: true, content: content }, function(data){
                // console.log('%o', data);
                if(data.error !== ''){
                    $('#error').addClass('active').text(data.error || data);
                    $('#saving').removeClass('active');
                    setTimeout(function(){
                        $('#error').removeClass('active');
                    }, 1000);
                } else {
                    $('#saving .text').text(params.loadedText || 'Updated');
                    document.title = document.title.replace(' *', '');
                    setTimeout(function(){
                        $('#saving').removeClass('active');
                        if(params.callback)
                            params.callback();
                    }, 1000);
                }
            }, 'json');
        };
    }
    var saveFile = updateFunction({
        loadingText: 'Saving...',
        loadedText: 'Saved',
    });
    var deleteFile = updateFunction({
        loadingText: 'Deleting...',
        loadedText: 'Deleted'
    });
    function safeDeleteFile(editor){
        var ok = confirm('Do you really want to delete this page?');
        if(!ok) return;
        deleteFile(editor);
    }

    var saveAndBrowse = updateFunction({
        loadingText: 'Saving...',
        loadedText: 'Saved',
        callback: function(){
            window.location = current_url;
        }
    });

    $(function() {
        // add the save and delete actions
        var saveIdx = Editor.toolbar.length - 1;
        Editor.toolbar.splice(saveIdx, 0,
            { name: 'save', action: saveFile },
            { name: 'delete', action: safeDeleteFile },
            '|',
            { name: 'save', shortcut: 'Ctrl-S', action: saveAndBrowse }
        );

        var editor = new Editor();
        editor.render();
        $('.editorwrap').data('editor', editor);
    });
    </script>

  </body>
</html>

{'fraction_non_alphanumeric': 0.18744142455482662, 'fraction_numerical': 0.003983130271790066, 'mean_word_length': 2.226379440665155, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6106844', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2434, 'n_words': 491}