(www-format-encode-string): Add setting for `=mj' and `==mj'.
[chise/est.git] / cwiki-common.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'char-db-util)
3
4 (setq file-name-coding-system 'utf-8-mcs-er)
5
6
7 (concord-assign-genre 'creator@ruimoku "/usr/local/var/ruimoku/db")
8 (concord-assign-genre 'person-name@ruimoku "/usr/local/var/ruimoku/db")
9
10 (concord-assign-genre 'journal-volume@ruimoku "/usr/local/var/ruimoku/db")
11 (concord-assign-genre 'article@ruimoku "/usr/local/var/ruimoku/db")
12 (concord-assign-genre 'book@ruimoku "/usr/local/var/ruimoku/db")
13
14 (concord-assign-genre 'classification@ruimoku "/usr/local/var/ruimoku/db")
15 (concord-assign-genre 'region@ruimoku "/usr/local/var/ruimoku/db")
16 (concord-assign-genre 'era@ruimoku "/usr/local/var/ruimoku/db")
17 (concord-assign-genre 'period@ruimoku "/usr/local/var/ruimoku/db")
18 (concord-assign-genre 'journal@ruimoku "/usr/local/var/ruimoku/db")
19 (concord-assign-genre 'journal-name@ruimoku "/usr/local/var/ruimoku/db")
20 (concord-assign-genre 'publisher@ruimoku "/usr/local/var/ruimoku/db")
21 (concord-assign-genre 'publisher-name@ruimoku "/usr/local/var/ruimoku/db")
22
23 (mount-char-attribute-table '*instance@ruimoku/bibliography/title)
24 ;; (mount-char-attribute-table '*instance@ruimoku/bibliography/content*note)
25
26 (concord-assign-genre 'entry@zh-classical "/usr/local/var/kanbun/db")
27 ;; (concord-assign-genre 'morpheme-entry@zh-classical "/usr/local/var/kanbun/db")
28 (concord-assign-genre 'word-class@zh-classical "/usr/local/var/kanbun/db")
29 (concord-assign-genre 'morpheme@zh-classical "/usr/local/var/kanbun/db")
30 (concord-assign-genre 'sentence@zh-classical "/usr/local/var/kanbun/db")
31 ;; (concord-assign-genre 'sentence-entry@zh-classical "/usr/local/var/kanbun/db")
32
33 (mount-char-attribute-table '*instance@morpheme-entry/zh-classical)
34
35
36 (mount-char-attribute-table '->HNG)
37 (mount-char-attribute-table '<-HNG)
38
39
40 (defvar est-hide-cgi-mode nil)
41 (defvar est-view-url-prefix "..")
42 (defvar chise-wiki-view-url "view.cgi")
43 (defvar chise-wiki-edit-url "edit.cgi")
44
45 (defvar chise-wiki-bitmap-glyphs-url
46   "http://www.chise.org/glyphs")
47
48 (defvar chise-wiki-hng-bitmap-glyphs-url
49   "http://hng.chise.org/glyphs/HNG")
50
51 (defvar chise-wiki-glyph-cgi-url
52   "http://www.chise.org/chisewiki/glyph.cgi")
53
54 (defvar chise-wiki-displayed-features nil)
55
56 (defvar est-coded-charset-priority-list
57   '(; =ucs
58     =cns11643-1 =cns11643-2 =cns11643-3
59     =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
60     =gb2312 =gb12345
61     =jis-x0208 =jis-x0208@1990
62     =jis-x0213-2
63     =jis-x0212
64     =adobe-japan1
65     =cbeta =jef-china3
66     =jis-x0213-1@2000 =jis-x0213-1@2004
67     =jis-x0208@1983 =jis-x0208@1978
68     =zinbun-oracle =>zinbun-oracle
69     =daikanwa
70     =gt =gt-k
71     =>>>adobe-japan1
72     =>>>jis-x0208 =>>>jis-x0213-1 =>>>jis-x0213-2
73     =>>jis-x0208 =>>jis-x0213-1 =>>jis-x0213-2
74     =>>adobe-japan1
75     =+>jis-x0208 =+>jis-x0213-1 =+>jis-x0213-2
76     =+>jis-x0208@1978
77     =+>adobe-japan1
78     =>jis-x0208 =>jis-x0213-1
79     =>>gt
80     =>ucs@iso =>ucs@unicode
81     =>ucs@jis =>ucs@cns =>ucs@ks
82     =>>ucs@iso =>>ucs@unicode
83     =>>ucs@jis =>>ucs@cns =>>ucs@ks
84     =>>>ucs@iso =>>>ucs@unicode
85     =>>>ucs@jis =>>>ucs@cns =>>>ucs@ks
86     ===ucs@iso
87     =ruimoku-v6
88     =big5
89     =big5-cdp
90     =>cbeta
91     =mj
92     ==mj
93     ===mj
94     =ucs-itaiji-001
95     =ucs-itaiji-002
96     =ucs-itaiji-003))
97
98 (defun decode-uri-string (string &optional coding-system)
99   (if (> (length string) 0)
100       (let ((i 0)
101             dest)
102         (setq string
103               (mapconcat (lambda (char)
104                            (if (eq char ?+)
105                                " "
106                              (char-to-string char)))
107                          string ""))
108         (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
109           (setq dest (concat dest
110                              (substring string i (match-beginning 0))
111                              (char-to-string
112                               (int-char
113                                (string-to-int (match-string 1 string) 16))))
114                 i (match-end 0)))
115         (decode-coding-string
116          (concat dest (substring string i))
117          coding-system))))
118
119 (defun www-feature-type (feature-name)
120   (or (char-feature-property feature-name 'type)
121       (let ((str (symbol-name feature-name)))
122         (cond
123          ((string-match "\\*note\\(@[^*]+\\)?$" str)
124           'stext)
125          ((string-match "\\*sources\\(@[^*]+\\)?$" str)
126           'domain-list)
127          ((string-match "\\*" str)
128           nil)
129          ((string-match "^\\(->\\|<-\\)" str)
130           'relation)
131          ((string-match "^ideographic-structure\\(@\\|$\\)" str)
132           'structure)
133          ))))
134
135 (defun www-feature-format (feature-name)
136   (or (char-feature-property feature-name 'presentation-format)
137       (char-feature-property feature-name 'format)
138       (let (fn parent ret)
139         (setq fn feature-name)
140         (while (and (setq parent (char-feature-name-parent fn))
141                     (null (setq ret
142                                 (char-feature-property
143                                  parent 'format))))
144           (setq fn parent))
145         ret)
146       '((name) " : " (value))))
147
148 (defun www-feature-value-format (feature-name)
149   (or (char-feature-property feature-name 'value-presentation-format)
150       (char-feature-property feature-name 'value-format)
151       (let (fn parent ret)
152         (setq fn feature-name)
153         (while (and (setq parent (char-feature-name-parent fn))
154                     (null (setq ret
155                                 (or (char-feature-property
156                                      parent 'value-presentation-format)
157                                     (char-feature-property
158                                      parent 'value-format)))))
159           (setq fn parent))
160         ret)
161       (let ((type (www-feature-type feature-name)))
162         (cond ((eq type 'relation)
163                'space-separated)
164               ((eq type 'structure)
165                'space-separated-ids)
166               ((eq type 'stext)
167                'wiki-text)
168               ))
169       (if (find-charset feature-name)
170           (if (and (= (charset-dimension feature-name) 2)
171                    (= (charset-chars feature-name) 94))
172               '("0x" (HEX)
173                 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
174             '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))
175       'space-separated))
176
177 (defun char-feature-name-at-domain (feature-name domain)
178   (if domain
179       (let ((name (symbol-name feature-name)))
180         (cond
181          ((string-match "@[^*]+$" name)
182           (intern (format "%s/%s" name domain))
183           )
184          (t
185           (intern (format "%s@%s" name domain))
186           )))
187     feature-name))
188
189 (defun char-feature-name-parent (feature-name)
190   (let ((name (symbol-name feature-name)))
191     (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
192         (intern (substring name 0 (car (last (match-data) 2)))))))
193
194 (defun char-feature-name-domain (feature-name)
195   (let ((name (symbol-name feature-name)))
196     (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
197         (intern (substring name (1+ (match-beginning 0)))))))
198
199 (defun char-feature-name-sans-versions (feature)
200   (let ((feature-name (symbol-name feature)))
201     (if (string-match "[@/]\\$rev=latest$" feature-name)
202         (intern (substring feature-name 0 (match-beginning 0)))
203       feature)))
204
205 (defun est-object-genre (object)
206   (if (characterp object)
207       'character
208     (concord-object-genre object)))
209
210 (defun www-get-feature-value (object feature)
211   (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
212     (cond
213      ((characterp object)
214       (mount-char-attribute-table latest-feature)
215       (or (char-feature object latest-feature)
216           (char-feature object feature))
217       )
218      (t
219       (or (condition-case nil
220               (concord-object-get object latest-feature)
221             (error nil))
222           (condition-case nil
223               (concord-object-get object feature)
224             (error nil)))
225       ))))
226
227 (defun get-previous-code-point (ccs code)
228   (let ((chars (charset-chars ccs))
229         (dim (charset-dimension ccs))
230         (i 0)
231         mask byte-min byte-max
232         bytes dest)
233     (cond
234      ((= chars 94)
235       (setq mask #x7F
236             byte-min 33
237             byte-max 126)
238       )
239      ((= chars 96)
240       (setq mask #x7F
241             byte-min 32
242             byte-max 127)
243       )
244      ((= chars 128)
245       (setq mask #x7F
246             byte-min 0
247             byte-max #xFF)
248       )
249      (t ; (= chars 256)
250       (setq mask #xFF
251             byte-min 0
252             byte-max #xFF)
253       ))
254     (setq bytes (make-vector dim 0))
255     (while (< i dim)
256       (aset bytes i (logand (lsh code (* i -8)) mask))
257       (setq i (1+ i)))
258     (setq i 0)
259     (while (and (< i dim)
260                 (progn
261                   (aset bytes i (1- (aref bytes i)))
262                   (< (aref bytes i) byte-min)))
263       (aset bytes i byte-max)
264       (setq i (1+ i)))
265     (when (< i dim)
266       (setq dest (aref bytes 0)
267             i 1)
268       (while (< i dim)
269         (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
270               i (1+ i)))
271       dest)))
272
273 (defun get-next-code-point (ccs code)
274   (let ((chars (charset-chars ccs))
275         (dim (charset-dimension ccs))
276         (i 0)
277         mask byte-min byte-max
278         bytes dest)
279     (cond
280      ((= chars 94)
281       (setq mask #x7F
282             byte-min 33
283             byte-max 126)
284       )
285      ((= chars 96)
286       (setq mask #x7F
287             byte-min 32
288             byte-max 127)
289       )
290      ((= chars 128)
291       (setq mask #x7F
292             byte-min 0
293             byte-max #xFF)
294       )
295      (t ; (= chars 256)
296       (setq mask #xFF
297             byte-min 0
298             byte-max #xFF)
299       ))
300     (setq bytes (make-vector dim 0))
301     (while (< i dim)
302       (aset bytes i (logand (lsh code (* i -8)) mask))
303       (setq i (1+ i)))
304     (setq i 0)
305     (while (and (< i dim)
306                 (progn
307                   (aset bytes i (1+ (aref bytes i)))
308                   (> (aref bytes i) byte-max)))
309       (aset bytes i byte-min)
310       (setq i (1+ i)))
311     (when (< i dim)
312       (setq dest (aref bytes 0)
313             i 1)
314       (while (< i dim)
315         (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
316               i (1+ i)))
317       dest)))
318
319 (defun find-previous-defined-code-point (ccs code)
320   (let ((i (get-previous-code-point ccs code))
321         char)
322     (cond
323      ((eq ccs '=jis-x0208)
324       (setq ccs '=jis-x0208@1990))
325      ((eq ccs '=jis-x0213-1)
326       (setq ccs '=jis-x0213-1@2004)))
327     (while (and i
328                 (>= i 0)
329                 (null (setq char (decode-char ccs i
330                                               (unless (eq ccs '=ucs)
331                                                 'defined-only)))))
332       (setq i (get-previous-code-point ccs i)))
333     char))
334
335 (defun find-next-defined-code-point (ccs code)
336   (let ((i (get-next-code-point ccs code))
337         max char)
338     (setq max (+ code 1000))
339     (cond
340      ((eq ccs '=jis-x0208)
341       (setq ccs '=jis-x0208@1990))
342      ((eq ccs '=jis-x0213-1)
343       (setq ccs '=jis-x0213-1@2004)))
344     (while (and i
345                 (<= i max)
346                 (null (setq char (decode-char ccs i
347                                               (unless (eq ccs '=ucs)
348                                                 'defined-only)))))
349       (setq i (get-next-code-point ccs i)))
350     char))
351
352
353 ;;; @ URI representation
354 ;;;
355
356 (defun est-uri-decode-feature-name-body (uri-feature)
357   (let ((len (length uri-feature))
358         (i 0)
359         ch dest)
360     (while (< i len)
361       (setq dest
362             (concat
363              dest
364              (if (eq (aref uri-feature i) ?\.)
365                  (if (and (< (+ i 2) len)
366                           (eq (aref uri-feature (+ i 2)) ?\.))
367                      (prog1
368                          (cond
369                           ((eq (setq ch (aref uri-feature (1+ i))) ?\.)
370                            "/")
371                           ((eq ch ?-)
372                            "*")
373                           (t
374                            (substring uri-feature i (+ i 3))
375                            ))
376                        (setq i (+ i 3)))
377                    (setq i (1+ i))
378                    ".")
379                (prog1
380                    (char-to-string (aref uri-feature i))
381                  (setq i (1+ i)))))))
382     dest))
383
384 (defun est-uri-encode-feature-name-body (feature)
385   (mapconcat (lambda (c)
386                (cond ((eq c ?*)
387                       ".-.")
388                      ((eq c ?/)
389                       "...")
390                      (t (char-to-string c))))
391              feature ""))
392
393 (defun www-uri-decode-feature-name (uri-feature)
394   (let (feature)
395     (setq uri-feature (decode-uri-string uri-feature 'utf-8-mcs-er))
396     (cond
397      ((string-match "^from\\." uri-feature)
398       (intern (format "<-%s"
399                       (est-uri-decode-feature-name-body
400                        (substring uri-feature (match-end 0)))))
401       )
402      ((string-match "^to\\." uri-feature)
403       (intern (format "->%s"
404                       (est-uri-decode-feature-name-body
405                        (substring uri-feature (match-end 0)))))
406       )
407      ((string-match "^rep\\." uri-feature)
408       (intern (format "=%s"
409                       (est-uri-decode-feature-name-body
410                        (substring uri-feature (match-end 0)))))
411       )
412      ((string-match "^rep[2i]\\." uri-feature)
413       (intern (format "===%s"
414                       (est-uri-decode-feature-name-body
415                        (substring uri-feature (match-end 0)))))
416       )
417      ((string-match "^g\\." uri-feature)
418       (intern (format "=>>%s"
419                       (est-uri-decode-feature-name-body
420                        (substring uri-feature (match-end 0)))))
421       )
422      ((string-match "^g[i2]\\." uri-feature)
423       (intern (format "==%s"
424                       (est-uri-decode-feature-name-body
425                        (substring uri-feature (match-end 0)))))
426       )
427      ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
428       (intern (format "=>>%s%s"
429                       (make-string (string-to-int
430                                     (match-string 1 uri-feature))
431                                    ?>)
432                       (est-uri-decode-feature-name-body
433                        (substring uri-feature (match-end 0)))))
434       )
435      ((string-match "^o\\." uri-feature)
436       (intern (format "=+>%s"
437                       (est-uri-decode-feature-name-body
438                        (substring uri-feature (match-end 0)))))
439       )
440      ((string-match "^a\\." uri-feature)
441       (intern (format "=>%s"
442                       (est-uri-decode-feature-name-body
443                        (substring uri-feature (match-end 0)))))
444       )
445      ((string-match "^a\\([0-9]+\\)\\." uri-feature)
446       (intern (format "%s>%s"
447                       (make-string (string-to-int
448                                     (match-string 1 uri-feature))
449                                    ?=)
450                       (est-uri-decode-feature-name-body
451                        (substring uri-feature (match-end 0)))))
452       )
453      ((and (setq uri-feature (est-uri-decode-feature-name-body uri-feature))
454            (setq feature (intern (format "=>%s" uri-feature)))
455            (find-charset feature))
456       feature)
457      ((and (setq feature (intern (format "=>>%s" uri-feature)))
458            (find-charset feature))
459       feature)
460      ((and (setq feature (intern (format "=>>>%s" uri-feature)))
461            (find-charset feature))
462       feature)
463      ((and (setq feature (intern (format "=%s" uri-feature)))
464            (find-charset feature))
465       feature)
466      (t (intern uri-feature)))))
467
468 (defun www-uri-encode-feature-name (feature-name)
469   (setq feature-name (symbol-name feature-name))
470   (cond
471    ((string-match "^=\\+>\\([^=>]+\\)" feature-name)
472     (concat "o."
473             (est-uri-encode-feature-name-body
474              (substring feature-name (match-beginning 1))))
475     )
476    ((string-match "^=\\([^=>]+\\)" feature-name)
477     (concat "rep."
478             (est-uri-encode-feature-name-body
479              (substring feature-name (match-beginning 1))))
480     )
481    ((string-match "^==\\([^=>]+\\)" feature-name)
482     (concat "g2."
483             (est-uri-encode-feature-name-body
484              (substring feature-name (match-beginning 1))))
485     )
486    ((string-match "^===\\([^=>]+\\)" feature-name)
487     (concat "repi."
488             (est-uri-encode-feature-name-body
489              (substring feature-name (match-beginning 1))))
490     )
491    ((string-match "^=>>\\([^=>]+\\)" feature-name)
492     (concat "g."
493             (est-uri-encode-feature-name-body
494              (substring feature-name (match-beginning 1))))
495     )
496    ((string-match "^=>>>\\([^=>]+\\)" feature-name)
497     (concat "gi."
498             (est-uri-encode-feature-name-body
499              (substring feature-name (match-beginning 1))))
500     )
501    ((string-match "^=>>\\(>+\\)" feature-name)
502     (format "gi%d.%s"
503             (length (match-string 1 feature-name))
504             (est-uri-encode-feature-name-body
505              (substring feature-name (match-end 1))))
506     )
507    ((string-match "^=>\\([^=>]+\\)" feature-name)
508     (concat "a."
509             (est-uri-encode-feature-name-body
510              (substring feature-name (match-beginning 1))))
511     )
512    ((string-match "^\\(=+\\)>" feature-name)
513     (format "a%d.%s"
514             (length (match-string 1 feature-name))
515             (est-uri-encode-feature-name-body
516              (substring feature-name (match-end 0))))
517     )
518    ((string-match "^->" feature-name)
519     (concat "to."
520             (est-uri-encode-feature-name-body
521              (substring feature-name (match-end 0))))
522     )
523    ((string-match "^<-" feature-name)
524     (concat "from."
525             (est-uri-encode-feature-name-body
526              (substring feature-name (match-end 0))))
527     )
528    (t (est-uri-encode-feature-name-body feature-name))))
529
530 (defun www-uri-make-feature-name-url (uri-genre uri-feature-name uri-object)
531   (if est-hide-cgi-mode
532       (format "../feature/%s&%s/%s"
533               uri-feature-name uri-genre uri-object)
534     (format "%s?feature=%s&%s=%s"
535             chise-wiki-view-url uri-feature-name uri-genre uri-object)))
536
537 (defun www-uri-decode-object (genre char-rep)
538   (let (ccs cpos)
539     (cond
540      ((string-match (if est-hide-cgi-mode
541                         "\\(%3D\\|=\\|%3A\\|:\\)"
542                       "\\(%3A\\|:\\)") char-rep)
543       (setq ccs (substring char-rep 0 (match-beginning 0))
544             cpos (substring char-rep (match-end 0)))
545       (setq ccs (www-uri-decode-feature-name ccs))
546       (setq cpos (est-uri-decode-feature-name-body cpos))
547       (cond
548        ((string-match "^0x" cpos)
549         (setq cpos
550               (string-to-number (substring cpos (match-end 0)) 16))
551         )
552        (t
553         (setq cpos (car (read-from-string
554                          (decode-uri-string
555                           cpos file-name-coding-system))))
556         ))
557       (if (and (eq genre 'character)
558                (numberp cpos))
559           (decode-char ccs cpos)
560         (concord-decode-object ccs cpos genre))
561       )
562      (t
563       (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
564       (cond
565        ((eq genre 'character)
566         (when (= (length char-rep) 1)
567           (aref char-rep 0))
568         )
569        ((eq genre 'feature)
570         (concord-decode-object
571          '=id (www-uri-decode-feature-name char-rep) 'feature)
572         )
573        (t
574         (concord-decode-object
575          '=id (car (read-from-string char-rep)) genre)
576         ))))))
577
578 (defun www-uri-encode-object (object)
579   (if (characterp object)
580       (if (encode-char object '=ucs)
581           (mapconcat
582            (lambda (byte)
583              (format "%%%02X" byte))
584            (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
585            "")
586         (let ((ccs-list est-coded-charset-priority-list)
587               ccs ret)
588           (while (and ccs-list
589                       (setq ccs (pop ccs-list))
590                       (not (setq ret (encode-char object ccs 'defined-only)))))
591           (cond (ret
592                  (format (if est-hide-cgi-mode
593                              "%s=0x%X"
594                            "%s:0x%X")
595                          (www-uri-encode-feature-name ccs)
596                          ret))
597                 ((and (setq ccs (car (split-char object)))
598                       (setq ret (encode-char object ccs)))
599                  (format (if est-hide-cgi-mode
600                              "%s=0x%X"
601                            "%s:0x%X")
602                          (www-uri-encode-feature-name ccs)
603                          ret))
604                 (t
605                  (format (if est-hide-cgi-mode
606                              "system-char-id=0x%X"
607                            "system-char-id:0x%X")
608                          (encode-char object 'system-char-id))
609                  ))))
610     (format (if est-hide-cgi-mode
611                 "rep.id=%s"
612               "rep.id:%s")
613             (est-uri-encode-feature-name-body
614              (format "%s" (concord-object-id object))))))
615
616 (defun est-format-object (object &optional readable)
617   (if (characterp object)
618       (char-to-string object)
619     (let ((ret (or (if readable
620                        (or (concord-object-get object 'name)
621                            (concord-object-get object '=name)
622                            (concord-object-get object 'title)))
623                    (concord-object-id object))))
624       (format "%s" ret))))
625
626 (defun www-uri-make-object-url (object &optional uri-object)
627   (if est-hide-cgi-mode
628       (format "%s/%s/%s"
629               est-view-url-prefix
630               (est-object-genre object)
631               (or uri-object
632                   (www-uri-encode-object object)))
633     (format "%s?%s=%s"
634             chise-wiki-view-url
635             (est-object-genre object)
636             (or uri-object
637                 (www-uri-encode-object object)))))
638
639
640 ;;; @ Feature name presentation
641 ;;;
642
643 (defun www-format-feature-name-default (feature-name)
644   (mapconcat
645    #'capitalize
646    (split-string
647     (symbol-name feature-name)
648     "-")
649    " "))
650
651 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
652   (let ((str (symbol-name feature-name))
653         base meta)
654     (cond
655      ((string-match "\\*[^*]+$" str)
656       (setq base (substring str 0 (match-beginning 0))
657             meta (substring str (match-beginning 0)))
658       (concat (www-format-feature-name* (intern base) lang)
659               meta))
660      (t
661       (www-format-feature-name-default feature-name)
662       ))))
663
664 (defun www-format-feature-name-as-rel-to (feature-name)
665   (concat "\u2192" (substring (symbol-name feature-name) 2)))
666
667 (defun www-format-feature-name-as-rel-from (feature-name)
668   (concat "\u2190" (substring (symbol-name feature-name) 2)))
669
670 (defun www-format-feature-name-as-CCS (feature-name)
671   (let* ((rest
672           (split-string
673            (symbol-name feature-name)
674            "-"))
675          (dest (upcase (pop rest))))
676     (when (string-match "^=+>*" dest)
677       (setq dest (concat (substring dest 0 (match-end 0))
678                          " "
679                          (substring dest (match-end 0)))))
680     (cond
681      (rest
682       (while (cdr rest)
683         (setq dest (concat dest " " (upcase (pop rest)))))
684       (if (string-match "^[0-9]+$" (car rest))
685           (concat dest "-" (car rest))
686         (concat dest " " (upcase (car rest))))
687       )
688      (t dest))))
689
690 (defun www-format-feature-name* (feature-name &optional lang)
691   (let (name fn parent ret)
692     (cond
693      ((or (and lang
694                (char-feature-property
695                 feature-name
696                 (intern (format "name@%s" lang))))
697           (char-feature-property
698            feature-name 'name)))
699      ((and (setq name (symbol-name feature-name))
700            (string-match "\\*" name))
701       (www-format-feature-name-as-metadata feature-name lang))
702      (t
703       (setq fn feature-name)
704       (while (and (setq parent (char-feature-name-parent fn))
705                   (null (setq ret
706                               (or (and lang
707                                        (char-feature-property
708                                         parent
709                                         (intern (format "name@%s" lang))))
710                                   (char-feature-property
711                                    parent 'name)))))
712         (setq fn parent))
713       (cond
714        (ret
715         (concat ret (substring (symbol-name feature-name)
716                                (length (symbol-name parent)))))
717        ((find-charset feature-name)
718         (www-format-feature-name-as-CCS feature-name))
719        ((string-match "^\\(->\\)" name)
720         (www-format-feature-name-as-rel-to feature-name))
721        ((string-match "^\\(<-\\)" name)
722         (www-format-feature-name-as-rel-from feature-name))
723        (t
724         (www-format-feature-name-default feature-name)
725         ))
726       ))))
727
728 (defun www-format-feature-name (feature-name &optional lang)
729   (www-format-encode-string
730    (www-format-feature-name* feature-name lang)))
731
732
733 ;;; @ HTML generator
734 ;;;
735
736 (defvar www-format-char-img-style "vertical-align:bottom;")
737
738 (defun www-format-encode-string (string &optional without-tags as-body)
739   (with-temp-buffer
740     (insert string)
741     (let (plane code subcode start end char variants ret rret)
742       (when as-body
743         (goto-char (point-min))
744         (while (search-forward "&" nil t)
745           (replace-match "&amp;" nil t)))
746       (goto-char (point-min))
747       (while (search-forward "<" nil t)
748         (replace-match "&lt;" nil t))
749       (goto-char (point-min))
750       (while (search-forward ">" nil t)
751         (replace-match "&gt;" nil t))
752       (if without-tags
753           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
754         (let ((coded-charset-entity-reference-alist
755                (list*
756                 '(=gt                   "GT-" 5 d)
757                 '(=mj                    "MJ" 6 d)
758                 '(=hanyo-denshi/ja   "HD-JA-" 4 X)
759                 '(=hanyo-denshi/jb   "HD-JB-" 4 X)
760                 '(=hanyo-denshi/jc   "HD-JC-" 4 X)
761                 '(=hanyo-denshi/jd   "HD-JD-" 4 X)
762                 '(=hanyo-denshi/ft   "HD-FT-" 4 X)
763                 '(=hanyo-denshi/ia   "HD-IA-" 4 X)
764                 '(=hanyo-denshi/ib   "HD-IB-" 4 X)
765                 '(=hanyo-denshi/hg   "HD-HG-" 4 X)
766                 '(=hanyo-denshi/ip   "HD-IP-" 4 X)
767                 '(=hanyo-denshi/jt   "HD-JT-" 4 X)
768                 '(=hanyo-denshi/ks   "HD-KS-" 6 d)
769                 '(=>>hanyo-denshi/ja "G-HD-JA-" 4 X)
770                 '(=>>hanyo-denshi/jb "G-HD-JB-" 4 X)
771                 '(=>>hanyo-denshi/jc "G-HD-JC-" 4 X)
772                 '(=>>hanyo-denshi/jd "G-HD-JD-" 4 X)
773                 '(=>>hanyo-denshi/ft "G-HD-FT-" 4 X)
774                 '(=>>hanyo-denshi/ia "G-HD-IA-" 4 X)
775                 '(=>>hanyo-denshi/ib "G-HD-IB-" 4 X)
776                 '(=>>hanyo-denshi/hg "G-HD-HG-" 4 X)
777                 '(=>>hanyo-denshi/ip "G-HD-IP-" 4 X)
778                 '(=>>hanyo-denshi/jt "G-HD-JT-" 4 X)
779                 '(=>>hanyo-denshi/ks "G-HD-KS-" 6 d)
780                 '(==mj                  "g2-MJ" 6 d)
781                 '(==hanyo-denshi/ja "g2-HD-JA-" 4 X)
782                 '(==hanyo-denshi/jb "g2-HD-JB-" 4 X)
783                 '(==hanyo-denshi/jc "g2-HD-JC-" 4 X)
784                 '(==hanyo-denshi/jd "g2-HD-JD-" 4 X)
785                 '(==hanyo-denshi/ft "g2-HD-FT-" 4 X)
786                 '(==hanyo-denshi/ia "g2-HD-IA-" 4 X)
787                 '(==hanyo-denshi/ib "g2-HD-IB-" 4 X)
788                 '(==hanyo-denshi/hg "g2-HD-HG-" 4 X)
789                 '(==hanyo-denshi/ip "g2-HD-IP-" 4 X)
790                 '(==hanyo-denshi/jt "g2-HD-JT-" 4 X)
791                 '(==hanyo-denshi/ks "g2-HD-KS-" 6 d)
792                 '(=cns11643-1           "C1-" 4 X)
793                 '(=cns11643-2           "C2-" 4 X)
794                 '(=cns11643-3           "C3-" 4 X)
795                 '(=cns11643-4           "C4-" 4 X)
796                 '(=cns11643-5           "C5-" 4 X)
797                 '(=cns11643-6           "C6-" 4 X)
798                 '(=cns11643-7           "C7-" 4 X)
799                 '(=adobe-japan1-6       "AJ1-" 5 d)
800                 '(=big5-cdp             "CDP-" 4 X)
801                 '(=gb2312               "G0-" 4 X)
802                 '(=gb12345              "G1-" 4 X)
803                 '(=jis-x0208@1990       "J90-" 4 X)
804                 '(=jis-x0212            "JSP-" 4 X)
805                 '(=cbeta                "CB" 5 d)
806                 '(=jis-x0208@1997       "J97-" 4 X)
807                 '(=jis-x0208@1978       "J78-" 4 X)
808                 '(=jis-x0208@1983       "J83-" 4 X)
809                 '(=ruimoku-v6           "RUI6-" 4 X)
810                 '(=zinbun-oracle        "ZOB-" 4 d)
811                 '(=jef-china3           "JC3-" 4 X)
812                 '(=ucs@unicode          "UU+" 4 X)
813                 '(=ucs@JP/hanazono  "hanaJU+" 4 X)
814                 '(==cns11643-1        "R-C1-" 4 X)
815                 '(==cns11643-2        "R-C2-" 4 X)
816                 '(==cns11643-3        "R-C3-" 4 X)
817                 '(==cns11643-4        "R-C4-" 4 X)
818                 '(==cns11643-5        "R-C5-" 4 X)
819                 '(==cns11643-6        "R-C6-" 4 X)
820                 '(==cns11643-7        "R-C7-" 4 X)
821                 '(=hanziku-1         "HZK01-" 4 X)
822                 '(=hanziku-2         "HZK02-" 4 X)
823                 '(=hanziku-3         "HZK03-" 4 X)
824                 '(=hanziku-4         "HZK04-" 4 X)
825                 '(=hanziku-5         "HZK05-" 4 X)
826                 '(=hanziku-6         "HZK06-" 4 X)
827                 '(=hanziku-7         "HZK07-" 4 X)
828                 '(=hanziku-8         "HZK08-" 4 X)
829                 '(=hanziku-9         "HZK09-" 4 X)
830                 '(=hanziku-10        "HZK10-" 4 X)
831                 '(=hanziku-11        "HZK11-" 4 X)
832                 '(=hanziku-12        "HZK12-" 4 X)
833                 '(=big5                  "B-" 4 X)
834                 '(=daikanwa              "M-" 5 d)
835                 coded-charset-entity-reference-alist)))
836           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
837
838           (goto-char (point-min))
839           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\)?CB\\([0-9]+\\);" nil t)
840             (setq code (string-to-int (match-string 2)))
841             (replace-match
842              (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\"
843 style=\"%s\">"
844                      code
845                      chise-wiki-bitmap-glyphs-url
846                      (/ code 1000) code
847                      www-format-char-img-style)
848              t 'literal))
849
850           (goto-char (point-min))
851           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
852             (setq plane (match-string 2)
853                   code (string-to-int (match-string 3) 16))
854             (replace-match
855              (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\"
856 style=\"%s\">"
857                      plane code
858                      chise-wiki-bitmap-glyphs-url
859                      plane
860                      (- (lsh code -8) 32)
861                      (- (logand code 255) 32)
862                      www-format-char-img-style)
863              t 'literal))
864
865           (goto-char (point-min))
866           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?J0-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
867             (setq code (string-to-int (match-string 2) 16))
868             (replace-match
869              (format "<img alt=\"J0-%04X\" src=\"%s/JIS-90/%02d-%02d.gif\"
870 style=\"%s\">"
871                      code
872                      chise-wiki-bitmap-glyphs-url
873                      (- (lsh code -8) 32)
874                      (- (logand code 255) 32)
875                      www-format-char-img-style)
876              t 'literal))
877
878           (goto-char (point-min))
879           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-\\(JA\\|JB\\|JC\\|JD\\|FT\\|IA\\|IB\\|HG\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
880             (setq plane (match-string 2)
881                   code (string-to-int (match-string 3) 16))
882             (replace-match
883              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%02d%02d.png\"
884 style=\"%s\">"
885                      plane code
886                      chise-wiki-bitmap-glyphs-url
887                      plane
888                      (- (lsh code -8) 32)
889                      (- (logand code 255) 32)
890                      www-format-char-img-style)
891              t 'literal))
892
893           (goto-char (point-min))
894           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-\\(IP\\|JT\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
895             (setq plane (match-string 2)
896                   code (string-to-int (match-string 3) 16))
897             (replace-match
898              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%04X.png\"
899 style=\"%s\">"
900                      plane code
901                      chise-wiki-bitmap-glyphs-url
902                      plane code
903                      www-format-char-img-style)
904              t 'literal))
905
906           (goto-char (point-min))
907           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-KS-\\([0-9]+\\);" nil t)
908             (setq code (string-to-int (match-string 2)))
909             (replace-match
910              (format "<img alt=\"HD-KS%06d\" src=\"%s/IVD/HanyoDenshi/KS%06d.png\"
911 style=\"vertical-align:middle\">"
912                      code
913                      chise-wiki-bitmap-glyphs-url
914                      code
915                      www-format-char-img-style)
916              t 'literal))
917
918           (goto-char (point-min))
919           (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
920             (setq plane (string-to-int (match-string 1))
921                   code (string-to-int (match-string 2) 16))
922             (replace-match
923              (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\"
924 style=\"%s\">"
925                      plane code
926                      chise-wiki-bitmap-glyphs-url
927                      plane
928                      (- (lsh code -8) 32)
929                      (- (logand code 255) 32)
930                      www-format-char-img-style)
931              t 'literal))
932
933           (goto-char (point-min))
934           (while (re-search-forward "&\\(R-\\)?C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
935             (setq plane (string-to-int (match-string 2))
936                   code (string-to-int (match-string 3) 16))
937             (replace-match
938              (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\"
939 style=\"%s\">"
940                      plane code
941                      chise-wiki-bitmap-glyphs-url
942                      plane code
943                      www-format-char-img-style)
944              t 'literal))
945
946           (goto-char (point-min))
947           (while (re-search-forward "&\\(R-\\)?JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
948             (setq code (string-to-int (match-string 2) 16))
949             (replace-match
950              (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
951                      code code)
952              t 'literal))
953
954           (goto-char (point-min))
955           (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
956             (setq code (string-to-int (match-string 2)))
957             (replace-match
958              (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\"
959 style=\"vertical-align:middle\">"
960                      code
961                      chise-wiki-bitmap-glyphs-url
962                      code
963                      www-format-char-img-style)
964              t 'literal))
965
966           (goto-char (point-min))
967           (while (re-search-forward "&HNG\\([0-9]+\\)-\\([0-9][0-9][0-9][0-9]\\)\\([0-9]\\);" nil t)
968             (setq plane (match-string 1)
969                   code (string-to-int (match-string 2))
970                   subcode (string-to-int (match-string 3)))
971             (setq subcode
972                   (if (eq subcode 0)
973                       ""
974                     (char-to-string (decode-char 'ascii (+ 96 subcode)))))
975             (replace-match
976              (format
977               "<img alt=\"HNG%s-%04d%s\" src=\"%s/%s/%04d%s.png\"
978 style=\"vertical-align:middle; width: 48px; height: 48px\">"
979               plane code subcode
980               chise-wiki-hng-bitmap-glyphs-url
981               plane code subcode
982               www-format-char-img-style)
983              t 'literal))
984
985           (goto-char (point-min))
986           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?AJ1-\\([0-9]+\\);" nil t)
987             (setq code (string-to-int (match-string 2)))
988             (replace-match
989              (format "<img alt=\"AJ1-%05d\" src=\"%s/IVD/AdobeJapan1/CID+%d.png\"
990 style=\"vertical-align:middle\">"
991                      code
992                      chise-wiki-bitmap-glyphs-url
993                      code
994                      www-format-char-img-style)
995              t 'literal))
996
997           (goto-char (point-min))
998           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?MJ\\([0-9]+\\);" nil t)
999             (setq code (string-to-int (match-string 2)))
1000             (replace-match
1001              (format "<img alt=\"MJ%06d\" src=\"http://mojikiban.ipa.go.jp/search/MJ%06d\"
1002 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1003                      code
1004                      code
1005                      www-format-char-img-style)
1006              t 'literal))
1007
1008           (goto-char (point-min))
1009           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\)?IU[+-]\\([0-9A-F]+\\);" nil t)
1010             (setq code (string-to-int (match-string 2) 16))
1011             (replace-match
1012              (format "<img alt=\"u%04x\" src=\"http://glyphwiki.org/glyph/u%04x.100px.png\"
1013 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1014                      code
1015                      code
1016                      www-format-char-img-style)
1017              t 'literal))
1018
1019           (goto-char (point-min))
1020           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?U-i\\([0-9]+\\)\\+\\([0-9A-F]+\\);" nil t)
1021             (setq plane (string-to-int (match-string 2))
1022                   code (string-to-int (match-string 3) 16))
1023             (replace-match
1024              (format "<img alt=\"u%04x-itaiji-%03d\" src=\"http://glyphwiki.org/glyph/u%04x-itaiji-%03d.100px.png\"
1025 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1026                      code
1027                      plane
1028                      code
1029                      plane
1030                      www-format-char-img-style)
1031              t 'literal))
1032
1033           (goto-char (point-min))
1034           (while (re-search-forward "&\\(A-\\|G-\\|R-\\|g2-\\)?GT-\\([0-9]+\\);" nil t)
1035             (setq code (string-to-int (match-string 2)))
1036             (replace-match
1037              (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\"
1038 style=\"%s\">"
1039                      code
1040                      chise-wiki-glyph-cgi-url
1041                      code
1042                      www-format-char-img-style)
1043              t 'literal))
1044
1045           (goto-char (point-min))
1046           (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
1047             (setq code (string-to-int (match-string 2)))
1048             (replace-match
1049              (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\"
1050 style=\"%s\">"
1051                      code
1052                      chise-wiki-glyph-cgi-url
1053                      code
1054                      www-format-char-img-style)
1055              t 'literal))
1056
1057           (goto-char (point-min))
1058           (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
1059             (setq code (string-to-int (match-string 1) 16))
1060             (replace-match
1061              (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\"
1062 style=\"%s\">"
1063                      code
1064                      chise-wiki-glyph-cgi-url
1065                      code
1066                      www-format-char-img-style)
1067              t 'literal))
1068
1069           (goto-char (point-min))
1070           (while (re-search-forward "&\\(G-\\|g2-\\|R-\\)?CDP-\\([0-9A-F]+\\);" nil t)
1071             (setq code (string-to-int (match-string 2) 16))
1072             (replace-match
1073              (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\"
1074 style=\"%s\">"
1075                      code
1076                      chise-wiki-glyph-cgi-url
1077                      code
1078                      www-format-char-img-style)
1079              t 'literal))
1080
1081           (goto-char (point-min))
1082           (while (re-search-forward
1083                   "&\\(I-\\)?HZK\\(0[1-9]\\|1[0-2]\\)-\\([0-9A-F]+\\);" nil t)
1084             (setq plane (match-string 2)
1085                   code (string-to-int (match-string 3) 16))
1086             (replace-match
1087              (format "<img alt=\"HZK%s-%04X\" src=\"%s?char=HZK%s-%04X\"
1088 style=\"%s\">"
1089                      plane
1090                      code
1091                      chise-wiki-glyph-cgi-url
1092                      plane
1093                      code
1094                      www-format-char-img-style)
1095              t 'literal))
1096
1097           (goto-char (point-min))
1098           (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
1099             (setq code (string-to-int (match-string 1) 16))
1100             (replace-match
1101              (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\"
1102 style=\"vertical-align:middle\">"
1103                      code
1104                      chise-wiki-glyph-cgi-url
1105                      code
1106                      www-format-char-img-style)
1107              t 'literal))
1108
1109           (goto-char (point-min))
1110           (while (re-search-forward "&hanaJU\\+\\([0-9A-F]+\\);" nil t)
1111             (setq code (string-to-int (match-string 1) 16))
1112             (replace-match
1113              (format "<img alt=\"hanaJU+%04X\" src=\"%s?char=hana-JU+%04X\"
1114 style=\"vertical-align:middle\">"
1115                      code
1116                      chise-wiki-glyph-cgi-url
1117                      code
1118                      www-format-char-img-style)
1119              t 'literal))
1120
1121           (goto-char (point-min))
1122           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\|R-\\)?\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
1123             (setq code (string-to-int (match-string 3) 16))
1124             (replace-match
1125              (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\"
1126 style=\"vertical-align:middle\">"
1127                      code
1128                      code
1129                      www-format-char-img-style)
1130              t 'literal))
1131
1132           (goto-char (point-min))
1133           (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
1134             (setq code (string-to-int (match-string 1) 16))
1135             (setq start (match-beginning 0)
1136                   end (match-end 0))
1137             (setq char (decode-char 'system-char-id code))
1138             (cond
1139              ((and (setq variants
1140                          (or (www-get-feature-value char '->subsumptive)
1141                              (www-get-feature-value char '->denotational)))
1142                    (progn
1143                      (while (and variants
1144                                  (setq ret (www-format-encode-string
1145                                             (char-to-string (car variants))))
1146                                  (string-match "&MCS-\\([0-9A-F]+\\);" ret))
1147                        (setq variants (cdr variants)))
1148                      ret))
1149               (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
1150                 (goto-char start)
1151                 (delete-region start end)
1152                 (insert ret))
1153               )
1154              ((setq ret (or (www-get-feature-value char 'ideographic-combination)
1155                             (www-get-feature-value char 'ideographic-structure)))
1156               (setq ret
1157                     (mapconcat
1158                      (lambda (ch)
1159                        (if (listp ch)
1160                            (if (characterp (setq rret (find-char ch)))
1161                                (setq ch rret)))
1162                        (if (characterp ch)
1163                            (www-format-encode-string
1164                             (char-to-string ch) without-tags)
1165                          (www-format-encode-string
1166                           (format "%S" ch) without-tags)))
1167                      ret ""))
1168               (when ret
1169                 (goto-char start)
1170                 (delete-region start end)
1171                 (insert ret))
1172               )))
1173           ))
1174       ;; (goto-char (point-min))
1175       ;; (while (search-forward "&GT-" nil t)
1176       ;;   (replace-match "&amp;GT-" t 'literal))
1177       (buffer-string))))
1178
1179 (defun www-html-display-text (text)
1180   (princ
1181    (with-temp-buffer
1182      (insert text)
1183      (goto-char (point-min))
1184      (while (search-forward "<" nil t)
1185        (replace-match "&lt;" nil t))
1186      (goto-char (point-min))
1187      (while (search-forward ">" nil t)
1188        (replace-match "&gt;" nil t))
1189      (goto-char (point-min))
1190      (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1191        (replace-match
1192         (format "<a href=\"%s\">%s</a>"
1193                 (match-string 2)
1194                 (match-string 1))
1195         nil t))
1196      (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1197      (goto-char (point-min))
1198      (while (search-forward "&GT-" nil t)
1199        (replace-match "&amp;GT-" nil t))
1200      (buffer-string))))
1201
1202 (defun www-html-display-paragraph (text)
1203   (princ "<p>")
1204   (www-html-display-text text)
1205   (princ "</p>\n"))
1206
1207
1208 ;;; @ for GlyphWiki
1209 ;;;
1210
1211 (defvar coded-charset-GlyphWiki-id-alist
1212   '((=ucs-var-001       "u"     4 x "-var-001")
1213     (=ucs-var-002       "u"     4 x "-var-002")
1214     (=ucs-var-003       "u"     4 x "-var-003")
1215     (=ucs-itaiji-001    "u"     4 x "-itaiji-001")
1216     (=ucs-itaiji-002    "u"     4 x "-itaiji-002")
1217     (=ucs-itaiji-003    "u"     4 x "-itaiji-003")
1218     (=ucs-itaiji-084    "u"     4 x "-itaiji-084")
1219     (=adobe-japan1-0    "aj1-"  5 d nil)
1220     (=adobe-japan1-1    "aj1-"  5 d nil)
1221     (=adobe-japan1-2    "aj1-"  5 d nil)
1222     (=adobe-japan1-3    "aj1-"  5 d nil)
1223     (=adobe-japan1-4    "aj1-"  5 d nil)
1224     (=adobe-japan1-5    "aj1-"  5 d nil)
1225     (=adobe-japan1-6    "aj1-"  5 d nil)
1226     (==adobe-japan1-0   "aj1-"  5 d nil)
1227     (==adobe-japan1-1   "aj1-"  5 d nil)
1228     (==adobe-japan1-2   "aj1-"  5 d nil)
1229     (==adobe-japan1-3   "aj1-"  5 d nil)
1230     (==adobe-japan1-4   "aj1-"  5 d nil)
1231     (==adobe-japan1-5   "aj1-"  5 d nil)
1232     (==adobe-japan1-6   "aj1-"  5 d nil)
1233     (===adobe-japan1-0  "aj1-"  5 d nil)
1234     (===adobe-japan1-1  "aj1-"  5 d nil)
1235     (===adobe-japan1-2  "aj1-"  5 d nil)
1236     (===adobe-japan1-3  "aj1-"  5 d nil)
1237     (===adobe-japan1-4  "aj1-"  5 d nil)
1238     (===adobe-japan1-5  "aj1-"  5 d nil)
1239     (===adobe-japan1-6  "aj1-"  5 d nil)
1240     (=decomposition@cid)
1241     (=decomposition@hanyo-denshi)
1242     (=hanyo-denshi/ks   "koseki-" 6 d nil)
1243     (=>>hanyo-denshi/ks "koseki-" 6 d nil)
1244     (=koseki            "koseki-" 6 d nil)
1245     (=ucs@jis           "u"     4 x nil)
1246     (==ucs@jis          "u"     4 x nil)
1247     (==ucs@iso          "u"     4 x nil)
1248     (===ucs@jis         "u"     4 x nil)
1249     (=ucs@cns           "u"     4 x "-t")
1250     (==ucs@cns          "u"     4 x "-t")
1251     (=jis-x0212         "jsp-"  4 x nil)
1252     (=jis-x0213-1@2000  "jx1-2000-" 4 x nil)
1253     (=jis-x0213-1@2004  "jx1-2004-" 4 x nil)
1254     (=jis-x0213-2       "jx2-"  4 x nil)
1255     (=gt                "gt-"   5 d nil)
1256     (=daikanwa          "dkw-"  5 d nil)
1257     (==daikanwa         "dkw-"  5 d nil)
1258     (===daikanwa        "dkw-"  5 d nil)
1259     (=gt-k              "gt-k"  5 d nil)
1260     (=jef-china3        "jc3-"  4 x nil)
1261     (=big5              "b-"    4 x nil)
1262     (=ucs@ks            "u"     4 x "-k")
1263     (==ucs@ks           "u"     4 x "-k")
1264     (===ucs@ks          "u"     4 x "-k")
1265     (=ks-x1001          "k0-"   4 x nil)
1266     (=jis-x0208@1978/1pr "j78-" 4 x nil)
1267     (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1268     (=jis-x0208@1978    "j78-"  4 x nil)
1269     (=>>>jis-x0208@1978 "j78-"  4 x nil)
1270     (=>>jis-x0208@1978  "j78-"  4 x nil)
1271     (=+>jis-x0208@1978  "j78-"  4 x nil)
1272     (=ucs@JP            "u"     4 x nil)
1273     (=ucs@gb            "u"     4 x "-g")
1274     (=ucs@iso           "u"     4 x "-u")
1275     (=ucs@unicode       "u"     4 x "-us")
1276     (=big5-cdp          "cdp-"  4 x nil)
1277     (=>>big5-cdp        "cdp-"  4 x nil)
1278     (=cns11643-1        "c1-"   4 x nil)
1279     (=cns11643-2        "c2-"   4 x nil)
1280     (=cns11643-3        "c3-"   4 x nil)
1281     (=cns11643-4        "c4-"   4 x nil)
1282     (=cns11643-5        "c5-"   4 x nil)
1283     (=cns11643-6        "c6-"   4 x nil)
1284     (=cns11643-7        "c7-"   4 x nil)
1285     (=jis-x0208         "j90-"  4 x nil)
1286     (=>>>jis-x0208      "j90-"  4 x nil)
1287     (=>>jis-x0208       "j90-"  4 x nil)
1288     (=+>jis-x0208       "j90-"  4 x nil)
1289     (=jis-x0208@1990    "j90-"  4 x nil)
1290     (=>>>jis-x0208@1990 "j90-"  4 x nil)
1291     (=>>jis-x0208@1990  "j90-"  4 x nil)
1292     (=+>jis-x0208@1990  "j90-"  4 x nil)
1293     (=jis-x0208@1983    "j83-"  4 x nil)
1294     (=>>>jis-x0208@1983 "j83-"  4 x nil)
1295     (=>>jis-x0208@1983  "j83-"  4 x nil)
1296     (=+>jis-x0208@1983  "j83-"  4 x nil)
1297     (=cbeta             "cb"    5 d nil)
1298     (=>>daikanwa        "dkw-"  5 d nil)
1299     (=big5-cdp-var-3    "cdp-"  4 x "-var-3")
1300     (=big5-cdp-var-5    "cdp-"  4 x "-var-5")
1301     (=ucs               "u"     4 x nil)
1302     ))
1303
1304 (defun char-GlyphWiki-id (char)
1305   (let ((rest coded-charset-GlyphWiki-id-alist)
1306         spec ret code)
1307     (while (and rest
1308                 (setq spec (pop rest))
1309                 (null (setq ret (char-feature char (car spec))))))
1310     (when ret
1311       (or
1312        (and (listp ret)
1313             (mapconcat #'char-GlyphWiki-id ret "-"))
1314        (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1315             (cond
1316              ((and (or (encode-char char '=jis-x0208@1990)
1317                        (encode-char char '=jis-x0212)
1318                        (encode-char char '=jis-x0213-1)
1319                        (encode-char char '=jis-x0213-2))
1320                    (setq code (encode-char char '=ucs@jis)))
1321               (format "u%04x" code)
1322               )
1323              ((and (or (encode-char char '=gb2312)
1324                        (encode-char char '=gb12345))
1325                    (setq code (encode-char char '=ucs@gb)))
1326               (format "u%04x-g" code)
1327               )
1328              ((and (or (encode-char char '=cns11643-1)
1329                        (encode-char char '=cns11643-2)
1330                        (encode-char char '=cns11643-3)
1331                        (encode-char char '=cns11643-4)
1332                        (encode-char char '=cns11643-5)
1333                        (encode-char char '=cns11643-6)
1334                        (encode-char char '=cns11643-7))
1335                    (setq code (encode-char char '=ucs@cns)))
1336               (format "u%04x-t" code)
1337               )
1338              ((and (encode-char char '=ks-x1001)
1339                    (setq code (encode-char char '=ucs@ks)))
1340               (format "u%04x-k" code)
1341               )))
1342        (format (format "%s%%0%d%s%s"
1343                        (nth 1 spec)
1344                        (nth 2 spec)
1345                        (nth 3 spec)
1346                        (or (nth 4 spec) ""))
1347                ret)))))
1348
1349
1350 ;;; @ End.
1351 ;;;
1352
1353 (provide 'cwiki-common)
1354
1355 ;;; cwiki-common.el ends here