如何将redcloth与coderay集成

发布于 2024-12-17 20:46:05 字数 328 浏览 8 评论 0原文

我想将语法突出显示与红布一起使用。

Coderay的描述是这样的:

针对选定语言的快速、简单的语法突出显示,以 红宝石。配有 RedCloth 集成和 LOC 计数器。 1

但我没有找到有关如何执行此操作的文档?

我应该在哪里放置代码来进行突出显示?我考虑过将其放入 module ApplicationHelper 这是一个好主意吗?

I want to use syntax highlighting along with redcloth.

The description of coderay says:

Fast and easy syntax highlighting for selected languages, written in
Ruby. Comes with RedCloth integration and LOC counter. 1

But I did not find a documentation about how to do this?

Where should I put the code to do the hightlighting? I thought about putting it into module ApplicationHelper is this a good idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄离 2024-12-24 20:46:05

选项 1:

简单如下:http://railscasts .com/episodes/207-syntax-highlighting?autoplay=true
使用 Rails3 时,将助手更改为:

  def coderay(text) 
    text.gsub!(/\<code(?: lang="(.+?)")?\>(.+?)\<\/code\>/m) do 
      code = CodeRay.scan($2, $1).div(:css => :class) 
      "<notextile>#{code}</notextile>" 
    end 
    return text.html_safe 
  end

如果您使用 HAML,您将需要使用 ~ 符号:

~ raw textilize(coderay(...))

选项 2:

CodeRay 内置了对 RedCloth 的支持。

  1. 将所需的 gem 文件添加到您的 Gemfile 中。
宝石“红布”,:require => ‘红布’
gem 'coderay', :require =>; ['coderay', 'coderay/for_redcloth']
  1. 像使用 RedCloth 一样渲染代码字符串(~ 而不是 =,因为我使用 HAML)。
~ raw textilize(“这里的一些代码@应该@被格式化。”)
~ raw textilize(“这里的一些代码@[ruby]应该被格式化。”)
  1. 您还可以渲染文件。
# 文件位于 /my/file/path/filename.doc
h1。我的头衔 
bc[ruby].. # Nekaj za napisat 
def self.myfun   
把“阿斯达斯” 
结尾

# 在你的视图文件中
~ raw textilize(File.read("/my/file/path/filename.doc"))

我更喜欢第二种选择。

您可以在 http://en.wikipedia.org/ 找到有关使用 Textile 标记语言进行样式设置的更多信息。 wiki/Textile_(markup_language)

OPTION 1:

Simpe as this: http://railscasts.com/episodes/207-syntax-highlighting?autoplay=true
When using rails3 change helper to this:

  def coderay(text) 
    text.gsub!(/\<code(?: lang="(.+?)")?\>(.+?)\<\/code\>/m) do 
      code = CodeRay.scan($2, $1).div(:css => :class) 
      "<notextile>#{code}</notextile>" 
    end 
    return text.html_safe 
  end

If you use HAML you will want to use ~ sign:

~ raw textilize(coderay(...))

OPTION 2:

CodeRay has built-in support for RedCloth.

  1. Add required gem files into your Gemfile.
gem "RedCloth", :require => 'redcloth'
gem 'coderay', :require => ['coderay', 'coderay/for_redcloth']
  1. Render the code string like you would do it with RedCloth (~ instead of = because I using HAML).
~ raw textilize("Some code here @that should@ be formated.")
~ raw textilize("Some code here @[ruby]that should@ be formated.")
  1. You can also render a file.
# File at /my/file/path/filename.doc
h1. My title 
bc[ruby].. # Nekaj za napisat 
def self.myfun   
puts "asdas" 
end

# Inside your view file
~ raw textilize(File.read("/my/file/path/filename.doc"))

I prefere the second option.

You can find more about styling with Textile markup language at http://en.wikipedia.org/wiki/Textile_(markup_language)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文