Bloody Mary - blog

Bloody Mary 別館

iG:Syntax Hiliter の新バージョン

iG:Syntax Hiliter Ver.4.3 へのアップグレード

WordPress のプラグイン iG:Syntax Hiliter がバージョンアップしてたので、アップグレードしてみた。

使いやすくなったけど、使えなくなった shorthand tags もあった。

iG:Syntax Hiliter アップグレード

1. DL ~ アップロードまで

http://downloads.wordpress.org/plugin/igsyntax-hiliter.zip

からファイルをダウンロードして解凍する。

igsyntax-hiliter というディレクトリができるので、 wordpress/wp-content/plugins/ に FTP か何かでアップロードする。

ちなみに、私は Ver.3.5 あたりから Ver.4.3 にアップグレードしたので、ファイルを上書きすることはない。

バージョン ファイル構成
Ver.3.5 あたり ig_syntax_hilite/
syntax_hilite.php
Ver.4.3 igsyntax-hiliter/

2. プラグインの停止

旧バージョンを停止、新バージョンを有効にする。

3. 旧ファイル群の削除

plugin/ から、以下のファイル・ディレクトリを削除する。

  • ig_syntax_hilite/
  • syntax_hilite.php

以上で新バージョンが利用できるようになったはずだ。

※ 慎重な人は古いファイルを取って置きたがるだろう。その場合、 plugin/tmp/ などのディレクトリに上記ファイルを移動させただけでは、プラグイン管理画面にしつこく旧バージョン情報が残ってしまう。ではどうするかというと plugin/tmp/tmp/ のようにして、 2 階層下のディレクトリに放り込んでやれば OK。

iG:Syntax Hiliter の使い方

いままでは

[php]
ほにゃらら
[/php]

とかやっていたものを、

[sourcecode language=”php”]
ほにゃらら
[/sourcecode]

のようにする。

shorthand tags と言って、今までどおり[php]のようにして使えるものもある。一方、[code]は今まで通り使えるが、 [CODE] のように大文字似しているものは認識しなくなった。

CODE [code]
  1. # 小文字で指定すると OK。
  2. print "Hello, World !";
CODE [CODE]

[CODE]
大文字で指定すると NG。
print “Hello, World !”;
[/CODE]

ハイライトの行数を指定できる
コード

[sourcecode language=”php” highlight=”3″]
<?php

phpinfo();

?>
[/sourcecode]

実際の表示
  1. <?php
  2.  
  3. phpinfo();
  4.  
  5. ?>

複数行をハイライト指定する場合はカンマ (,) で区切る。

ex. highlight=”1,3,5,7″

連続する行をハイライト指定する場合はハイフン (-) で。

ex. highlight=”1,3-7,13-20″

今まで使えてたと思われる shorthand tags の検証

[delphi]と[smarty]は NG だった。

ActionScript [as]
  1. # ほげ
  2. print "Hello, World !";
ASP [asp]
  1. # ほげ
  2. print "Hello, World !";
c [c]
  1. # ほげ
  2. print "Hello, World !";
c++ [cpp]
  1. # ほげ
  2. print "Hello, World !";
c# [csharp]
  1. # ほげ
  2. print "Hello, World !";
css [css]
  1. # ほげ
  2. print "Hello, World !";
CODE [code]
  1. # ほげ
  2. print "Hello, World !";
delphi [delphi]

[delphi]
# ほげ
print “Hello, World !”;
[/delphi]

html [html]
  1. # ほげ
  2. print "Hello, World !";
Java [java]
  1. # ほげ
  2. print "Hello, World !";
JavaScript [js]
  1. # ほげ
  2. print "Hello, World !";
MySQL [mysql]
  1. # ほげ
  2. print "Hello, World !";
perl [perl]
  1. # ほげ
  2. print "Hello, World !";
php [php]

