<commit_before>var check = require('check-types');
var html = require('pithy');

var sampleDiv = require('./sample');
var exampleDiv = require('./example');
var reformat = require('../utils/code').reformat;

function examplesToHtml(name, apiExamples, framework) {
    check.verifyString(name, 'missing name');
    check.verifyArray(apiExamples, 'missing api examples');

    var examples = apiExamples.map(function (example) {
        return exampleDiv(name, example.comment, framework);
    });
    return examples;
}

function samplesToHtml(apiSamples, framework) {
    check.verifyArray(apiSamples, 'missing api samples');
    var samples = apiSamples.map(function (example) {
        return sampleDiv(example, framework);
    });
    return samples;
}

function codeDiv(id, apiComment, visible) {
    check.verifyString(id, 'missing code id');
    check.verifyObject(apiComment, 'missing comment');
    // console.log('code div for\n', apiComment);
    if (!apiComment.code) {
        return null;
    }
    check.verifyString(apiComment.code, 'missing code');

    var prettyCode = reformat(apiComment.code, true);
    check.verifyString(prettyCode, 'could not make code pretty for\n', apiComment.code);

    check.verifyObject(apiComment.ctx, 'missing ctx in ' + JSON.stringify(apiComment));
    var name = apiComment.ctx.type + ' ' + apiComment.ctx.name;

    var classNames = 'methodCode namedCode';
    if (visible) {
        classNames += ' displayed';
    }
    var attributes = {
        id: id + 'd',
        class: classNames
    };
    var codeElement = html.div(attributes, [
        html.span({
            class: "sampleName sampleLabel"
        }, name),
        html.pre({
            class: "prettyprint linenums"
        }, prettyCode)
    ]);

    return codeElement;
}

function methodDiv(commented, framework) {
    check.verifyObject(commented, 'missing api comment object');
    check.verifyString(framework, 'missing framework');

    var apiComment = commented.comment;
    check.verifyObject(apiComment, 'expected comment object');

    var name = null;
    var ctx = apiComment.ctx;
    if (ctx) {
        console.assert(ctx, 'missing ctx property, comment', apiComment);
        check.verifyString(ctx.name, 'missing function name');
        name = ctx.name;
    } else {
        name = apiComment.tagValue('function');
    }
    if (!name) {
        return null;
    }
    console.log('documenting method', name);

    var toggles = [];
    var exampleElements = [];<commit_msg>inserted code block inside pre block for methods fixes #59<commit_after>var check = require('check-types');
var html = require('pithy');

var sampleDiv = require('./sample');
var exampleDiv = require('./example');
var reformat = require('../utils/code').reformat;

function examplesToHtml(name, apiExamples, framework) {
    check.verifyString(name, 'missing name');
    check.verifyArray(apiExamples, 'missing api examples');

    var examples = apiExamples.map(function (example) {
        return exampleDiv(name, example.comment, framework);
    });
    return examples;
}

function samplesToHtml(apiSamples, framework) {
    check.verifyArray(apiSamples, 'missing api samples');
    var samples = apiSamples.map(function (example) {
        return sampleDiv(example, framework);
    });
    return samples;
}

function codeDiv(id, apiComment, visible) {
    check.verifyString(id, 'missing code id');
    check.verifyObject(apiComment, 'missing comment');
    // console.log('code div for\n', apiComment);
    if (!apiComment.code) {
        return null;
    }
    check.verifyString(apiComment.code, 'missing code');

    var prettyCode = reformat(apiComment.code, true);
    check.verifyString(prettyCode, 'could not make code pretty for\n', apiComment.code);

    check.verifyObject(apiComment.ctx, 'missing ctx in ' + JSON.stringify(apiComment));
    var name = apiComment.ctx.type + ' ' + apiComment.ctx.name;

    var classNames = 'methodCode namedCode';
    if (visible) {
        classNames += ' displayed';
    }
    var attributes = {
        id: id + 'd',
        class: classNames
    };
    var codeElement = html.div(attributes, [
        html.span(".sampleName.sampleLabel", name),
        html.pre(".prettyprint.linenums", [
            html.code(null, prettyCode)])
    ]);

    return codeElement;
}

function methodDiv(commented, framework) {
    check.verifyObject(commented, 'missing api comment object');
    check.verifyString(framework, 'missing framework');

    var apiComment = commented.comment;
    check.verifyObject(apiComment, 'expected comment object');

    var name = null;
    var ctx = apiComment.ctx;
    if (ctx) {
        console.assert(ctx, 'missing ctx property, comment', apiComment);
        check.verifyString(ctx.name, 'missing function name');
        name = ctx.name;
    } else {
        name = apiComment.tagValue('function');
    }
    if (!name) {
        return null;
    }
    console.log('documenting method', name);

    var toggles = [];
    var exampleElements = [];
{'fraction_non_alphanumeric': 0.13038301250248066, 'fraction_numerical': 0.00039690414764834294, 'mean_word_length': 3.2317380352644838, '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': '4414447', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1410, 'n_words': 358}