<commit_before>class MarkupLatex

  require "#{Rails.root}/lib/hedra-latex.rb"

  def initialize(text)
    @text  = text    
  end
  
  def to_latex
    build_string_from_array build_array decode @text.dup
  end

  private

  def build_string_from_array(compiled_array)
    string = ""
    compiled_array.each{|a| string << a[1]}
    string
  end

  def build_array(content_text)
    array = prepare_text content_text
    compiled_array = compile_latex array
  end

  def decode(content_text)
    coder ||= HTMLEntities.new
    coder.decode(content_text)
  end
  
  def compile_latex(array)
    array.each do |element|
      if element[0] == :html
        element[1] = HedraLatex.convert(Kramdown::Document.new(element[1], :input => 'html').root)[0]
      elsif element[0] == :latex
        element[1] = ActionView::Base.full_sanitizer.sanitize(element[1])
        #removing html tags of latex code
      end
    end
  end

  def prepare_text(text)
    l_begin = "{beginlatex}"
    l_end = "{endlatex}"
    start_index = 0
    array_text = []

    while !text.empty?
      start_latex = text.index(l_begin)
      if(start_latex.nil?)
        array_text << [:html, text[(start_index)..(text.size - 1)]]
        text[start_index..text.size - 1] = ""
      else
        end_latex = text.index(l_end)
        array_text << [:html, text[(start_index)..(start_latex - 1)]]
        array_text << [:latex, text[(start_latex + l_begin.size)..(end_latex - 1)]]
        text[(start_index)..(end_latex + l_end.size - 1)] = ""
      end 
    end
    array_text
  end
end<commit_msg>Alteração da tag do código Latex<commit_after>class MarkupLatex

  require "#{Rails.root}/lib/hedra-latex.rb"

  def initialize(text)
    @text  = text    
  end
  
  def to_latex
    build_string_from_array build_array decode @text.dup
  end

  private

  def build_string_from_array(compiled_array)
    string = ""
    compiled_array.each{|a| string << a[1]}
    string
  end

  def build_array(content_text)
    array = prepare_text content_text
    compiled_array = compile_latex array
  end

  def decode(content_text)
    coder ||= HTMLEntities.new
    coder.decode(content_text)
  end
  
  def compile_latex(array)
    array.each do |element|
      if element[0] == :html
        element[1] = HedraLatex.convert(Kramdown::Document.new(element[1], :input => 'html').root)[0]
      elsif element[0] == :latex
        element[1] = ActionView::Base.full_sanitizer.sanitize(element[1])
        #removing html tags of latex code
      end
    end
  end

  def prepare_text(text)
    l_begin = "{{"
    l_end = "}}"
    start_index = 0
    array_text = []

    while !text.empty?
      start_latex = text.index(l_begin)
      if(start_latex.nil?)
        array_text << [:html, text[(start_index)..(text.size - 1)]]
        text[start_index..text.size - 1] = ""
      else
        end_latex = text.index(l_end)
        array_text << [:html, text[(start_index)..(start_latex - 1)]]
        array_text << [:latex, text[(start_latex + l_begin.size)..(end_latex - 1)]]
        text[(start_index)..(end_latex + l_end.size - 1)] = ""
      end 
    end
    array_text
  end
end
{'fraction_non_alphanumeric': 0.12551768079006054, 'fraction_numerical': 0.008920038228735267, 'mean_word_length': 2.7649880095923263, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, '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': '5068397', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1116, 'n_words': 214}