10/21/2006

Syntax Highlight 套件

我在這個 Blog 寫的程式碼都是用 nopaste 這個網站幫我轉的,他會自動幫我 Syntax Highlight,實在很方便,不過我最近發現到 JAVAEye 有一個很棒的功能,當你在論壇發表文章,文章裡面放上程式碼的時候,如果你用 [code] [/code] 將他包起來。他會自動幫你作 Syntax Highlight。大家都知道 JavaEye是 Ruby on Rails 作的,那他是怎麼做到的呢?我發現到也有人跟我有一樣的問題,有人的回答是『有一个叫Syntax的lib』。我上網找到 syntax 的官方網站,並且測試一下,發現到他的 Syntax Highlight 是CSS class 包起來的
 <span class="keyword">yield</span>
需要自己寫 CSS Class 才可以成功顯示顏色,並且縮排有問題。既然這樣的話,有沒有可能 JavaEye 是另外一個套件呢?又花點時間 survey到 CodeRay 這個套件,一經適用,發現到他產生的 HTML 是呈現
<span style="color:#080; font-weight:bold">case</span>
因為是直接把顏色包入 tag 之中,所以不需 CSS 就可以直接顯示了。很不幸的,CodeRay 的縮排還是有問題,會呈現這樣的慘狀
! /usr/bin/ruby

when 'Net::HTTPServiceUnavailable'
puts now+ ' '+res.class.to_s
when 'Net::HTTPMethodNotAllowed'
puts now+ ' '+res.class.to_s
else
puts now + ' '+res.class.to_s
end

真是夠慘的,是我那裡使用錯誤嗎?有人知道嗎?

以下是我目前試出來的用法。

Syntax :
安裝 : gem i syntax
使用方式:
require 'syntax/convertors/html'

convertor
= Syntax::Convertors::HTML.for_syntax "ruby"
html
= convertor.convert( File.read( "program.rb" ) )

puts html
CodeRay :
安裝:gem i coderay
使用方式:
require 'coderay'
print CodeRay.scan(File.read('ruby.rb'), :ruby).div
PS. typo 有 CodeRay 的套件,可以到這裡看看怎麼安裝

13 則留言:

匿名 提到...

