(function () {
  var content = document.querySelector('.content');
  if (!content) return;

  var headings = content.querySelectorAll('h2, h3, h4');
  if (!headings.length) return;

  headings.forEach(function (h) {
    if (!h.id) return;
    var a = document.createElement('a');
    a.href = '#' + h.id;
    a.className = 'heading-anchor';
    a.setAttribute('aria-label', 'Link to this section');
    a.textContent = '#';
    h.insertBefore(a, h.firstChild);
  });
}());
