diff --git a/lib/main/build-site.js b/lib/main/build-site.js index 72ee89f84..e2bf63665 100644 --- a/lib/main/build-site.js +++ b/lib/main/build-site.js @@ -33,10 +33,16 @@ function build(type) { $a.replaceWith($a.html()); }); - // Fix marky-markdown wrapping of sibling anchors. - $('h3 ~ a').each(function() { - var $a = $(this); - $a.nextAll('p').first().append($a); + // Fix marky-markdown wrapping around headers. + $('p:empty + h3').prev().remove(); + + $('h3 ~ p:empty').each(function() { + var $p = $(this), + node = this.previousSibling; + + while ((node = node.previousSibling) && node.name != 'h3' && node.name != 'p') { + $p.prepend(node.nextSibling); + } }); // Append YAML front matter.