<commit_before>/*
 *  Scrapedown - make a fist at turning a Web page into markdown
 */
function loadScript(src, callback, value) {
    var r = false;
    var js = document.createElement('script');
    js.type = 'text/javascript';
    js.src = scrapedown_location + src;
    js.onload = js.onreadystatechange = function() {
        if (!r && (!this.readyState || this.readyState == 'complete')) {
          r = true;
          callback(value);
        }
    };
    document.body.appendChild(js);
}


/*
 *  daisy chain loading scripts ..
 */
loadScript("readability.js", function () {
    readability.init(function (div) {
        loadScript("to-markdown.js", function () {
            var text = toMarkdown(div.innerHTML);
            textarea = scrapedown_build_gui();
            textarea.value = text;
        });
    });
});


/*
 *  create gui
 */
function scrapedown_build_gui(text) {

    var gui = document.createElement("div");
    gui.id = "scrapedown";

    var left = document.createElement("div");
    left.id = "leftContainer";
    gui.appendChild(left);

    var textarea = document.createElement("textarea");
    textarea.id = "inputPane";
    textarea.setAttribute("class", "pane");
    textarea.setAttribute("cols", 80);
    textarea.setAttribute("rows", 20);
    left.appendChild(textarea);

    var right = document.createElement("div");
    right.id = "rightContainer";
    gui.appendChild(right);

    var preview = document.createElement("div");
    preview.setAttribute("class", "pane");
    preview.id = "previewPane";

    document.body.appendChild(gui);
    return textarea;
}<commit_msg>live preview pane<commit_after>/*
 *  Scrapedown - make a fist at turning a Web page into markdown
 */
function loadScript(src, callback, value) {
    var r = false;
    var js = document.createElement('script');
    js.type = 'text/javascript';
    js.src = scrapedown_location + src;
    js.onload = js.onreadystatechange = function() {
        if (!r && (!this.readyState || this.readyState == 'complete')) {
          r = true;
          callback(value);
        }
    };
    document.body.appendChild(js);
}


/*
 *  daisy chain loading scripts ..
 */
loadScript("readability.js", function () {
    readability.init(function (div) {
        loadScript("to-markdown.js", function () {
            var text = toMarkdown(div.innerHTML);
            scrapedown_build_gui();
            document.getElementById('inputPane').value = text;

            loadScript("showdown.js", function () {
                scrapedown_render();

                // polling for changes is a little clumsy, but most reliable ..
                window.setInterval(scrapedown_render, 500);
            });
        });
    });
});


/*
 *  create gui
 */
function scrapedown_build_gui(text) {

    var gui = document.createElement("div");
    gui.id = "scrapedown";

    var left = document.createElement("div");
    left.id = "leftContainer";
    gui.appendChild(left);

    var textarea = document.createElement("textarea");
    textarea.id = "inputPane";
    textarea.setAttribute("class", "pane");
    textarea.setAttribute("cols", 80);
    textarea.setAttribute("rows", 20);
    left.appendChild(textarea);

    var right = document.createElement("div");
    right.id = "rightContainer";
    gui.appendChild(right);

    var preview = document.createElement("div");
    preview.setAttribute("class", "pane");
    preview.id = "previewPane";
    right.appendChild(preview);

    document.body.appendChild(gui);
}


/*
 *  render preview of markdown text
 */
var lastText;
var converter;

function scrapedown_render() {

    text = document.getElementById('inputPane').value;

    if (text === lastText) {
        return;
    }
    lastText = text;

    if (!converter) {
        converter = new Showdown.converter();
    }

    document.getElementById('previewPane').innerHTML = converter.makeHtml(text);
};
{'fraction_non_alphanumeric': 0.14395491803278687, 'fraction_numerical': 0.0028176229508196722, 'mean_word_length': 2.8060428849902532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1491593', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1115, 'n_words': 239}