(function(document) {
function updateOutline() {
var arrAllHeader = document.querySelectorAll("h1,h2,h3,h4,h5,h6");
var arrOutline = ['
'];
var header, headerText;
var id = 0;
var level = 0,
lastLevel = 1;
var levelCount = 0;
for (var i = 0, c = arrAllHeader.length; i < c; i++) {
header = arrAllHeader[i];
headerText = header.innerText;
header.setAttribute('id', id);
level = header.tagName.match(/^h(\d)$/i)[1];
levelCount = level - lastLevel;
if (levelCount > 0) {
for (var j = 0; j < levelCount; j++) {
arrOutline.push('');
}
} else if (levelCount < 0) {
levelCount *= -1;
for (var j = 0; j < levelCount; j++) {
arrOutline.push('
');
}
};
arrOutline.push('- ');
arrOutline.push('' + headerText + '');
arrOutline.push('
');
lastLevel = level;
id++;
}
arrOutline.push('
')
var outline = document.getElementById('markdown-outline');
if(arrOutline.length > 2){
outline.innerHTML = arrOutline.join('');
showOutline();
}
else outline.style.display = 'none';
}
function showOutline() {
var outline = document.getElementById('markdown-outline');
var markdownContainer = document.getElementById('markdown-container');
outline.style.left = markdownContainer.offsetLeft + markdownContainer.offsetWidth + 10 + 'px';
outline.style.maxHeight = document.body.clientHeight - 30;
outline.style.display = 'block';
}
updateOutline();
}(document));