ruby Jekyll为Marked.app渲染

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Jekyll为Marked.app渲染相关的知识,希望对你有一定的参考价值。

#!/usr/bin/ruby
#  Github-flavored markdown to HTML, in a command-line util.
#
#  $ cat README.md | ./ghmarkdown.rb
#
#  Notes:
#
#  You will need to install Pygments for syntax coloring
#
#    $ pip install pygments
#
#  Install the gems rdiscount, albino, and nokogiri
#
#  To work with http://markedapp.com/ I also had to
#    $ sudo ln -s /usr/local/bin/pygmentize /usr/bin
#

require 'rubygems'
require 'rdiscount'
require 'albino'
require 'nokogiri'
require 'enumerator'

def markdown(text)
  options = [:smart,]
  text.gsub!(/---(.*)---/m, '')
  # Replace {% highlight lang [linenos] %}<data>{% endhighlight %} with colourised code.
  text.gsub!(/\{\{( *)?"(.*?)"\}\}/, '\1\2')
  text.gsub!(/^\{% highlight (.+?) (linenos)? ?%\}(.*?)^\{% endhighlight %\}/m) do |match|
    data = Albino.colorize($3, $1).to_s
    if $2
      pre, data, post = data.split(/<.?pre>/)
      # data.gsub!(/^(.+)/, '<span class="lineno">#</span>\1')
      data = data.split(/\n/)
      data = data.each_with_index.map do |line, index|
        "<span class='lineno'>#{index + 1}</span>#{line}\n"
      end
      data = "#{pre}<pre>#{data}</pre>#{post}"
    end
    data
  end
  RDiscount.new(text, *options).to_html
end

puts markdown(ARGF.read)

以上是关于ruby Jekyll为Marked.app渲染的主要内容,如果未能解决你的问题,请参考以下文章

ruby Jekyll模板中的环境变量

ruby 中等喜欢Jekyll的阅读时间

ruby Jekyll标记云/标签页插件

ruby Jekyll的灵活,对数分布,标签云。

ruby Jekyll Lightbox图像插件

ruby Jekyll HTML压缩