Generate id attributes for HTML block elements


Generate id attributes for HTML block elements.

var identify = require('identify');
var html = "<h1>The Wizard of Oz</h1><p>The morning after the balloon</p>";
// <h1 id="the-wizard-of-oz">The Wizard of Oz</h1><p id="the-morning-after">The morning after the balloon</p> 

For a more complete example, see gh-pages/example, e.g. deep-linking to the first blockquote.

npm install identify

Pass an extra object to identify() to set options. The defaults are:

  block_elements: block_elements,
  anchor: false
  • block_elements: a list of elements to add id attributes to. Defaults to all HTML(5) block elements, as specified by the Mozilla Developer Network.

  • anchor: prepend an anchor to each element, for example:

      <h1 id="the-wizard-of-oz"><a href="#the-wizard-of-oz" class="anchor"></a>The Wizard of Oz</h1>

Copyright 2012 Tom Vincent

Released under the MIT License.