Personal tools

ZopeでSyntax Coloring

by ats posted at 2005-04-29 20:25 last modified 2005-10-18 23:04

クイックハックです。

ZopeのreStructuredTextでSyntax Coloringを可能にするプロダクトZSilverCityをリリースします。

http://coreblog.org/junk/ZSilverCity02.tgz

SilverCity(http://silvercity.sourceforge.net/)をインストールして使ってください。コード部分のCSSの定義はSilverCityの配布物に入っていますので,COREBlogのstyle_cssなどに追加して使ってください。また,コード部分はcode-blockというクラスのついたdivタグで囲まれます。

Python Cookbookの以下のエントリからコードを拝借しています。

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252170

reStのディレクティブ表記法に準じます。「.. code-block:: 言語セレクタ」以下に続くインデントされたブロックについてSyntax Coloringを適用します。

.. code-block:: Python

    class Singleton(type):
        """Simple Singleton from Python Cookbook"""
        def __init__(self, *args):
            type.__init__(self, *args)
            self._instances = {}
    
        def __call__(self, *args):
            if not args in self._instances:
                self._instances[args] = type.__call__(self, *args)
            return self._instances[args]

と書くと,以下のようになります。

class Singleton(type):
    
"""Simple Singleton from Python Cookbook"""
    
def __init__(self, *args):
        
type.__init__(self, *args)
        
self._instances = {}

    
def __call__(self, *args):
        
if not args in self._instances:
            
self._instances[args] = type.__call__(self, *args)
        
return self._instances[args]

SilverCityがUnicodeStringに対応していない模様で,コメントなどに日本語を使うとエラーになりますので注意してください。


SilverCity同梱のCSSより,Trac(http://www.edgewall.com/trac/)のCSSの方がイケていたので拝借してしまった。

~/htdocs/css/code.cssに定義があります。

Category(s)
zope
python
The URL to Trackback this entry is:
http://coreblog.org/ats/640/tbping

Re: ZopeでSyntax Coloring

Posted by yohgaki at 2005-04-29 23:02
Syntanx Hilightingの方が通じやすいかも。

Re: ZopeでSyntax Coloring

Posted by ats at 2005-04-30 09:52
>yohagiさん

Google先生に聞いてみると

"syntax Highlighting" -> 約 686,000 件
"syntax Coloring" -> 約 86,000 件



Plonified

Posted by Feel Fine! at 2005-10-18 23:04
COREBlogのRSS用metaタグを追加(清水川記)を参考に Feel Fine! でも Mozilla Firefox などが RSS を見つけられるようにした。 Zope で Syntax Coloring(TRIVIAL TECHNOLOGIES)もすばらしいなぁ。 reStructuredTextの書き方が解らないので手を出さなかったのだが、後でやってみよう。
Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)
(Required)
(Required)
(Required)
コメントスパム避けのための認証文字列です

Captcha Image

About this blog
■Author
atsこと柴田淳です。この記事を読んでいただくと,技術者としての人となりを分かってもらえるかも。
Webcore株式会社 代表取締役
Plone上で動く,オープンソースのBlog Product - COREBlog2を使って運用しています。

 
最近書いた本,Mook
みんなのPython 改訂版
Python使いはもちろん,プログラミングの初心者から,他言語からの移行組までご好評いただいているPythonの定番入門書の第2版です。Python 3.0を含む最新の情報について加筆を行い,より読みやすいように構成を大幅に見直しました。第一版をお持ちの方にもお役立ていただける内容になっています。
みんなのPython Webアプリ編
Pythonの基礎から,Webアプリやフレームワークの仕組みまで,つまることなく一気に学べる書籍です。「みんなのPython」と一緒に読んでください:-)。
 

Powered by Plone, the Open Source Content Management System