<commit_before># *************************************
#
#   Heading Links
#   -> Named anchor links on headings
#
# *************************************
#
# options.elements - the heading elements
# options.anchorClass - the class to add to the anchor
#
# *************************************

@Spellbook.headingLinks = do ->

  settings = {}

  init = (options) ->
    settings = $.extend(
      headings: $('h1, h2, h3, h4, h5')
      anchorClass: 'anchor'
    , options)

    addAnchors()

  slugify = (string) ->
    string.toLowerCase().replace(/[^\w ]+/g,'').replace(/\s+/g,'-')

  addAnchors = ->
    settings.headings.each ->
      element = $(@)
      slug = slugify( element.text() )
      element.attr('id', slug)
      element.prepend("<a class='#{settings.anchorClass}' href='##{slug}'>#</a>")

  init: init

# -------------------------------------
#   Usage
# -------------------------------------
#
# Spellbook.headingLinks.init()
#<commit_msg>Add comments to Spellbook.headingLinks<commit_after># *************************************
#
#   Heading Links
#   -> Named anchor links on headings
#
# *************************************
#
# options.elements - the heading elements
# options.anchorClass - the class to add to the anchor
#
# *************************************

@Spellbook.headingLinks = do ->

  # -------------------------------------
  #   Instance Variables
  # -------------------------------------

  settings = {}

  # -------------------------------------
  #   Initialize
  # -------------------------------------

  init = (options) ->
    settings = $.extend(
      headings: $('h1, h2, h3, h4, h5')
      anchorClass: 'anchor'
    , options)

    addAnchors()

  # -------------------------------------
  #   Slugify
  # -------------------------------------
  # string - the string to slugify
  # -------------------------------------

  slugify = (string) ->
    string.toLowerCase().replace(/[^\w ]+/g,'').replace(/\s+/g,'-')

  # -------------------------------------
  #   Add Anchors
  # -------------------------------------

  addAnchors = ->
    settings.headings.each ->
      element = $(@)
      slug = slugify( element.text() )
      element.attr('id', slug)
      element.prepend("<a class='#{settings.anchorClass}' href='##{slug}'>#</a>")

  # -------------------------------------
  #   Public Methods
  # -------------------------------------

  init: init

# -------------------------------------
#   Usage
# -------------------------------------
#
# Spellbook.headingLinks.init()
#
{'fraction_non_alphanumeric': 0.42733699921445406, 'fraction_numerical': 0.003927729772191673, 'mean_word_length': 1.3893058161350844, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '6319535', 'n_tokens_mistral': 705, 'n_tokens_neox': 671, 'n_words': 128}