summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/glossary.js
blob: 89ff13588d6ac3282a7c0cfc52f4f0707640002b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var _ = require('lodash');
var dom = require('./dom');

// HTML -> Glossary
function parseGlossary(html) {
    var $ = dom.parse(html);

    var entries = [];

    $('h2').each(function() {
        var $heading = $(this);
        var $next = $heading.next()
        var $p =  $next.is('p')? $next.first() : $next.find('p').first();

        var entry = {};

        entry.name = $heading.text();
        entry.description = $p.text();

        entries.push(entry);
    });

    return entries;
}

module.exports = parseGlossary;