<commit_before>module Docstache
  class Renderer
    BLOCK_REGEX = /\{\{([\#\^])([\w\.]+)\}\}.+?\{\{\/\g<2>\}\}/m

    def initialize(xml, data)
      @content = xml
      @data = DataScope.new(data)
    end

    def render
      find_and_expand_blocks
      replace_tags(@content, @data)
      return @content
    end

    private

    def find_and_expand_blocks
      blocks = @content.text.scan(BLOCK_REGEX)
      found_blocks = blocks.uniq.map { |block|
        inverted = block[0] == "^"
        Block.find_all(name: block[1], elements: @content.elements, data: @data, inverted: inverted)
      }.flatten
      found_blocks.each do |block|
        expand_and_replace_block(block)
      end
    end
<commit_msg>:bug: fixes problem with a block regex<commit_after>module Docstache
  class Renderer
    BLOCK_REGEX = /\{\{([\#\^])([\w\.]+)\}\}.+?\{\{\/\k<2>\}\}/m

    def initialize(xml, data)
      @content = xml
      @data = DataScope.new(data)
    end

    def render
      find_and_expand_blocks
      replace_tags(@content, @data)
      return @content
    end

    private

    def find_and_expand_blocks
      blocks = @content.text.scan(BLOCK_REGEX)
      found_blocks = blocks.uniq.map { |block|
        inverted = block[0] == "^"
        Block.find_all(name: block[1], elements: @content.elements, data: @data, inverted: inverted)
      }.flatten
      found_blocks.each do |block|
        expand_and_replace_block(block)
      end
    end

{'fraction_non_alphanumeric': 0.14432989690721648, 'fraction_numerical': 0.004123711340206186, 'mean_word_length': 2.4749403341288785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6057301', 'n_tokens_mistral': 503, 'n_tokens_neox': 477, 'n_words': 100}