function toc() {
    var dest = $('#toc');
    var content = $('#content');
    if (!content || !dest.length) return;
    
    //dest.empty();

    var location = window.location.href;
    if (window.location.hash)
        location = location.substring(0, location.lastIndexOf(window.location.hash));

    var ul = $('<ul>');
    var headers = $(content).find('*').filter(function() { return /^h[1234]$/.test(this.tagName.toLowerCase()) });
    console.log(headers);
    for (var k = 0; k < headers.length; k++) {
        var elem = $(headers[k]);
        var li = $('<li>')
        li.addClass('toc-' + headers[k].tagName.toLowerCase());
        li.append($('<a />').attr('href', location + '#section-' + k).text(elem.text()));
        ul.append(li);
        elem.before($('<a name="section-' + k + '" />'));
    }; 
    dest.show();
    dest.append(ul);
};
