<commit_before># encoding=utf-8
require 'cgi'

module Polytexnic
  module Postprocessor

    def postprocess
      xml_to_html
    end

    def xml_to_html
      @html = Nokogiri::HTML.fragment(processed_xml).to_html
    end

    # Handles output of \emph{} and \textit{}.
    def emphasis(doc)
      doc.xpath('//hi[@rend="it"]').each do |node|
        node.name = 'em'
        node.remove_attribute('rend')
      end
    end

    # Handles output of \texttt{}.
    def typewriter(doc)
      doc.xpath('//hi[@rend="tt"]').each do |node|
        node.name = 'span'
        node['class'] = 'tt'
        node.remove_attribute('rend')
      end
    end

    # Handles verbatim and Verbatim environments.
    # \begin{verbatim}
    # <stuff>
    # \end{verbatim}
    # and
    # \begin{Verbatim}
    # <stuff>
    # \end{Verbatim}
    # Note that verbatim is a built-in LaTeX environment, whereas
    # Verbatim is loaded by the Verbatim package (and used by the
    # code environment).
    def verbatim(doc)
      doc.xpath('//verbatim').each do |node|
        node.name = 'pre'
        node['class'] = 'verbatim'
      end
      doc.xpath('//Verbatim').each do |node|
        node.name = 'pre'
        node['class'] = 'verbatim'
      end      
    end

    def processed_xml
      doc = Nokogiri::XML(@xml)
      emphasis(doc)
      typewriter(doc)
      verbatim(doc)
      # Code
      doc.xpath('//code').each do |node|
        node.name = 'div'
        node['class'] = 'code'
      end
      # equation
      doc.xpath('//equation').each do |node|
        node.name = 'div'
        node['class'] = 'equation'
        begin
          next_paragraph = node.parent.next_sibling.next_sibling
          next_paragraph['noindent'] = 'true'<commit_msg>[#47570323] Handle code envs<commit_after># encoding=utf-8
require 'cgi'

module Polytexnic
  module Postprocessor

    def postprocess
      xml_to_html
    end

    def xml_to_html
      @html = Nokogiri::HTML.fragment(processed_xml).to_html
    end

    # Handles output of \emph{} and \textit{}.
    def emphasis(doc)
      doc.xpath('//hi[@rend="it"]').each do |node|
        node.name = 'em'
        node.remove_attribute('rend')
      end
    end

    # Handles output of \texttt{}.
    def typewriter(doc)
      doc.xpath('//hi[@rend="tt"]').each do |node|
        node.name = 'span'
        node['class'] = 'tt'
        node.remove_attribute('rend')
      end
    end

    # Handles verbatim and Verbatim environments.
    # \begin{verbatim}
    # <stuff>
    # \end{verbatim}
    # and
    # \begin{Verbatim}
    # <stuff>
    # \end{Verbatim}
    # Note that verbatim is a built-in LaTeX environment, whereas
    # Verbatim is loaded by the Verbatim package (and used by the
    # code environment).
    def verbatim(doc)
      doc.xpath('//verbatim').each do |node|
        node.name = 'pre'
        node['class'] = 'verbatim'
      end
      doc.xpath('//Verbatim').each do |node|
        node.name = 'pre'
        node['class'] = 'verbatim'
      end      
    end

    # Handles code environments.
    # \begin{code}
    # <code>
    # \end{code}
    def code(doc)
      doc.xpath('//code').each do |node|
        node.name = 'div'
        node['class'] = 'code'
      end      
    end

    def processed_xml
      doc = Nokogiri::XML(@xml)
      emphasis(doc)
      typewriter(doc)
      verbatim(doc)
      code(doc)
      # equation
      doc.xpath('//equation').each do |node|
        node.name = 'div'
        node['class'] = 'equation'
        begin
          next_paragraph = node.parent.next_sibling.next_sibling
          next_paragraph['noindent'] = 'true'
{'fraction_non_alphanumeric': 0.13412283117598459, 'fraction_numerical': 0.002754062241806665, 'mean_word_length': 2.0675675675675675, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '5984217', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1185, 'n_words': 273}