auto_anchors
This module automatically generates HTML id attributes for a configurable list of matched elements. The most common (and default) use is to automatically generate HTML ids on headings, for the purpose of creating anchor links. For example:
<h2>About Dunder Mifflin</h2>
becomes:
<h2 id="about-dunder-mifflin">About Dunder Mifflin</h2>
This module also can insert permalinks inline to aid editors or site users in copying the appropriate URL to link directly to an anchor (such as "/about#kevins-famous-chili"). This mimics the behavior that is available on pages within the Drupal Developer Documentation on drupal.org.
This module was discussed as the Module of the Week on the Talking Drupal podcast, episode #477. (From 3:05 to 11:45)
Features
- Can be applied to a fully-configurable list of elements anywhere on the page (not just within a node body or field, and not just on headings)
- Does not interfere with or change manually-added or already-existing HTML ids
- Converts text to i18n-friendly, hyphenated, short, and clean HTML ids
- Generates unique ids, even when multiple elements have the same text content
Usage
By default, this module automatically generates ids on <h2>, <h3>, <h4>, <h5>, and <h6> elements within the HTML <body> and inserts inline permalinks that can be viewed by administrator users. Simply download and install the module.
For more advanced configuration, visit the module settings page (located at /admin/config/auto_anchors/settings). The visibility of inserted inline permalinks can also be controlled via permissions (at /admin/people/permissions#module-auto_anchors).