I am aware there is a Railscast and ASCIIcast for using Textile (RedCloth) with CodeRay, and the way it is done is by a helper:
module ApplicationHelper
def coderay(text)
text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do
CodeRay.scan($3, $2).div(:css => :class)
end
end
end
and
<%= textilize(coderay(@article.content)) %>
so the assumption is that the @article.content already has <code> and </code> wrapped around (so that CodeRay can work)...
but what if it is Markdown, then the "4 space indentation", like on StackOverflow, will first need to be converted to <code> and </code> format first.
So in this case, seems like we can use
<%= coderay(Markdown.new(@article.content).to_html).html_safe #html_safe for Rails 3 %>
so it first gets the <code> and </code> format for CodeRay to use, and then just basically substitute /<code>.*?</code>/m with the CodeRay results.
Is this a proper way to do it? But if what we actually have <code> and </code> on the "4 space indented" code, then it will actually choke this processing, because now there is nested <code>, so the first <code> will get matched, skipping the second <code> as just content for CodeRay, and then match the first </code> and leave the second </code> dangling there unprocessed. How can this be done -- maybe CodeRay has some Markdown options?