[url=http://nintendo-wii-cheap.com/deals/Wii+Console+Wii+Fit+Bundle/]Wii+Console+Wii+Fit+Bundle[/url]. Super Mario Galaxy 2, Naruto Shippuden CoNR 3, How To Train Your Dragon, Super Monkey Ball: Step And Roll, Excitebots: Trick Racing, Virtua Tennis 2009, Game Party 3.

匿名 提到...

It’s really a nice and helpful piece of information. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing.

匿名 提到...

Hopefully, this area should be the proper place to submit this... I simply just hoped to make it easy for anybody inside the forum who lives in Down Under know about a fabulous top of the range audio visual equipment world-wide-web site labeled as Ordio. I found them quite by accident when I was shopping around for [url=http://www.ordio.com.au]Sennheiser Headphones[/url] and it just so happened that these people had the cheapest prices around. Not only that but they are extraordinarily helpful and even followed up on my expenditure to ensure I was still completely happy. They buy out considerable inventories of high end audio visual equipment so that they can honestly break the price down. Most certainly visit their site if you're watching for some home electronics.

Dan

匿名 提到...

"Staropolskim obyczajem,
gdy w Wigilię gwiazda wstaje,
Nowy Rok zaś cyfrę zmienia,
wszyscy wszystkim ślą życzenia.
Przy tej pięknej sposobności
i ja życzę Wam radości,
aby wszystkim się darzyło,
z roku na rok lepiej było."

[url=http://www.karty-swiateczne.com]kartki świąteczne[/url] - kartki świąteczne
NIECH MIKOŁAJ PRZYNIESIE CI PEŁEN WOREK SZCZĘŚCIA I POCIECHY DLA SERCA!

- Żyj z rodziną i przyjaciółmi w zgodzie i pogódź się z nimi nawet jeśli to niemożliwe!

CZAS ŚWIĄT TO OKRES WIARY, NADZIEI, POJEDNANIA I WYBACZANIA!

Niech nadchodzące święta, pełne rodzinnego ciepła i odpoczynku, napełnią Was prawdziwą radością i pokojem. Niech będzie to dla Was chwila wytchnienia od codzienności, chwila refleksji i dobrej nowiny, która wyzwoli to, co najlepsze i da siły do podejmowania nowych zadań na cały zbliżający się nowy rok

匿名 提到...

Just want to say your article is striking. The clarity in your post is simply striking and i can take for granted you are an expert on this subject. Well with your permission allow me to grab your rss feed to keep up to date with forthcoming post. Thanks a million and please keep up the ac complished work. Excuse my poor English. English is not my mother tongue. Martin , auto insurance california

匿名 提到...

taylor swift nude fakes pics taylor swift free nude fakes

匿名 提到...

finasteride erectile dysfunction dilantin iv vs dilantin po famotidine dosing atarax pa80 complications of celexa aceon replacement testosterone sex patch purchase hair loss cream online adelle allegra compounding aristocort what organisms does augmentin kill a href cheap imodium darvocet and maxalt kamasutra contoured condoms where to buy how often can prednisone be taken hytrin use in women singulair sidekick avapro 300 mg anxiety celexa social flonase buy uk trazodone and heroin withdrawal lexapro and gabba caffeine antioxidant benefits of coffee tea brand cialis online

add-vantage vial diltiazem [url=http://alluringacademi.pbworks.com/]define chloroquine[/url] lamisil allergic reactions [url=http://literatetransla.pbworks.com/]abilify and stevens-johnson syndrome[/url] zocor clinical trials [url=http://torpidsanity26.pbworks.com/]buy cod glyset[/url] side effects for omeprazole [url=http://pumpedpregnancy.pbworks.com/]altace perscripion[/url] lithium patch [url=http://punytorpor37.pbworks.com/]when does carafate tablets expire[/url] ranitidine liquid dosage [url=http://boorishlesion18.pbworks.com/]double concentrated furosemide infusion[/url] buy viagra in malaysia [url=http://pointlesstariff.pbworks.com/]imuran and pancytopenia[/url] decadron dosage for brain tumor [url=http://juvenilepoker40.pbworks.com/]what does cymbalta feel like[/url] combination of wellbutrin and paxil [url=http://whisperingranch.pbworks.com/]articoli sul bactrim[/url] samini bromocriptine indomethacine rat [url=http://scandalousradio.pbworks.com/]antibiogram of cefixime in salmonella[/url]

匿名 提到...

I'm really Glad i ran across this blog.Added lightyror.thegiive.net to my bookmark!

匿名 提到...

I'm really Glad i ran across this blog.Added lightyror.thegiive.net to my bookmark!

匿名 提到...

A only one days ago, we analyzed the 2010 day-dream baseball pitcher sleepers to timepiece in 2010. Today, we assess as a look at the more important side of the equation - pretence baseball hitters sleepers.
[url=http://www.communitywalk.com/user/view/180828 ]Jack[/url]

匿名 提到...

Greetings Web site owner! Are trying proclaim that we as if your internet page rather a lot.
[url=http://www.businesscreditcardv.com]business credit card[/url] [url=http://www.businesscreditcardv.com/apply-for-business-credit-card]apply for business credit card[/url] business credit card airline mile [url=http://www.calendartemplatev.com]calendar template[/url] [url=http://www.calendartemplatev.com/yearly-calendar-template]yearly calendar template[/url] 2011 calendar template holidays [url=http://www.carbatteryv.com]car battery[/url] [url=http://www.carbatteryv.com/car-battery-sizes]car battery sizes[/url] car battery not starting [url=http://www.digitalphotoframev.com]digital photo frame[/url] [url=http://www.digitalphotoframev.com/phillips-digital-photo-frame]phillips digital photo frame[/url] digital photo frame internal memory [url=http://www.fitnessgymv.com]fitness gym[/url] [url=http://www.fitnessgymv.com/pure-fitness-gym]pure fitness gym[/url] fitness gym wear [url=http://www.greenhomev.com/]green home[/url] [url=http://www.greenhomev.com/green-home-solutions]green home solutions[/url] fitness gym arizona [url=http://www.hairremovalv.com]hair removal[/url] [url=http://www.hairremovalv.com/hair-removal-cream]hair removal cream[/url] no no hair removal reviews [url=http://www.homemadepizzav.com]homemade pizza[/url] [url=http://www.homemadepizzav.com/healthy-homemade-pizza]healthy homemade pizza[/url] home made pizza pops [url=http://www.horsetrailersv.com]horse trailers[/url] [url=http://www.horsetrailersv.com/sundowner-horse-trailers]sundowner horse trailers[/url] horse trailers sundowner [url=http://www.hybridbikev.com]hybrid bike[/url] [url=http://www.hybridbikev.com/schwinn-hybrid-bikes]schwinn hybrid bikes[/url] best hybrid bike australia [url=http://www.itunesv.org]itunes[/url] [url=http://www.itunesv.org/itunes-store]itunes store[/url] itunes link maker [url=http://www.kneepainv.com]knee pain[/url] [url=http://www.kneepainv.com/sharp-knee-pain]sharp knee pain[/url] knee pain even lying down [url=http://www.lavenderplantsv.com]lavender plants[/url] [url=http://www.lavenderplantsv.com/white-lavender-plants]white lavender plants[/url] lavender plants cats [url=http://www.minimacv.com]mini mac[/url] [url=http://www.minimacv.com/mini-mac-11]mini mac 11[/url] mini mac hdmi [url=http://www.moneytreev.com]money treev[/url] [url=http://www.moneytreev.com/money-tree-gift]money tree gift[/url] money tree house plant [url=http://www.organicvegetablev.com]organic vegetable[/url] [url=http://www.organicvegetablev.com/organic-vegetable-plants]organic vegetable plants[/url] organic vegetable herb seeds [url=http://www.paintballgunv.com]paintball gun[/url] [url=http://www.paintballgunv.com/cheap-paintball-guns]cheap paintball guns[/url] paintball gun regulators [url=http://www.pontoonboatsv.com]pontoon boats[/url] [url=http://www.pontoonboatsv.com/small-pontoon-boats]small pontoon boats[/url] pontoon boats georgia [url=http://www.projectmanagementv.com]project management[/url] [url=http://www.projectmanagementv.com/project-management-courses]project management courses[/url] project management 42 processes [url=http://www.ps3gamesv.com]ps3 games[/url] [url=http://www.ps3gamesv.com/top-ps3-games-for-2010]top ps3 games for 2010[/url] ps3 games cheap [url=http://www.thyroidproblemv.com]thyroid problem[/url] [url=http://www.thyroidproblemv.com/treatment-for-thyroid-problem]treatment for thyroid problem[/url] thyroid problems and hives [url=http://www.turnkeywebsitev.com]turnkey website[/url] [url=http://www.turnkeywebsitev.com/turnkey-website-scripts]turnkey website scripts[/url] turnkey website reseller program [url=http://www.vitamindv.com]vitamin d[/url] [url=http://www.vitamindv.com/vitamin-d-deficiency-symptoms]vitamin d deficiency symptoms[/url] vitamin d kidney failure

匿名 提到...

Hello do you watch http://pulse.yahoo.com/_OBFIBSSBGTZIRBQBEXN3FFO2I4/blog/articles/19310 Kim Kardashian orgasm scene download, or http://pulse.yahoo.com/_OBFIBSSBGTZIRBQBEXN3FFO2I4/blog/articles/19311 anne hathaway films, and http://kimkardashiansextape1.typepad.com Kim Kardashian fucking cock, and http://pulse.yahoo.com/_OBFIBSSBGTZIRBQBEXN3FFO2I4/blog/articles/19313 jessica biel lesbian photos, pic

匿名 提到...

[url=http://www.tadalafil.sitew.com/]tadalafil alternative[/url]
tadalafil super active