<commit_before>var url = require('url');
var _ = require('lodash');
var inherits = require('util').inherits;
var links = require('../utils').links;
var kramed = require('kramed');

var rendererId = 0;

function GitBookRenderer(options, extra_options) {
    if(!(this instanceof GitBookRenderer)) {
        return new GitBookRenderer(options, extra_options);
    }
    GitBookRenderer.super_.call(this, options);

    this._extra_options = extra_options;
    this.quizRowId = 0;
    this.id = rendererId++;
    this.quizIndex = 0;
}
inherits(GitBookRenderer, kramed.Renderer);

GitBookRenderer.prototype._unsanitized = function(href) {
    var prot = '';
    try {
        prot = decodeURIComponent(unescape(href))
            .replace(/[^\w:]/g, '')
            .toLowerCase();

    } catch (e) {
        return true;
    }

    if(prot.indexOf('javascript:') === 0) {
        return true;
    }

    return false;
};

GitBookRenderer.prototype.link = function(href, title, text) {
    // Our "fixed" href
    var _href = href;

    // Don't build if it looks malicious
    if (this.options.sanitize && this._unsanitized(href)) {
        return text;
    }

    // Parsed version of the url
    var parsed = url.parse(href);
    var o = this._extra_options;
    var extname = _.last(parsed.path.split("."));

    // Relative link, rewrite it to point to github repo
    if(links.isRelative(_href) && extname == "md") {<commit_msg>Fix #491: handle correctly url without path for links<commit_after>var url = require('url');
var _ = require('lodash');
var inherits = require('util').inherits;
var links = require('../utils').links;
var kramed = require('kramed');

var rendererId = 0;

function GitBookRenderer(options, extra_options) {
    if(!(this instanceof GitBookRenderer)) {
        return new GitBookRenderer(options, extra_options);
    }
    GitBookRenderer.super_.call(this, options);

    this._extra_options = extra_options;
    this.quizRowId = 0;
    this.id = rendererId++;
    this.quizIndex = 0;
}
inherits(GitBookRenderer, kramed.Renderer);

GitBookRenderer.prototype._unsanitized = function(href) {
    var prot = '';
    try {
        prot = decodeURIComponent(unescape(href))
            .replace(/[^\w:]/g, '')
            .toLowerCase();

    } catch (e) {
        return true;
    }

    if(prot.indexOf('javascript:') === 0) {
        return true;
    }

    return false;
};

GitBookRenderer.prototype.link = function(href, title, text) {
    // Our "fixed" href
    var _href = href;

    // Don't build if it looks malicious
    if (this.options.sanitize && this._unsanitized(href)) {
        return text;
    }

    // Parsed version of the url
    var parsed = url.parse(href);
    var o = this._extra_options;
    var extname = parsed.path? _.last(parsed.path.split(".")) : "";

    // Relative link, rewrite it to point to github repo
    if(links.isRelative(_href) && extname == "md") {
{'fraction_non_alphanumeric': 0.1415352981494174, 'fraction_numerical': 0.0037697052775873888, 'mean_word_length': 2.9392712550607287, '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': '6052875', 'n_tokens_mistral': 939, 'n_tokens_neox': 910, 'n_words': 219}