Skip to content

Commit

Permalink
Fix table of content anchor bug - #97
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBarranqueiro committed Oct 2, 2015
1 parent 835c990 commit 4ce8764
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions layout/_partial/post.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
var postContent = post.content;
// Generate and insert table of contents in post content
if ((/<!--(\s*)[t|T][o|O][c|C](\s*)-->/).test(post.content)) {
if ((/<!--(\s*)[t|T][o|O][c|C](\s*)-->/).test(postContent)) {
if (__('post.toc_title')) {
tableOfContents = '<h1 id=\"table-of-contents\">' + __('post.toc') + '</h1>';
} else {
tableOfContents = '<span id="table-of-contents"></span>';
}
tableOfContents += toc(post.content, {list_number: false})
post.content = post.content.replace(/<!--(\s*)[t|T][o|O][c|C](\s*)-->/, tableOfContents)
tableOfContents += toc(postContent, {list_number: false})
postContent = postContent.replace(/<!--(\s*)[t|T][o|O][c|C](\s*)-->/, tableOfContents)
}
// Replace `<!-- endcontent -->` by `</div>` and `<!-- content -->` by `</div class="main-content-wrap">`
// it's an hack to insert html tag without
// having auto delete or auto closed by the markdown render engine
// Currently used to insert an image in full width, out of `main-content-wrap` div
// which center the content and have a limited width (750px)
post.content = post.content.replace(/<!-- ?endcontent ?-->/g, '</div>')
postContent = postContent.replace(/<!-- ?endcontent ?-->/g, '</div>')
.replace(/<!-- ?content ?-->/g, '<div class="main-content-wrap">');
%>
<article class="post" itemscope itemType="http://schema.org/BlogPosting">
Expand All @@ -29,7 +29,7 @@
<% } %>
<div class="post-content markdown" itemprop="articleBody">
<div class="main-content-wrap">
<%- post.content %>
<%- postContent %>
<% if (theme.image_gallery) { %>
<%- partial('post/gallery', {photos: post.photos})%>
<% } %>
Expand All @@ -42,7 +42,7 @@
<%- partial('post/tag', {tags: post.tags})%>
</div>
<% } %>
<%- partial('post/actions') %>
<%- partial('post/actions', {postContent: postContent}) %>
<% if (post.comments && theme.disqus_shortname) { %>
<%- partial('post/disqus') %>
<% } %>
Expand Down

0 comments on commit 4ce8764

Please sign in to comment.