SafariとChromeでSyntaxHighlighterのPythonコードがハイライトされない問題の解決法
追記(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等どうぞー。
