updated pygments output to wrap code blocks with <code> tags

This commit is contained in:
Patrick Crowley 2009-10-22 21:14:05 -07:00
parent 2f2e45bedf
commit 4cc0873172
2 changed files with 12 additions and 5 deletions

View File

@ -31,11 +31,11 @@ module Jekyll
def render_pygments(context, code) def render_pygments(context, code)
if context["content_type"] == "markdown" if context["content_type"] == "markdown"
return "\n" + Albino.new(code, @lang).to_s(@options) + "\n" return "\n" + add_code_tags(Albino.new(code, @lang).to_s(@options), @lang) + "\n"
elsif context["content_type"] == "textile" elsif context["content_type"] == "textile"
return "<notextile>" + Albino.new(code, @lang).to_s(@options) + "</notextile>" return "<notextile>" + add_code_tags(Albino.new(code, @lang).to_s(@options), @lang) + "</notextile>"
else else
return Albino.new(code, @lang).to_s(@options) return add_code_tags(Albino.new(code, @lang).to_s(@options), @lang)
end end
end end
@ -49,6 +49,13 @@ module Jekyll
</div> </div>
HTML HTML
end end
def add_code_tags(code, lang)
# Add nested <code> tags to code blocks
code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
code = code.sub(/<\/pre>/,"</code></pre>")
end
end end
end end

View File

@ -49,7 +49,7 @@ CONTENT
end end
should "render markdown with pygments line handling" do should "render markdown with pygments line handling" do
assert_match %{<pre>test\n</pre>}, @result assert_match %{<pre><code class='text'>test\n</code></pre>}, @result
end end
end end
@ -59,7 +59,7 @@ CONTENT
end end
should "render markdown with pygments line handling" do should "render markdown with pygments line handling" do
assert_match %{<pre>Æ\n</pre>}, @result assert_match %{<pre><code class='text'>Æ\n</code></pre>}, @result
end end
end end