ラベル プログラミング の投稿を表示しています。 すべての投稿を表示
ラベル プログラミング の投稿を表示しています。 すべての投稿を表示

2007年11月23日金曜日

選択した文字列をURLエンコード/デコードするBookmarklet b

コメントをURLエンコードで書いてる人がいたので,簡単に読むためにてきとーに作成


選択文字列をURLエンコードするBookmarklet

javascript:(function(){var d=document,w=window,ds=d.selection,ws=w.selection,wg=w.getSelection;t=((ds?ds.createRange().text:ws?ws.createRange().text:wg?wg():d.getSelection?d.getSelection():'')+'');prompt('encode selected text.', encodeURI(t))})();


選択文字列をURLデコードするBookmarklet
javascript:(function(){var d=document,w=window,ds=d.selection,ws=w.selection,wg=w.getSelection;t=((ds?ds.createRange().text:ws?ws.createRange().text:wg?wg():d.getSelection?d.getSelection():'')+'');prompt('decode selected text.', decodeURI(t))})();


どう作ったらすっきりするかなぁ

2007年6月4日月曜日

google-code-prettifyを使ってみた b

はてなにはシンタックスハイライト機能があっていいなーと思ってたけれど,
GoogleがJavascriptで動作するシンタックスハイライトスクリプトを作成していた.
google-code-prettify といスクリプト.
早速導入してみた.


The lexer should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles. It works passably on Ruby, PHP and Awk and a decent subset of Perl, but, because of commenting conventions, doesn't work on Smalltalk, Lisp-like, or CAML-like languages.

説明書によると
C,Java,Python,Bash,SQL,HTML,XML,CSS,Javascript,Makefile対応で,Ruby,PHP,Awk,Perlも大まかには対応しているらしい.Smalltalk,Lisp,CAMLは無理みたい.そして実際の使い方だが,


Usage:
1) include this source file in an html page via
<script src="/path/to/prettify.js" type="text/javascript"></script>
2) define style rules. See the example page for examples.
3) mark the <pre> and <code> tags in your source with class=prettyprint.
You can also use the (html deprecated) <xmp> tag, but the pretty printer
needs to do more substantial DOM manipulations to support that, so some
css styles may not be preserved.


prettify.css
prettify.js
の二つのファイルからなっており,これをどこかに設置して以下のように読み込ませればよい.
<link href="prettify.cssのパス" rel="stylesheet" type="text/css/">
<script src="prettify.jsのパス" type="text/javascript></script>

そして<pre>タグもしくは<code>タグにclass=prettyprintをつけて使えばよいみたい.

動かないじゃんと思ったら,WEBページの方のREADMEに
Add onload="prettyPrint()" to your document's body tag.
と書いてあった.忘れずに追加.
<body onload="prettyPrint()">