※ 試しに 46 ~ 50 行目をハイライト

  1. <?php
  2.  
  3. /**********************************************************************************
  4.  
  5.     DBConnect クラス利用方法
  6.  
  7.     //  DB 接続
  8.     $db1 = new DBConnect();
  9.  
  10.     // この時点で可能な処理
  11.     // $mysqli = $db1->getMysqli()
  12.  
  13.     $table = $db1->getEscapeString($table); // POST データは信用できないので sql エスケープする
  14.     $sql = "SELECT * FROM {$table}";
  15.     $db1->setResult($sql);
  16.  
  17.     // この時点で可能な処理
  18.     // $result = $db1->getResult();
  19.     // $cols = $db1->getCols();     // 列数
  20.     // $rows = $db1->getRows();     // 行数
  21.  
  22.     if (empty($db1->error)) {       // エラーがなければ処理する
  23.  
  24.     } else {
  25.         print "<p>エラーが発生しました。{$db1->error}</p>\n";
  26.         print "<p>sql: " . $sql . "</p>\n";
  27.     }
  28.  
  29.     // DB 接続のクローズ処理 (クラスのデストラクタで DB のクローズ処理がされる)
  30.     if (!is_null($db1)) {
  31.         unset($db1);
  32.     }
  33.  
  34.  **********************************************************************************/
  35.  
  36. class DBConnect
  37. {
  38.  
  39.     private $mysqli;
  40.     private $result;
  41.     private $rows = 0;
  42.     private $cols = 0;
  43.     public  $error = "";
  44.  
  45.     // クラス定義時に呼び出される
  46.     function __construct()
  47.     {
  48.         $this->setMysqli();
  49.  
  50.     }
  51.  
  52.     // クラスが削除されるときに呼び出される
  53.     function __destruct()
  54.     {
  55.         $this->Close();
  56.     }
  57.  
  58.     private function setMysqli()
  59.     {
  60.         include "config.inc.php";
  61.  
  62.         mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  63.  
  64.         try {                                                   // DB への接続
  65.             $mysqli = new mysqli("localhost", $DB_USER, $DB_PASS, $DB_NAME);
  66.             $mysqli->set_charset('utf8');
  67.         } catch (mysqli_sql_exception $e) {
  68.             $this->$error .= $e->getMessage();
  69.         }
  70.  
  71.         $this->mysqli = $mysqli;
  72.     }
  73.  
  74.     public function getMysqli()
  75.     {
  76.         return $this->mysqli;
  77.     }
  78.  
  79.  
  80.     public function setResult($sql)
  81.     {
  82.         $mysqli = $this->mysqli;
  83.         try {
  84.             $result = $mysqli->query($sql);
  85.             $this->cols   = $mysqli->field_count;
  86.             $this->rows   = $result->num_rows;
  87.             $this->result = $result;
  88.         } catch (mysqli_sql_exception $e) {
  89.             $this->error .= $e->getMessage();
  90.         }
  91.     }
  92.  
  93.  
  94.     public function getResult()
  95.     {
  96.         return $this->result;
  97.     }
  98.  
  99.     public function getCols()
  100.     {
  101.         return $this->cols;
  102.     }
  103.  
  104.     public function getRows()
  105.     {
  106.         return $this->rows;
  107.     }
  108.  
  109.     public function getEscapeString ($str)
  110.     {
  111.         $str = $this->mysqli->real_escape_string($str);
  112.         return $str;
  113.     }
  114.  
  115.     private function Close()
  116.     {
  117.         if (!is_null($this->result)) {
  118.             $this->result->close();             // レコードセット破棄
  119.         }
  120.  
  121.         if (!is_null($this->mysqli)) {
  122.             $this->mysqli->close();             // DB 接続を閉じる
  123.         }
  124.     }
  125.  
  126. }
  127.  
  128.  
  129. ?>
Python [python]
  1. # ほげ
  2. print "Hello, World !";
ruby [ruby]
  1. # ほげ
  2. print "Hello, World !";
SMARTY [smarty]

[smarty]
# ほげ
print “Hello, World !”;
[/smarty]

SQL [sql]
  1. # ほげ
  2. print "Hello, World !";
Visual Basic [vb]
  1. # ほげ
  2. print "Hello, World !";
VB.NET [vbnet]
  1. # ほげ
  2. print "Hello, World !";
XML [xml]
  1. # ほげ
  2. print "Hello, World !";
Updated: 2015/9/3 木曜日 — 10:46:02

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

Bloody Mary - blog © 2008 - 2021