<commit_before>$ ->
  form = $('form#notepad_form')
  notepad = $('textarea#notepad')
  output = $('div#output')
  html_output = $('textarea#html-output')
  toggle_output = $('a#toggle-output')
  loading = $('div#loading')
  parser_select = $('select#parser')
  
  cached_input = notepad.val();
  show_html = false;
  
  # Process markdown
  process = ->
    return if notepad.val() == cached_input
    loading.show()
    pre_cache = notepad.val()
    $.post form.attr('action'), form.serialize(), (data, textStatus) ->
      output.html(data)
      html_output.val(data)
      loading.hide()
      cached_input = pre_cache
  
  # Parser change
  parser_change = ->
    # TODO: update default if it is still the default text
    cached_input = ''
    
    # Reprocess
    process()
  
  # Toggle output
  toggle = (e) ->
    e.preventDefault()
    show_html = !show_html
    
    if show_html
      toggle_output.html('Hide HTML')
      output.hide()
      html_output.show()
    else
      toggle_output.html('Show HTML')
      output.show()
      html_output.hide()
  
  # Add event for keyup and focus
  notepad.keyup(process)
  notepad.focus()
  
  # Add event for parser change
  parser_select.change(parser_change)
  
  # Add event for toggle link
  toggle_output.click(toggle)<commit_msg>Use the new API<commit_after>$ ->
  form = $('form#notepad_form')
  notepad = $('textarea#notepad')
  output = $('div#output')
  html_output = $('textarea#html-output')
  toggle_output = $('a#toggle-output')
  loading = $('div#loading')

  last_markdown = notepad.val();
  show_html = false;

  # Process markdown
  process = ->
    markdown = notepad.val()
    return if markdown == last_markdown
    loading.show()
    jQuery.ajax(
      url: form.attr('action')
      data: markdown
      type: 'POST'
      headers:
        'Content-Type': 'text/x-markdown'
        'Accept': 'text/html'
      dataType: 'html'
    ).done (data) ->
      output.html(data)
      html_output.val(data)
      loading.hide()
      last_markdown = markdown

  # Toggle output
  toggle = (e) ->
    e.preventDefault()
    show_html = !show_html

    if show_html
      toggle_output.html('Hide HTML')
      output.hide()
      html_output.show()
    else
      toggle_output.html('Show HTML')
      output.show()
      html_output.hide()

  # Add event for keyup and focus
  notepad.keyup(process)
  notepad.focus()

  # Add event for toggle link
  toggle_output.click(toggle)
{'fraction_non_alphanumeric': 0.1333061557276804, 'fraction_numerical': 0.0, 'mean_word_length': 2.7753846153846156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '5382365', 'n_tokens_mistral': 836, 'n_tokens_neox': 806, 'n_words': 175}