2003-11-20 12:04:19

Plasma 版的 Kwiki Formatter

最近在公司開始用力地使用 kwiki. 原先使用的是 OddMuse, 相較起來, kwiki 的語法就少多了. 這時候, 就該自己動手作.

成果就是 CGI::Kwiki::Formatter::Plasma. 更詳細的介紹在這裡. 最新版的源碼, 可在 藝立協的 Subversion 檔案庫 取得.

另外, 以下的說明文字可附加至 快紀文字格式語法 頁面, 說明新增的功能:

以下是本快紀的擴充語法.
----
[&AlignBegin center]這一段置中.[&AlignEnd]
[&AlignBegin center]這一段置中.[&AlignEnd]
[&AlignBegin right]這一段靠右.[&AlignEnd]
[&AlignBegin right]這一段靠右.[&AlignEnd]
[&AlignBegin center]
而且可跨超多段.

對不對?
[&AlignEnd]
[&AlignBegin center]
而且可跨超多段.

對不對?
[&AlignEnd]
----
這是 [&_ColorBegin red yellow]紅底黃字[&_ColorEnd] 的字串.
這是 [&_ColorBegin red yellow]紅底黃字[&_ColorEnd] 的字串.
也可以使用 [&_ColorBegin #923FED #FFFFFF]色碼[&_ColorEnd] 指定
也可以使用 [&_ColorBegin #923FED #FFFFFF]色碼[&_ColorEnd] 指定
----
[=Entity] 函式. 可以寫出有特殊用途的特殊字元.

要這樣寫都行: [=[&_Entity 91]&_Entity 91[&_Entity 93]].
要這樣寫都行: [=[&_Entity 91]&_Entity 91[&_Entity 93]].
----
定義清單:
;PC:個人電腦
;Mark-up Language:標記語言
;;XML:http://www.w3.org/XML/
;;HTML:http://www.w3.org/MarkUp/
;PC:個人電腦
;Mark-up Language:標記語言
;;XML:http://www.w3.org/XML/
;;HTML:http://www.w3.org/MarkUp/
----
表格中可以指定文字格式:
| 一般文字 | /斜體/ |
| _底線_ | /*粗體加斜體*/ |
| 一般文字 | /斜體/ |
| _底線_ | /*粗體加斜體*/ |
----
擴充版表格語法:
|跨越多欄的好長的一行文字|||
|跨越多列| 對中 | 對中 |
|^|靠左 |靠左 |
|^| 靠右| 靠右|
|跨越多欄的好長的一行文字|||
|跨越多列| 對中 | 對中 |
|^|靠左 |靠左 |
|^| 靠右| 靠右|
由 plasma 於 12:04 PM 所發表 | 迴響 (1)

2003-11-17 09:51:59

mozex installer wich T.Chinese fix

Some people said they don't know how to apply the patch, which fixes T.Chinese charcter problem, that I mentioned in the previous blog entry.

Ok, I made an .xpi installer, containing the patch stated my previous blog. You don't have to apply the patch manually, but you still have to install it manually. Automatic installing needs modifications to Apache's httpd.conf, but I don't have the authorization to do it.


  • Download the installer here. Mozilla should pop up a prompt, asking whether you want to install it or not..

  • After installed, restart Mozilla.

The file saved is in UTF-8, so your editor must recognize it.

由 plasma 於 09:51 AM 所發表 | 迴響 (530)

2003-11-14 09:31:32

mozex 與中文

mozex 是一個 Mozilla 的外掛模組. 它對 Mozilla 加強了許多功能, 像是使用外部編輯器來看 HTML 源碼, 以偏好的程式來處理不同的連結. 我最喜歡的, 是以外部編輯器來編輯 textarea 裡的資料.


Mozilla 本身雖然有提供一些基本的編輯功能, 但是畢竟不是文字編輯器, 用起來不甚順手. 而且每個人都有偏好的文字編輯器, 能夠使用自己順手的工具, 來編輯一篇較長的文字 (像是這一篇. :), 不是很好嗎?

可惜的是, mozex 存出來的文字檔, 無法被文字編輯器正確地辨識. 簡單地說, Mozilla 本身以 Unicode 來儲存內部的文字, 也就是兩個位元組. 但是寫出時, 卻只會寫入每個字的 低位元組! 例如以 快紀 兩個字作測試. 它在 Mozilla 中的表示為:

5feb 7d00

但是實際存進檔案時, 變成:

eb 00

我對它修改了一下, 在寫入檔案之前, 先轉成 UTF-8 的字元串流, 然後讀檔之後, 再轉回 Unicode. 這樣就可以正確地被可辨識 Unicode 的文字編輯器所使用. 以下是對 v1.07 的 mozex 的 patch (或者你可以從這裡下載):

diff -ruN content/mozex/mozex.js content.new/mozex/mozex.js
--- content/mozex/mozex.js	Sun Sep 21 17:14:58 2003
+++ content.new/mozex/mozex.js	Fri Nov 14 00:07:55 2003
@@ -865,11 +865,16 @@
             return false;
         }
        
+        var uc = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
+          createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+        uc.charset = "UTF-8";
+        var data_stream = uc.ConvertFromUnicode( data );
+
         var stream = Components.classes["@mozilla.org/network/file-output-stream;1"].
                      createInstance(Components.interfaces.nsIFileOutputStream);
         var PR_WRONLY = 0x02;
         stream.init(file, PR_WRONLY, 0600, 0);
-        stream.write(data, data.length);
+        stream.write(data_stream, data_stream.length);
         stream.flush()
         stream.close();
     } 
@@ -898,7 +903,10 @@
             var data = sis.read(sis.available());
             sis.close();
             is.close();
-            return data;
+        var uc = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
+          createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+        uc.charset = "UTF-8";
+            return uc.ConvertToUnicode( data );
         }
         else {
             mozexError("temporary file '" + filename + "' does not exist or is not readable");

使用方式:

  • 安裝 mozex.
  • ~/.mozilla/user_name/foobar.slt/chrome, 將 mozex.jar 以 unzip 解開來. 你會看到新產生一個 content 目錄.
  • 套用以上的 patch. 這個 patch 只會修改 content/mozex/mozex.js 而已.
  • 刪除原先的 mozex.jar, 將 content 目錄以 zip 再壓回 mozex.jar.
  • 重新啟動 Mozilla.

現在, mozex 應該就會輸出可正確被文字編輯器使用的 utf-8 檔案了. 本篇 blog 就是以 mozex, 在 Emacs 上寫成的. :)

由 plasma 於 09:31 AM 所發表 | 迴響 (1)