(www-format-encode-string):
[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                 '(=hanyo-denshi/ja   "HD-JA-" 4 X)
758                 '(=hanyo-denshi/jb   "HD-JB-" 4 X)
759                 '(=hanyo-denshi/jc   "HD-JC-" 4 X)
760                 '(=hanyo-denshi/jd   "HD-JD-" 4 X)
761                 '(=hanyo-denshi/ft   "HD-FT-" 4 X)
762                 '(=hanyo-denshi/ia   "HD-IA-" 4 X)
763                 '(=hanyo-denshi/ib   "HD-IB-" 4 X)
764                 '(=hanyo-denshi/hg   "HD-HG-" 4 X)
765                 '(=hanyo-denshi/ip   "HD-IP-" 4 X)
766                 '(=hanyo-denshi/jt   "HD-JT-" 4 X)
767                 '(=hanyo-denshi/ks   "HD-KS-" 6 d)
768                 '(=>>hanyo-denshi/ja "G-HD-JA-" 4 X)
769                 '(=>>hanyo-denshi/jb "G-HD-JB-" 4 X)
770                 '(=>>hanyo-denshi/jc "G-HD-JC-" 4 X)
771                 '(=>>hanyo-denshi/jd "G-HD-JD-" 4 X)
772                 '(=>>hanyo-denshi/ft "G-HD-FT-" 4 X)
773                 '(=>>hanyo-denshi/ia "G-HD-IA-" 4 X)
774                 '(=>>hanyo-denshi/ib "G-HD-IB-" 4 X)
775                 '(=>>hanyo-denshi/hg "G-HD-HG-" 4 X)
776                 '(=>>hanyo-denshi/ip "G-HD-IP-" 4 X)
777                 '(=>>hanyo-denshi/jt "G-HD-JT-" 4 X)
778                 '(=>>hanyo-denshi/ks "G-HD-KS-" 6 d)
779                 '(==hanyo-denshi/ja "g2-HD-JA-" 4 X)
780                 '(==hanyo-denshi/jb "g2-HD-JB-" 4 X)
781                 '(==hanyo-denshi/jc "g2-HD-JC-" 4 X)
782                 '(==hanyo-denshi/jd "g2-HD-JD-" 4 X)
783                 '(==hanyo-denshi/ft "g2-HD-FT-" 4 X)
784                 '(==hanyo-denshi/ia "g2-HD-IA-" 4 X)
785                 '(==hanyo-denshi/ib "g2-HD-IB-" 4 X)
786                 '(==hanyo-denshi/hg "g2-HD-HG-" 4 X)
787                 '(==hanyo-denshi/ip "g2-HD-IP-" 4 X)
788                 '(==hanyo-denshi/jt "g2-HD-JT-" 4 X)
789                 '(==hanyo-denshi/ks "g2-HD-KS-" 6 d)
790                 '(=cns11643-1           "C1-" 4 X)
791                 '(=cns11643-2           "C2-" 4 X)
792                 '(=cns11643-3           "C3-" 4 X)
793                 '(=cns11643-4           "C4-" 4 X)
794                 '(=cns11643-5           "C5-" 4 X)
795                 '(=cns11643-6           "C6-" 4 X)
796                 '(=cns11643-7           "C7-" 4 X)
797                 '(=adobe-japan1-6       "AJ1-" 5 d)
798                 '(=big5-cdp             "CDP-" 4 X)
799                 '(=gb2312               "G0-" 4 X)
800                 '(=gb12345              "G1-" 4 X)
801                 '(=jis-x0208@1990       "J90-" 4 X)
802                 '(=jis-x0212            "JSP-" 4 X)
803                 '(=cbeta                "CB" 5 d)
804                 '(=jis-x0208@1997       "J97-" 4 X)
805                 '(=jis-x0208@1978       "J78-" 4 X)
806                 '(=jis-x0208@1983       "J83-" 4 X)
807                 '(=ruimoku-v6           "RUI6-" 4 X)
808                 '(=zinbun-oracle        "ZOB-" 4 d)
809                 '(=jef-china3           "JC3-" 4 X)
810                 '(=ucs@unicode          "UU+" 4 X)
811                 '(=ucs@JP/hanazono  "hanaJU+" 4 X)
812                 '(==cns11643-1        "R-C1-" 4 X)
813                 '(==cns11643-2        "R-C2-" 4 X)
814                 '(==cns11643-3        "R-C3-" 4 X)
815                 '(==cns11643-4        "R-C4-" 4 X)
816                 '(==cns11643-5        "R-C5-" 4 X)
817                 '(==cns11643-6        "R-C6-" 4 X)
818                 '(==cns11643-7        "R-C7-" 4 X)
819                 '(=hanziku-1         "HZK01-" 4 X)
820                 '(=hanziku-2         "HZK02-" 4 X)
821                 '(=hanziku-3         "HZK03-" 4 X)
822                 '(=hanziku-4         "HZK04-" 4 X)
823                 '(=hanziku-5         "HZK05-" 4 X)
824                 '(=hanziku-6         "HZK06-" 4 X)
825                 '(=hanziku-7         "HZK07-" 4 X)
826                 '(=hanziku-8         "HZK08-" 4 X)
827                 '(=hanziku-9         "HZK09-" 4 X)
828                 '(=hanziku-10        "HZK10-" 4 X)
829                 '(=hanziku-11        "HZK11-" 4 X)
830                 '(=hanziku-12        "HZK12-" 4 X)
831                 '(=big5                  "B-" 4 X)
832                 '(=daikanwa              "M-" 5 d)
833                 coded-charset-entity-reference-alist)))
834           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
835
836           (goto-char (point-min))
837           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\)?CB\\([0-9]+\\);" nil t)
838             (setq code (string-to-int (match-string 2)))
839             (replace-match
840              (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\"
841 style=\"%s\">"
842                      code
843                      chise-wiki-bitmap-glyphs-url
844                      (/ code 1000) code
845                      www-format-char-img-style)
846              t 'literal))
847
848           (goto-char (point-min))
849           (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)
850             (setq plane (match-string 2)
851                   code (string-to-int (match-string 3) 16))
852             (replace-match
853              (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\"
854 style=\"%s\">"
855                      plane code
856                      chise-wiki-bitmap-glyphs-url
857                      plane
858                      (- (lsh code -8) 32)
859                      (- (logand code 255) 32)
860                      www-format-char-img-style)
861              t 'literal))
862
863           (goto-char (point-min))
864           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?J0-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
865             (setq code (string-to-int (match-string 2) 16))
866             (replace-match
867              (format "<img alt=\"J0-%04X\" src=\"%s/JIS-90/%02d-%02d.gif\"
868 style=\"%s\">"
869                      code
870                      chise-wiki-bitmap-glyphs-url
871                      (- (lsh code -8) 32)
872                      (- (logand code 255) 32)
873                      www-format-char-img-style)
874              t 'literal))
875
876           (goto-char (point-min))
877           (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)
878             (setq plane (match-string 2)
879                   code (string-to-int (match-string 3) 16))
880             (replace-match
881              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%02d%02d.png\"
882 style=\"%s\">"
883                      plane code
884                      chise-wiki-bitmap-glyphs-url
885                      plane
886                      (- (lsh code -8) 32)
887                      (- (logand code 255) 32)
888                      www-format-char-img-style)
889              t 'literal))
890
891           (goto-char (point-min))
892           (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)
893             (setq plane (match-string 2)
894                   code (string-to-int (match-string 3) 16))
895             (replace-match
896              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%04X.png\"
897 style=\"%s\">"
898                      plane code
899                      chise-wiki-bitmap-glyphs-url
900                      plane code
901                      www-format-char-img-style)
902              t 'literal))
903
904           (goto-char (point-min))
905           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-KS-\\([0-9]+\\);" nil t)
906             (setq code (string-to-int (match-string 2)))
907             (replace-match
908              (format "<img alt=\"HD-KS%06d\" src=\"%s/IVD/HanyoDenshi/KS%06d.png\"
909 style=\"vertical-align:middle\">"
910                      code
911                      chise-wiki-bitmap-glyphs-url
912                      code
913                      www-format-char-img-style)
914              t 'literal))
915
916           (goto-char (point-min))
917           (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
918             (setq plane (string-to-int (match-string 1))
919                   code (string-to-int (match-string 2) 16))
920             (replace-match
921              (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\"
922 style=\"%s\">"
923                      plane code
924                      chise-wiki-bitmap-glyphs-url
925                      plane
926                      (- (lsh code -8) 32)
927                      (- (logand code 255) 32)
928                      www-format-char-img-style)
929              t 'literal))
930
931           (goto-char (point-min))
932           (while (re-search-forward "&\\(R-\\)?C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
933             (setq plane (string-to-int (match-string 2))
934                   code (string-to-int (match-string 3) 16))
935             (replace-match
936              (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\"
937 style=\"%s\">"
938                      plane code
939                      chise-wiki-bitmap-glyphs-url
940                      plane code
941                      www-format-char-img-style)
942              t 'literal))
943
944           (goto-char (point-min))
945           (while (re-search-forward "&\\(R-\\)?JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
946             (setq code (string-to-int (match-string 2) 16))
947             (replace-match
948              (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
949                      code code)
950              t 'literal))
951
952           (goto-char (point-min))
953           (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
954             (setq code (string-to-int (match-string 2)))
955             (replace-match
956              (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\"
957 style=\"vertical-align:middle\">"
958                      code
959                      chise-wiki-bitmap-glyphs-url
960                      code
961                      www-format-char-img-style)
962              t 'literal))
963
964           (goto-char (point-min))
965           (while (re-search-forward "&HNG\\([0-9]+\\)-\\([0-9][0-9][0-9][0-9]\\)\\([0-9]\\);" nil t)
966             (setq plane (match-string 1)
967                   code (string-to-int (match-string 2))
968                   subcode (string-to-int (match-string 3)))
969             (setq subcode
970                   (if (eq subcode 0)
971                       ""
972                     (char-to-string (decode-char 'ascii (+ 96 subcode)))))
973             (replace-match
974              (format
975               "<img alt=\"HNG%s-%04d%s\" src=\"%s/%s/%04d%s.png\"
976 style=\"vertical-align:middle; width: 48px; height: 48px\">"
977               plane code subcode
978               chise-wiki-hng-bitmap-glyphs-url
979               plane code subcode
980               www-format-char-img-style)
981              t 'literal))
982
983           (goto-char (point-min))
984           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?AJ1-\\([0-9]+\\);" nil t)
985             (setq code (string-to-int (match-string 2)))
986             (replace-match
987              (format "<img alt=\"AJ1-%05d\" src=\"%s/IVD/AdobeJapan1/CID+%d.png\"
988 style=\"vertical-align:middle\">"
989                      code
990                      chise-wiki-bitmap-glyphs-url
991                      code
992                      www-format-char-img-style)
993              t 'literal))
994
995           (goto-char (point-min))
996           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?MJ\\([0-9]+\\);" nil t)
997             (setq code (string-to-int (match-string 2)))
998             (replace-match
999              (format "<img alt=\"MJ%06d\" src=\"http://mojikiban.ipa.go.jp/search/MJ%06d\"
1000 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1001                      code
1002                      code
1003                      www-format-char-img-style)
1004              t 'literal))
1005
1006           (goto-char (point-min))
1007           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\)?IU[+-]\\([0-9A-F]+\\);" nil t)
1008             (setq code (string-to-int (match-string 2) 16))
1009             (replace-match
1010              (format "<img alt=\"u%04x\" src=\"http://glyphwiki.org/glyph/u%04x.100px.png\"
1011 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1012                      code
1013                      code
1014                      www-format-char-img-style)
1015              t 'literal))
1016
1017           (goto-char (point-min))
1018           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?U-i\\([0-9]+\\)\\+\\([0-9A-F]+\\);" nil t)
1019             (setq plane (string-to-int (match-string 2))
1020                   code (string-to-int (match-string 3) 16))
1021             (replace-match
1022              (format "<img alt=\"u%04x-itaiji-%03d\" src=\"http://glyphwiki.org/glyph/u%04x-itaiji-%03d.100px.png\"
1023 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1024                      code
1025                      plane
1026                      code
1027                      plane
1028                      www-format-char-img-style)
1029              t 'literal))
1030
1031           (goto-char (point-min))
1032           (while (re-search-forward "&\\(A-\\|G-\\|R-\\|g2-\\)?GT-\\([0-9]+\\);" nil t)
1033             (setq code (string-to-int (match-string 2)))
1034             (replace-match
1035              (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\"
1036 style=\"%s\">"
1037                      code
1038                      chise-wiki-glyph-cgi-url
1039                      code
1040                      www-format-char-img-style)
1041              t 'literal))
1042
1043           (goto-char (point-min))
1044           (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
1045             (setq code (string-to-int (match-string 2)))
1046             (replace-match
1047              (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\"
1048 style=\"%s\">"
1049                      code
1050                      chise-wiki-glyph-cgi-url
1051                      code
1052                      www-format-char-img-style)
1053              t 'literal))
1054
1055           (goto-char (point-min))
1056           (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
1057             (setq code (string-to-int (match-string 1) 16))
1058             (replace-match
1059              (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\"
1060 style=\"%s\">"
1061                      code
1062                      chise-wiki-glyph-cgi-url
1063                      code
1064                      www-format-char-img-style)
1065              t 'literal))
1066
1067           (goto-char (point-min))
1068           (while (re-search-forward "&\\(G-\\|g2-\\|R-\\)?CDP-\\([0-9A-F]+\\);" nil t)
1069             (setq code (string-to-int (match-string 2) 16))
1070             (replace-match
1071              (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\"
1072 style=\"%s\">"
1073                      code
1074                      chise-wiki-glyph-cgi-url
1075                      code
1076                      www-format-char-img-style)
1077              t 'literal))
1078
1079           (goto-char (point-min))
1080           (while (re-search-forward
1081                   "&\\(I-\\)?HZK\\(0[1-9]\\|1[0-2]\\)-\\([0-9A-F]+\\);" nil t)
1082             (setq plane (match-string 2)
1083                   code (string-to-int (match-string 3) 16))
1084             (replace-match
1085              (format "<img alt=\"HZK%s-%04X\" src=\"%s?char=HZK%s-%04X\"
1086 style=\"%s\">"
1087                      plane
1088                      code
1089                      chise-wiki-glyph-cgi-url
1090                      plane
1091                      code
1092                      www-format-char-img-style)
1093              t 'literal))
1094
1095           (goto-char (point-min))
1096           (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
1097             (setq code (string-to-int (match-string 1) 16))
1098             (replace-match
1099              (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\"
1100 style=\"vertical-align:middle\">"
1101                      code
1102                      chise-wiki-glyph-cgi-url
1103                      code
1104                      www-format-char-img-style)
1105              t 'literal))
1106
1107           (goto-char (point-min))
1108           (while (re-search-forward "&hanaJU\\+\\([0-9A-F]+\\);" nil t)
1109             (setq code (string-to-int (match-string 1) 16))
1110             (replace-match
1111              (format "<img alt=\"hanaJU+%04X\" src=\"%s?char=hana-JU+%04X\"
1112 style=\"vertical-align:middle\">"
1113                      code
1114                      chise-wiki-glyph-cgi-url
1115                      code
1116                      www-format-char-img-style)
1117              t 'literal))
1118
1119           (goto-char (point-min))
1120           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\|R-\\)?\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
1121             (setq code (string-to-int (match-string 3) 16))
1122             (replace-match
1123              (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\"
1124 style=\"vertical-align:middle\">"
1125                      code
1126                      code
1127                      www-format-char-img-style)
1128              t 'literal))
1129
1130           (goto-char (point-min))
1131           (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
1132             (setq code (string-to-int (match-string 1) 16))
1133             (setq start (match-beginning 0)
1134                   end (match-end 0))
1135             (setq char (decode-char 'system-char-id code))
1136             (cond
1137              ((and (setq variants
1138                          (or (www-get-feature-value char '->subsumptive)
1139                              (www-get-feature-value char '->denotational)))
1140                    (progn
1141                      (while (and variants
1142                                  (setq ret (www-format-encode-string
1143                                             (char-to-string (car variants))))
1144                                  (string-match "&MCS-\\([0-9A-F]+\\);" ret))
1145                        (setq variants (cdr variants)))
1146                      ret))
1147               (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
1148                 (goto-char start)
1149                 (delete-region start end)
1150                 (insert ret))
1151               )
1152              ((setq ret (or (www-get-feature-value char 'ideographic-combination)
1153                             (www-get-feature-value char 'ideographic-structure)))
1154               (setq ret
1155                     (mapconcat
1156                      (lambda (ch)
1157                        (if (listp ch)
1158                            (if (characterp (setq rret (find-char ch)))
1159                                (setq ch rret)))
1160                        (if (characterp ch)
1161                            (www-format-encode-string
1162                             (char-to-string ch) without-tags)
1163                          (www-format-encode-string
1164                           (format "%S" ch) without-tags)))
1165                      ret ""))
1166               (when ret
1167                 (goto-char start)
1168                 (delete-region start end)
1169                 (insert ret))
1170               )))
1171           ))
1172       ;; (goto-char (point-min))
1173       ;; (while (search-forward "&GT-" nil t)
1174       ;;   (replace-match "&amp;GT-" t 'literal))
1175       (buffer-string))))
1176
1177 (defun www-html-display-text (text)
1178   (princ
1179    (with-temp-buffer
1180      (insert text)
1181      (goto-char (point-min))
1182      (while (search-forward "<" nil t)
1183        (replace-match "&lt;" nil t))
1184      (goto-char (point-min))
1185      (while (search-forward ">" nil t)
1186        (replace-match "&gt;" nil t))
1187      (goto-char (point-min))
1188      (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1189        (replace-match
1190         (format "<a href=\"%s\">%s</a>"
1191                 (match-string 2)
1192                 (match-string 1))
1193         nil t))
1194      (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1195      (goto-char (point-min))
1196      (while (search-forward "&GT-" nil t)
1197        (replace-match "&amp;GT-" nil t))
1198      (buffer-string))))
1199
1200 (defun www-html-display-paragraph (text)
1201   (princ "<p>")
1202   (www-html-display-text text)
1203   (princ "</p>\n"))
1204
1205
1206 ;;; @ for GlyphWiki
1207 ;;;
1208
1209 (defvar coded-charset-GlyphWiki-id-alist
1210   '((=ucs-var-001       "u"     4 x "-var-001")
1211     (=ucs-var-002       "u"     4 x "-var-002")
1212     (=ucs-var-003       "u"     4 x "-var-003")
1213     (=ucs-itaiji-001    "u"     4 x "-itaiji-001")
1214     (=ucs-itaiji-002    "u"     4 x "-itaiji-002")
1215     (=ucs-itaiji-003    "u"     4 x "-itaiji-003")
1216     (=ucs-itaiji-084    "u"     4 x "-itaiji-084")
1217     (=ucs               "u"     4 x nil)
1218     (=adobe-japan1-0    "aj1-"  5 d nil)
1219     (=adobe-japan1-1    "aj1-"  5 d nil)
1220     (=adobe-japan1-2    "aj1-"  5 d nil)
1221     (=adobe-japan1-3    "aj1-"  5 d nil)
1222     (=adobe-japan1-4    "aj1-"  5 d nil)
1223     (=adobe-japan1-5    "aj1-"  5 d nil)
1224     (=adobe-japan1-6    "aj1-"  5 d nil)
1225     (==adobe-japan1-0   "aj1-"  5 d nil)
1226     (==adobe-japan1-1   "aj1-"  5 d nil)
1227     (==adobe-japan1-2   "aj1-"  5 d nil)
1228     (==adobe-japan1-3   "aj1-"  5 d nil)
1229     (==adobe-japan1-4   "aj1-"  5 d nil)
1230     (==adobe-japan1-5   "aj1-"  5 d nil)
1231     (==adobe-japan1-6   "aj1-"  5 d nil)
1232     (===adobe-japan1-0  "aj1-"  5 d nil)
1233     (===adobe-japan1-1  "aj1-"  5 d nil)
1234     (===adobe-japan1-2  "aj1-"  5 d nil)
1235     (===adobe-japan1-3  "aj1-"  5 d nil)
1236     (===adobe-japan1-4  "aj1-"  5 d nil)
1237     (===adobe-japan1-5  "aj1-"  5 d nil)
1238     (===adobe-japan1-6  "aj1-"  5 d nil)
1239     (=decomposition@cid)
1240     (=decomposition@hanyo-denshi)
1241     (=hanyo-denshi/ks   "koseki-" 6 d nil)
1242     (=>>hanyo-denshi/ks "koseki-" 6 d nil)
1243     (=koseki            "koseki-" 6 d nil)
1244     (=ucs@jis           "u"     4 x nil)
1245     (==ucs@jis          "u"     4 x nil)
1246     (==ucs@iso          "u"     4 x nil)
1247     (===ucs@jis         "u"     4 x nil)
1248     (=ucs@cns           "u"     4 x "-t")
1249     (==ucs@cns          "u"     4 x "-t")
1250     (=jis-x0212         "jsp-"  4 x nil)
1251     (=jis-x0213-1@2000  "jx1-2000-" 4 x nil)
1252     (=jis-x0213-1@2004  "jx1-2004-" 4 x nil)
1253     (=jis-x0213-2       "jx2-"  4 x nil)
1254     (=gt                "gt-"   5 d nil)
1255     (=daikanwa          "dkw-"  5 d nil)
1256     (==daikanwa         "dkw-"  5 d nil)
1257     (===daikanwa        "dkw-"  5 d nil)
1258     (=gt-k              "gt-k"  5 d nil)
1259     (=jef-china3        "jc3-"  4 x nil)
1260     (=big5              "b-"    4 x nil)
1261     (=ucs@ks            "u"     4 x "-k")
1262     (==ucs@ks           "u"     4 x "-k")
1263     (===ucs@ks          "u"     4 x "-k")
1264     (=ks-x1001          "k0-"   4 x nil)
1265     (=jis-x0208@1978/1pr "j78-" 4 x nil)
1266     (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1267     (=jis-x0208@1978    "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     (=ucs@JP            "u"     4 x nil)
1272     (=ucs@gb            "u"     4 x "-g")
1273     (=ucs@iso           "u"     4 x "-u")
1274     (=ucs@unicode       "u"     4 x "-us")
1275     (=big5-cdp          "cdp-"  4 x nil)
1276     (=>>big5-cdp        "cdp-"  4 x nil)
1277     (=cns11643-1        "c1-"   4 x nil)
1278     (=cns11643-2        "c2-"   4 x nil)
1279     (=cns11643-3        "c3-"   4 x nil)
1280     (=cns11643-4        "c4-"   4 x nil)
1281     (=cns11643-5        "c5-"   4 x nil)
1282     (=cns11643-6        "c6-"   4 x nil)
1283     (=cns11643-7        "c7-"   4 x nil)
1284     (=jis-x0208         "j90-"  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@1990    "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@1983    "j83-"  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     (=cbeta             "cb"    5 d nil)
1297     (=>>daikanwa        "dkw-"  5 d nil)
1298     (=big5-cdp-var-3    "cdp-"  4 x "-var-3")
1299     (=big5-cdp-var-5    "cdp-"  4 x "-var-5")
1300     ))
1301
1302 (defun char-GlyphWiki-id (char)
1303   (let ((rest coded-charset-GlyphWiki-id-alist)
1304         spec ret code)
1305     (while (and rest
1306                 (setq spec (pop rest))
1307                 (null (setq ret (char-feature char (car spec))))))
1308     (when ret
1309       (or
1310        (and (listp ret)
1311             (mapconcat #'char-GlyphWiki-id ret "-"))
1312        (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1313             (cond
1314              ((and (or (encode-char char '=jis-x0208@1990)
1315                        (encode-char char '=jis-x0212)
1316                        (encode-char char '=jis-x0213-1)
1317                        (encode-char char '=jis-x0213-2))
1318                    (setq code (encode-char char '=ucs@jis)))
1319               (format "u%04x" code)
1320               )
1321              ((and (or (encode-char char '=gb2312)
1322                        (encode-char char '=gb12345))
1323                    (setq code (encode-char char '=ucs@gb)))
1324               (format "u%04x-g" code)
1325               )
1326              ((and (or (encode-char char '=cns11643-1)
1327                        (encode-char char '=cns11643-2)
1328                        (encode-char char '=cns11643-3)
1329                        (encode-char char '=cns11643-4)
1330                        (encode-char char '=cns11643-5)
1331                        (encode-char char '=cns11643-6)
1332                        (encode-char char '=cns11643-7))
1333                    (setq code (encode-char char '=ucs@cns)))
1334               (format "u%04x-t" code)
1335               )
1336              ((and (encode-char char '=ks-x1001)
1337                    (setq code (encode-char char '=ucs@ks)))
1338               (format "u%04x-k" code)
1339               )))
1340        (format (format "%s%%0%d%s%s"
1341                        (nth 1 spec)
1342                        (nth 2 spec)
1343                        (nth 3 spec)
1344                        (or (nth 4 spec) ""))
1345                ret)))))
1346
1347
1348 ;;; @ End.
1349 ;;;
1350
1351 (provide 'cwiki-common)
1352
1353 ;;; cwiki-common.el ends here