summaryrefslogtreecommitdiffstats
path: root/lib/output/modifiers/addHeadingId.js
blob: e2e27200df5e74c92f4be66d5e955614b5518705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var slug = require('github-slugid');
var editHTMLElement = require('./editHTMLElement');

/**
    Add ID to an heading

    @param {HTMLElement} heading
*/
function addId(heading) {
    if (heading.attr('id')) return;
    heading.attr('id', slug(heading.text()));
}

/**
    Add ID to all headings

    @param {HTMLDom} $
*/
function addHeadingId($) {
    return editHTMLElement($, 'h1,h2,h3,h4,h5,h6', addId);
}

module.exports = addHeadingId;