- 2008-09-05 (金) 22:00
- JavaScript
追記(2009-02-14): v2.0でこのバグは改善されていました。
先日「Google Chrome」ベータ版がリリースされましたね。私もV8のパフォーマンス興味に試してみたら速すぎて笑っちゃいました。ただ同時に、閲覧情報のプライバシーや利用規約の内容等が結構物議を醸していますね。
まぁ前置きはこれくらいにして、そのChromeで自分のサイトの記事を読み込んだところSyntaxHighlighter(v1.5.1)がPythonのソースコードでのみ機能しませんでした。そして同様の問題はSafariでもみられました(どちらもWebKitを使っているからか)。デバッグしてみたらshBrushPython.jsコードのエラーでしたので、該当部分を以下のように修正しました。
ファイル10行目の中ほどの、
RegExp("'(?!')*(?:\\.|(\\\\\\')
の部分を、
RegExp("'(?!')(?:\\.|(\\\\\\')
に変更します。「*」を削除するだけです。
引用:Issue 52 - syntaxhighlighter - Google Code
Agreed, Python brush is 100% broken in all WebKit browsers. The issue is: SyntaxError: Invalid regular expression: nothing to repeat
file:///C:/Documents%20and%20Settings/fraser/Desktop/html/dp.SyntaxHighlighter/js/shBrushPython.js
(line 15)
It is line 10 in the compressed version and line 15 in the uncompressed version. The offending line is:
{ regex: new RegExp("'(?!')*(?:\\.|(\\\\\\')|[^\\''\\n\\r])*'", 'gm'), css:
'string' },
Doesn't matter what the Python input is.Confirming that the alternative shBrushPython.js in comment 1 works great.
As for the bug in the original regex, it boils down to RegExp("(?!x)*y") which is a negative look-ahead assertion. But neither I nor WebKit can figure out what the * is for. Deleting the * solves the problem and makes Python render fine.
Thanks, Neil and Guyon.
これでSafariとChromeでもハイライトされたPythonのソースコードを読むことが出来ます。試しに→Python: SQLiteにデータを格納、検索、出力 - pysqlite等どうぞー。
関連記事
- サイトメンテナンスのお知らせ - 日→英翻訳スクリプト
- Yahoo!検索 サイトエクスプローラー を利用するブックマークレット
- JavaのソースコードからUMLのクラス図を作成
- NetBeans から Subversion でコミットをする際のエラーの解決法の一例
- 携帯の迷惑メールフィルタのホワイトリスト(ドメイン)設定例
- Newer: Python: テキストファイルに書き込み - write()、writelines()メソッド
- Older: Rで統計: *.Rソースファイルの読み込みと実行 - source()関数
Comments:0
Trackbacks:0
- Trackback URL for this entry
- http://www.yukun.info/blog/2008/09/safari-webkit-python-syntaxhighlighter-issue.html/trackback
- Listed below are links to weblogs that reference
- SafariとChromeでSyntaxHighlighterのPythonコードがハイライトされない問題の解決法 from Yukun's Blog