<commit_before>'use strict';

// Based on: https://raw.github.com/imathis/octopress/master/plugins/code_block.rb

var util = require('hexo-util');
var highlight = util.highlight;
var stripIndent = require('strip-indent');

var rCaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/)(\S+)\s+(.+)/i;
var rCaptionUrl = /(\S[\S\s]*)\s+(https?:\/\/)(\S+)/i;
var rCaption = /(\S[\S\s]*)/;
var rLang = /\s*lang:(\w+)/i;

/**
* Code block tag
*
* Syntax:
*   {% codeblock [title] [lang:language] [url] [link text] %}
*   code snippet
*   {% endcodeblock %}
*/

module.exports = function(ctx) {
  return function codeTag(args, content) {
    var arg = args.join(' ');
    var config = ctx.config.highlight || {};

    if (!config.enable) {
      return '<pre><code>' + content + '</code></pre>';
    }

    var caption = '';
    var lang = '';
    var match;

    if (rLang.test(arg)) {
      arg = arg.replace(rLang, function() {
        lang = arguments[1];
        return '';
      });
    }

    if (rCaptionUrlTitle.test(arg)) {
      match = arg.match(rCaptionUrlTitle);
      caption = '<span>' + match[1] + '</span><a href="' + match[2] + match[3] + '">' + match[4] + '</a>';
    } else if (rCaptionUrl.test(arg)) {
      match = arg.match(rCaptionUrl);
      caption = '<span>' + match[1] + '</span><a href="' + match[2] + match[3] + '">link</a>';
    } else if (rCaption.test(arg)) {
      match = arg.match(rCaption);
      caption = '<span>' + match[1] + '</span>';
    }

    content = stripIndent(content).trim();

    content = highlight(content, {
      lang: lang,
      caption: caption,
      gutter: config.line_number,
      tab: config.tab_replace,
      autoDetect: config.auto_detect
    });

    content = content.replace(/{/g, '&#123;')
      .replace(/}/g, '&#125;');

    return content;
  };
};<commit_msg>added line_number flag to code block, allowing for independent enabling/disabling of line numbers for each block<commit_after>'use strict';

// Based on: https://raw.github.com/imathis/octopress/master/plugins/code_block.rb

var util = require('hexo-util');
var highlight = util.highlight;
var stripIndent = require('strip-indent');

var rCaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/)(\S+)\s+(.+)/i;
var rCaptionUrl = /(\S[\S\s]*)\s+(https?:\/\/)(\S+)/i;
var rCaption = /(\S[\S\s]*)/;
var rLang = /\s*lang:(\w+)/i;
var rLineNumber = /\s*line_number:(\w+)/i;

/**
 * Code block tag
 *
 * Syntax:
 *   {% codeblock [title] [lang:language] [url] [link text] [line_number:(true|false)] %}
 *   code snippet
 *   {% endcodeblock %}
 */

module.exports = function(ctx) {

  return function codeTag(args, content) {
    var arg = args.join(' ');
    var config = ctx.config.highlight || {};

    if (!config.enable) {
      return '<pre><code>' + content + '</code></pre>';
    }

    var caption = '';
    var lang = '';
    var line_number = config.line_number;
    var match;

    if (rLang.test(arg)) {
      arg = arg.replace(rLang, function() {
        lang = arguments[1];
        return '';
      });
    }

    if (rLineNumber.test(arg)) {
      arg = arg.replace(rLineNumber, function() {
        line_number = arguments[1] === 'true';
        return '';
      });
    }

    if (rCaptionUrlTitle.test(arg)) {
      match = arg.match(rCaptionUrlTitle);
      caption = '<span>' + match[1] + '</span><a href="' + match[2] + match[3] + '">' + match[4] + '</a>';
    } else if (rCaptionUrl.test(arg)) {
      match = arg.match(rCaptionUrl);
      caption = '<span>' + match[1] + '</span><a href="' + match[2] + match[3] + '">link</a>';
    } else if (rCaption.test(arg)) {
      match = arg.match(rCaption);
      caption = '<span>' + match[1] + '</span>';
    }

    content = stripIndent(content).trim();

    content = highlight(content, {
      lang: lang,
      caption: caption,
      gutter: line_number,
      tab: config.tab_replace,
      autoDetect: config.auto_detect
    });

    content = content.replace(/{/g, '&#123;')
      .replace(/}/g, '&#125;');

    return content;
  };
};
{'fraction_non_alphanumeric': 0.2142501245640259, 'fraction_numerical': 0.007722969606377678, 'mean_word_length': 2.7664165103189493, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 2, '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': '1645435', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1404, 'n_words': 285}