<commit_before>jQuery(function(){

    var minimized_elements = $('p.description');

    minimized_elements.each(function(){
        var t = $(this).text();
        if(t.length < 500) return;

        $(this).html(
            t.slice(0,500)+'<span>... </span><a href="#" class="more">More</a>'+
            '<span style="display:none;">'+ t.slice(500,t.length)+' <a href="#" class="less">Less</a></span>'
        );

    });

    $('a.more', minimized_elements).click(function(event){
        event.preventDefault();
        $(this).hide().prev().hide();
        $(this).next().show();
    });

    $('a.less', minimized_elements).click(function(event){
        event.preventDefault();
        $(this).parent().hide().prev().show().prev().show();
    });

});<commit_msg>387 Markdown in monograph description<commit_after>jQuery(function(){

    var minimized_elements = $('p.description');

    minimized_elements.each(function(){
        // TODO: Threshold should probably be passed in as a parameter.
        var threshold = 500;
        if ($(this).text().length <= threshold) return;

        $md = $($.parseHTML($(this).html()));
        var m = $md.length;
        var n = 0;
        var text = "";
        var total = 0;
        $(this).html(text);
        for(n=0; n<m; n++){
          // Text nodes have a nodeType of 3
          text = ($md[n].nodeType == 3) ? $md[n].data : $md[n].innerText;
          total += text.length;
          if (total > threshold) break;
          $(this).append($md[n]);
        }

        var index = text.length - (total - threshold);
        $clone = $($md[n]).clone();
        // Text nodes have a nodeType of 3
        if ($md[n].nodeType == 3) {
          $clone[0].textContent = text.slice(0,index);
          $md[n].textContent = text.slice(index,text.length);
        } else {
          $clone[0].innerHTML = text.slice(0,index);
          $md[n].innerHTML = text.slice(index,text.length);
        }
        $(this).append($clone[0]);
        $(this).append('<span>... </span><a href="#" class="more">More</a>');
        $less = $('<span style="display:none;"></span>');
        for(; n<m; n++){
          $less.append($md[n]);
        }
        $less.append(' <a href="#" class="less">Less</a>');
        $(this).append($less);
    });

    $('a.more', minimized_elements).click(function(event){
        event.preventDefault();
        $(this).hide().prev().hide();
        $(this).next().show();
    });

    $('a.less', minimized_elements).click(function(event){
        event.preventDefault();
        $(this).parent().hide().prev().show().prev().show();
    });
});
{'fraction_non_alphanumeric': 0.22069492172584956, 'fraction_numerical': 0.010691103474608629, 'mean_word_length': 2.34610472541507, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 20, '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': '975024', 'n_tokens_mistral': 833, 'n_tokens_neox': 798, 'n_words': 145}