<commit_before>_ = require 'underscore'

MATH_MARKER_BLOCK  = '\u200c\u200c\u200c' # zero-width non-joiner
MATH_MARKER_INLINE = '\u200b\u200b\u200b' # zero-width space

cleanMathArtifacts = ->
  # Once MathJax finishes processing, cleanup the MathJax message nodes to prevent
  # React "Invariant Violation" exceptions.
  # MathJax calls queued events in order, so this will be called after processing completes
  window.MathJax.Hub.Queue([ ->
    # copy-pasta in `/index.coffee`
    for nodeId in ['MathJax_Message', 'MathJax_Hidden', 'MathJax_Font_Test']
      el = document.getElementById(nodeId)
      break unless el # the elements won't exist if MathJax didn't do anything
      # Some of the elements are wrapped by divs without selectors under body
      # Select the parentElement unless it's already directly under body.
      el = el.parentElement unless el.parentElement is document.body
      el.parentElement.removeChild(el)
  ])


typesetMath = (root) ->
  nodes = root.querySelectorAll('[data-math]:not(.math-rendered)') or []
  hasMath = root.querySelector('math')

  # Return immediatly if no [data-math] or <math> elements are present
  # TODO: If the MathJax Queue is not available then MathJax has not loaded yet. Add a load callback to enqueue.
  return unless window.MathJax.Hub?.Queue? and (_.any(nodes) or hasMath)

  for node in nodes
    formula = node.getAttribute('data-math')
    # divs with data-math should be rendered as a block
    if node.tagName.toLowerCase() is 'div'
      node.textContent = "#{MATH_MARKER_BLOCK}#{formula}#{MATH_MARKER_BLOCK}"
    else
      node.textContent = "#{MATH_MARKER_INLINE}#{formula}#{MATH_MARKER_INLINE}"
    window.MathJax.Hub.Queue(['Typeset', MathJax.Hub, node])
    # mark node as processed
    node.classList.add('math-rendered')<commit_msg>mathjax isn't defined on karma test runner<commit_after>_ = require 'underscore'

MATH_MARKER_BLOCK  = '\u200c\u200c\u200c' # zero-width non-joiner
MATH_MARKER_INLINE = '\u200b\u200b\u200b' # zero-width space

cleanMathArtifacts = ->
  # Once MathJax finishes processing, cleanup the MathJax message nodes to prevent
  # React "Invariant Violation" exceptions.
  # MathJax calls queued events in order, so this will be called after processing completes
  window.MathJax.Hub.Queue([ ->
    # copy-pasta in `/index.coffee`
    for nodeId in ['MathJax_Message', 'MathJax_Hidden', 'MathJax_Font_Test']
      el = document.getElementById(nodeId)
      break unless el # the elements won't exist if MathJax didn't do anything
      # Some of the elements are wrapped by divs without selectors under body
      # Select the parentElement unless it's already directly under body.
      el = el.parentElement unless el.parentElement is document.body
      el.parentElement.removeChild(el)
  ])


typesetMath = (root) ->
  nodes = root.querySelectorAll('[data-math]:not(.math-rendered)') or []
  hasMath = root.querySelector('math')

  # Return immediatly if no [data-math] or <math> elements are present
  # TODO: If the MathJax Queue is not available then MathJax has not loaded yet. Add a load callback to enqueue.
  return unless window.MathJax?.Hub?.Queue? and (_.any(nodes) or hasMath)

  for node in nodes
    formula = node.getAttribute('data-math')
    # divs with data-math should be rendered as a block
    if node.tagName.toLowerCase() is 'div'
      node.textContent = "#{MATH_MARKER_BLOCK}#{formula}#{MATH_MARKER_BLOCK}"
    else
      node.textContent = "#{MATH_MARKER_INLINE}#{formula}#{MATH_MARKER_INLINE}"
    window.MathJax.Hub.Queue(['Typeset', MathJax.Hub, node])
    # mark node as processed
    node.classList.add('math-rendered')
{'fraction_non_alphanumeric': 0.10229759299781181, 'fraction_numerical': 0.009846827133479213, 'mean_word_length': 3.989085948158254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3485902', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1143, 'n_words': 343}