From 1d2f172d6bb12a7820bf2370327ce9a9c399be87 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 7 May 2013 18:12:47 +0200 Subject: [PATCH] Check to make sure there is a toc_token before trying to use it. Fixes #1047 --- lib/jekyll/converters/markdown/rdiscount_parser.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/converters/markdown/rdiscount_parser.rb b/lib/jekyll/converters/markdown/rdiscount_parser.rb index 87b09831..ca868d7a 100644 --- a/lib/jekyll/converters/markdown/rdiscount_parser.rb +++ b/lib/jekyll/converters/markdown/rdiscount_parser.rb @@ -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