<commit_before>module.exports = 
  getCursorPosition: (el) ->
    pos = 0
    # IE Support
    if document.selection
      el.focus()
      Sel = document.selection.createRange()
      SelLength = document.selection.createRange().text.length
      Sel.moveStart 'character', -el.value.length
      pos = Sel.text.length - SelLength
    # Firefox support
    else if el.selectionStart or el.selectionStart is 0
      pos = el.selectionStart
    pos

  number: (el) ->
    selector = 'H1,H2,H3,H4,H5,H6' # + ',OL,UL,LI'
    elems = []
    order = selector.split(',')
    map = {}
    map[sel] = {c:0, pos:i} for sel, i in order
    num = (tag) ->
      (c for i in [0..map[tag].pos]\
       when (c=map[(t=order[i])].c) isnt 0\
       and t not in ['OL', 'UL']).join ','
    count = (sel) ->
      e = map[sel]
      e.c++
      (map[order[i]].c = 0 for i in [e.pos+1...order.length])
    reset = (clear) ->
      elems = [] if clear
      obj.c = 0 for sel,obj of map
    for h, i in el.querySelectorAll('[data-number-reset],[data-number-clear],'+selector)
      if h.hasAttribute 'data-number-reset'
        reset()
      else if h.hasAttribute 'data-number-clear'
        reset true
      else
        t = h.tagName
        count t
        elems.push [h, num t] if t not in ['OL', 'UL']
    h.setAttribute 'data-number', n for [h, n] in elems
    el

  index: (el) ->
    for e in el.querySelectorAll('[data-number]')
      e.innerHTML = """
                   <span class="index">
                   #{e.getAttribute('data-number').split(',').join('. ')}.
                   </span>
                   """ + e.innerHTML
    el

  toc: (el) ->
    '<ul>' + (for e in el.querySelectorAll('H1,H2,H3,H4,H5,H6')
      """
      <li><a href="##{e.id}"><#{e.tagName}>
      #{e.innerHTML}
      </#{e.tagName}></a></li>
      """
    ).join('') + '</ul>'<commit_msg>Fixed hash links to headers from TOC<commit_after>slug = (str) -> str.trim().replace(/\s+/g,'-').toLowerCase()

module.exports = 
  getCursorPosition: (el) ->
    pos = 0
    # IE Support
    if document.selection
      el.focus()
      Sel = document.selection.createRange()
      SelLength = document.selection.createRange().text.length
      Sel.moveStart 'character', -el.value.length
      pos = Sel.text.length - SelLength
    # Firefox support
    else if el.selectionStart or el.selectionStart is 0
      pos = el.selectionStart
    pos

  number: (el) ->
    selector = 'H1,H2,H3,H4,H5,H6' # + ',OL,UL,LI'
    elems = []
    order = selector.split(',')
    map = {}
    map[sel] = {c:0, pos:i} for sel, i in order
    num = (tag) ->
      (c for i in [0..map[tag].pos]\
       when (c=map[(t=order[i])].c) isnt 0\
       and t not in ['OL', 'UL']).join ','
    count = (sel) ->
      e = map[sel]
      e.c++
      (map[order[i]].c = 0 for i in [e.pos+1...order.length])
    reset = (clear) ->
      elems = [] if clear
      obj.c = 0 for sel,obj of map
    for h, i in el.querySelectorAll('[data-number-reset],[data-number-clear],'+selector)
      if h.hasAttribute 'data-number-reset'
        reset()
      else if h.hasAttribute 'data-number-clear'
        reset true
      else
        t = h.tagName
        count t
        elems.push [h, num t] if t not in ['OL', 'UL']
    h.setAttribute 'data-number', n for [h, n] in elems
    el

  index: (el) ->
    for e in el.querySelectorAll('[data-number]')
      e.innerHTML = """
                   <span class="index">
                   #{e.getAttribute('data-number').split(',').join('. ')}.
                   </span>
                   """ + e.innerHTML
    el

  slug: slug

  toc: (el) ->
    '<ul>' + (for e in el.querySelectorAll('H1,H2,H3,H4,H5,H6')
      e.id = slug e.textContent
      """
      <li><a href="##{e.id}"><#{e.tagName}>
      #{e.innerHTML}
      </#{e.tagName}></a></li>
      """
    ).join('') + '</ul>'
{'fraction_non_alphanumeric': 0.18271476771347003, 'fraction_numerical': 0.010381520892810797, 'mean_word_length': 1.987596899224806, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 38, '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': '69215', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1366, 'n_words': 319}