Check to make sure there is a toc_token before trying to use it. Fixes #1047

This commit is contained in:
Parker Moore 2013-05-07 18:12:47 +02:00
parent 81fea5ae22
commit 1d2f172d6b
1 changed files with 11 additions and 2 deletions

View File

@ -15,11 +15,20 @@ module Jekyll
def convert(content)
rd = RDiscount.new(content, *@rdiscount_extensions)
html = rd.to_html
if rd.generate_toc and html.include?(@config['rdiscount']['toc_token'])
html.gsub!(@config['rdiscount']['toc_token'], rd.toc_content.force_encoding('utf-8'))
if @config['rdiscount']['toc_token']
html = replace_generated_toc(rd, html, @config['rdiscount']['toc_token'])
end
html
end
private
def replace_generated_toc(rd, html, toc_token)
if rd.generate_toc && html.include?(toc_token)
html.gsub(toc_token, rd.toc_content.force_encoding('utf-8'))
else
html
end
end
end
end
end