SyntaxHighlighterテスト

2010/04/23

HTML版用に、SyntaxHighlighterを使ってみた。

SyntaxHighlighter 2.0 -ソースコードを素敵に表示するを参考

こういうのは、Ajaxはすごい便利だ。 Flash10.0系のhtmlTextだと、できないだろうからなぁ。 てか、wonderflでソースのswf表示してるやつあるから、それを調査すればいいか。

■準備 (1) SyntaxHighlighterパッケージを任意に配置 (2) HTMLで、JavaScriptとCSSのパスを通す(shCore.js、shCore.cssは必須) (3) SyntaxHighlighter.all();

こんだけ。

■ソースの記述 (1) ソースコードは「pre」タグで囲む

(2) 対応言語表記に沿って記述

as3, actionscript3, bash, cf, coldfusion, c-sharp, csharp, cpp, c, css, delphi, diff, erl, erlang, groovy, html, js, jscript, javascript, java, jfx, javafx, pas, pascal, patch, perl, pl, php, plain, ps, powershell, py, python, rails, ror, ruby, scala, shell, sql, text, vb, vbnet, xml, xhtml, xslt, xhtml

例) pre class="brush:as3;"

■ActionScript3のソースの場合 [as3] /** * Copyright 2010 * Author: Yohei Yoshikawa **/ package com.yoos.app.controllers {

import com.yoos.app.views.TwitterFriendListView;
import com.yoos.app.views.TwitterTimelineView;
import com.yoos.app.views.TwitterView;
import com.yoos.libs.PageController;
import com.yoos.libs.twitter.controllers.Twitter;

import flash.events.Event;

import mx.collections.ArrayCollection;

[Bindable]
public class TwitterController extends PageController
{
    private static var instance:TwitterController;

    public static function getInstance():TwitterController {
        if (instance == null) {
            new TwitterController();
        }
        return instance;
    }

    public function TwitterController()
    {
        if (instance == null) {
            instance = this;
        }
    }

    override public function initialized(document:Object, id:String):void
    {
        view = document as TwitterView;
    }


    //view 
    public var view:TwitterView;
    public var twitterTimelineView:TwitterTimelineView;
    public var twitterFriendListView:TwitterFriendListView;

    private var currentFuncion:Function;

    public var twitter:Twitter;

    private var topMargin:Number = 0;

    private var delay:uint = 15000;

    public var userName:String = 'xxxxxx';
    public var password:String = 'xxxxxx';

    public function onCreationComplete(event:Event):void
    {
        twitter = new Twitter();
        twitter.userName = userName;
        twitter.password = password;

        generatePages();
        pageTwitterTimeline();
    }

    public function onTimelineCreationComplete(event:Event):void
    {

    }

    private function autoLoad():void
    {
        var timer:Timer = new Timer(delay);
        timer.addEventListener(TimerEvent.TIMER, onTimer);
        timer.start();

        function onTimer(event:TimerEvent):void
        {
            if (currentFuncion != null) {
                //currentFuncion(currentParams);
            }
        }           
    }

    private function generatePages():void
    {
        baseView = view;
        baseGroup = view.container;

        twitterTimelineView = new TwitterTimelineView();
        twitterFriendListView = new TwitterFriendListView();

        addPage(twitterTimelineView);
        addPage(twitterFriendListView);
    }

    public function tweet(message:String):void
    {
        twitter.tweet(message, onComplete);

        function onComplete(event:Event):void
        {
            view.messageField.text = '';
        }
    }

    public function deleteTweet(id:Number):void
    {
        var handler:Function = onComplete;
        twitter.deleteTweet(id, onComplete);

        function onComplete(event:Event):void
        {

        }
    }

    public function retweet(id:Number):void
    {
        var handler:Function = onComplete;
        twitter.retweet(id, onComplete);

        function onComplete(event:Event):void
        {

        }
    }

    public function reply(id:Number):void
    {
        var handler:Function = onComplete;
        twitter.reply(id, onComplete);

        function onComplete(event:Event):void
        {

        }
    }

    public function pageTwitterTimeline():void
    {
        page(twitterTimelineView);
        twitter.getHomeTimeline();
    }

    public function pageTwitterFridnedList():void
    {
        page(twitterFriendListView);
        twitter.getFriends();
    }

}

} [/as3]