Skip to content

Commit

Permalink
Nest jump links in children for elements that shouldn't contain them …
Browse files Browse the repository at this point in the history
…directly

Also generate links for definition lists and exercise part labels.

Closes #19, fixes #20, and closes #21.
  • Loading branch information
maxg committed Jul 23, 2018
1 parent 7887a72 commit 60f7384
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions web/handout/handout-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,13 @@ function convertExercise(container, category, heading, content) {
}

function identifyChunks(dense) {
var jumpable = 'h1, h2, h3, h4, h5, h6, .panel-heading' + (dense ? ', p, pre, ol>li:first-child, ul>li:first-child, table' : '');
var jumpable = 'h1, h2, h3, h4, h5, h6, .panel-heading' + (dense ? ', p, pre, ol:not(li ol), ul:not(li ul), dl, table, .exercise-part-heading' : '');
var exclude = '.exercise-explain *, .faq h3 + div > p:first-child';
var nest = {
'ol, ul': 'li',
'dl': 'dt',
'table': 'th, td',
};
var elements = $(jumpable).not(':has(' + jumpable + ')').not(exclude);
var chunks = {};
var stopwords = [
Expand Down Expand Up @@ -515,8 +520,15 @@ function identifyChunks(dense) {
});
}
})([], chunks);
elements.filter('[id]').prepend(function() {
return $('<a>').addClass('jump').attr('href', '#' + this.id);
elements.filter('[id]').each(function(idx, elt) {
var parent = $(elt);
$.each(nest, function(outer, inner) {
if (parent.is(outer)) {
parent = $(inner, parent).first();
return false;
}
});
parent.prepend($('<a>').addClass('jump').attr('href', '#' + elt.id));
});
}

Expand Down

0 comments on commit 60f7384

Please sign in to comment.