coderay

Syntax highlighting with CodeRay and Markdown (RDiscount) in a Rails 3 application

会有一股神秘感。 提交于 2019-12-06 05:09:23
问题 I'm trying to add some syntax highlighting to my blog that currently uses RDiscount. I am converting the Markdown to HTML with RDiscount then parsing the HTML code blocks with CodeRay to add syntax highlighting. This is what I have so far: class Post < ActiveRecord::Base before_save :render_body def render_body self.rendered_body = coderay(markdown(self.body)) end def markdown(text) RDiscount.new(text).to_html end def coderay(text) text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do

Syntax highlighting with CodeRay and Markdown (RDiscount) in a Rails 3 application

拟墨画扇 提交于 2019-12-04 10:15:30
I'm trying to add some syntax highlighting to my blog that currently uses RDiscount. I am converting the Markdown to HTML with RDiscount then parsing the HTML code blocks with CodeRay to add syntax highlighting. This is what I have so far: class Post < ActiveRecord::Base before_save :render_body def render_body self.rendered_body = coderay(markdown(self.body)) end def markdown(text) RDiscount.new(text).to_html end def coderay(text) text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do CodeRay.scan($3, $2).div(:css => :class) end end end And in my view: <%= raw @post.rendered_body %> Using