开发者

How to select a different theme/style for CodeRay syntax highlighting Ruby code?

开发者 https://www.devze.com 2023-02-13 23:26 出处:网络
I\'m having difficulty figuring out how to select a different theme/style for syntax highlighting of Ruby code using the CodeRay gem, the default is OK but i wonder if there\'s an开发者_如何学Cything

I'm having difficulty figuring out how to select a different theme/style for syntax highlighting of Ruby code using the CodeRay gem, the default is OK but i wonder if there's an开发者_如何学Cything else on offer? i can't seem to find them.

Thanks


It is my understanding that you generate your own coderay.css file. Coderay doesn't have "themes".


Try this:

CodeRay stylesheet

And then:

doc = Nokogiri::HTML(html)
  doc.search("//pre//code[@class]").each do |pre|
    tokens = CodeRay.scan(pre.text, pre[:class])
    pre.replace tokens.div(:css => :class)
  end

The trick is to render your tokens with a CSS class.

0

精彩评论

暂无评论...
验证码 换一张
取 消