• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
RubyでMarkdown記法というと、BlueClothが有名なのではないかと思いますが、rdiscountとrpeg_markdownという新しいライブラリが Daring Fireball氏のこちらの記事で紹介されていました。 [**Better Markdown Libraries for Ruby: RDiscount and rpeg-markdown**](http://mac.blogdig.net/archives/articles/August2008/17/Better_Markdown_Libraries_for_Ruby__RDiscount_and_rpeg_markdown.html) >Ryan Tomayko has solved this with two new Ruby extensions that wrap extremely fast (and accurate) C libraries for Markdown: David Loren Parsons’s Discount and Jon MacFarleane’s peg-markdown. 早速 [Formula](http://formula.s21g.com/) で使ってみようと検証していたのですが、上述の二つのライブラリには、 エスケープの仕方でMARKDOWN記法の解釈に以下のような違いがあるようです。 ruby>> source = "[test](http://foo.com/?x%3Dx%2B5%2B2y)" RDiscount.new(source).to_html #=> "

test

\n" Markdown.new(source).to_html # rpeg-markdown #=> "\n\n

test

" <<-- RDiscountの方は、エスケープ済みのQuery Stringをもう一回エスケープしてしまっているようです。
posted by genki genki on Mon 18 Aug 2008 at 23:23 with 2 comments

Maruku
は、Rubyで実装された高機能なMARKDOWN記法のインタプリタです。
RubyでMARKDOWNといえば、BlueClothがお馴染みですが、
Marukuは数式のサポートやPDF出力なども実装されており、
より高機能なものとなっているようです。

ところで、Marukuを使っていてImmediate Link記法
<http://~~>
が、httpsで始まるURLの場合にうまく動作しないようだったので、
任意のスキームを扱えるように拡張する方法を紹介します。

ruby>>
module MaRuKu
module Strings
def line_md_type_with_arbitrary_schemes(l)
return :text if l =~ /^<[a-z]+:\S+?>/
line_md_type_without_arbitrary_schemes(l)
end
alias_method_chain :line_md_type, :arbitrary_schemes
end
end
<<--

上記のように、line_md_typeを拡張すればOKです。

Marukuを紹介するプレゼン資料を見つけたので紹介します。

posted by genki genki on Fri 15 Feb 2008 at 01:39 with 0 comments