开发者

Syntax highlighting in HAML's markdown filter

开发者 https://www.devze.com 2023-02-09 18:30 出处:网络
I\'m using HAML\'s markdown filter, like this: :markdown This is markdown text, yay! but I want to do syntax highlighting for code inside that text, something like:

I'm using HAML's markdown filter, like this:

:markdown
  This is markdown text, yay!

but I want to do syntax highlighting for code inside that text, something like:

:markdown
  This is markdown text, yay!
  <code lang="ruby">
    def 开发者_开发技巧hello(world)
      puts "Hello #{world}"
    end
  </code>

Any ideas how to do it? I know how to use CodeRay, but I don't see how to grab ahold of that text.


http://railscasts.com/episodes/272-markdown-with-redcarpet uses albino, nokogiri and pygments


Markdown does support code blocks out of the box, but does not support syntax highlighting.

see http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#markdown-filter for what markdown libraries haml looks for to parse your markdown.

If you want to pass your code to a filter that makes it highlighted you can write your own filter extension to haml. It is actually quite easy.

http://haml-lang.com/docs/yardoc/Haml/Filters/Base.html

If I were you though, I would just put the code in as a block and use a javascript library like GeSHi to highlight the code. http://qbnz.com/highlighter/index.php

So you can do something like:

  %pre.ruby 
    puts "this is now syntax highlighted"

And if you have geshi included, it now highlighted.

0

精彩评论

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

关注公众号