1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'char-db-util)
4 (defvar chise-wiki-view-url "view.cgi")
5 (defvar chise-wiki-edit-url "edit.cgi")
7 (defvar chise-wiki-bitmap-glyphs-url
8 "http://chise.zinbun.kyoto-u.ac.jp/glyphs")
10 (defvar chise-wiki-glyph-cgi-url
11 "http://chise.zinbun.kyoto-u.ac.jp/chisewiki/glyph.cgi")
13 (defvar chise-wiki-displayed-features nil)
15 (defun decode-uri-string (string &optional coding-system)
16 (if (> (length string) 0)
20 (mapconcat (lambda (char)
23 (char-to-string char)))
25 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
26 (setq dest (concat dest
27 (substring string i (match-beginning 0))
30 (string-to-int (match-string 1 string) 16))))
33 (concat dest (substring string i))
36 (defun www-feature-type (feature-name)
37 (or (char-feature-property feature-name 'type)
38 (let ((str (symbol-name feature-name)))
40 ((string-match "\\*note\\(@[^*]+\\)?$" str)
42 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
44 ((string-match "\\*" str)
46 ((string-match "^\\(->\\|<-\\)" str)
48 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
52 (defun www-feature-format (feature-name)
53 (or (char-feature-property feature-name 'format)
55 (setq fn feature-name)
56 (while (and (setq parent (char-feature-name-parent fn))
58 (char-feature-property
62 '((name) " : " (value))))
64 (defun www-feature-value-format (feature-name)
65 (or (char-feature-property feature-name 'value-format)
67 (setq fn feature-name)
68 (while (and (setq parent (char-feature-name-parent fn))
70 (char-feature-property
71 parent 'value-format))))
74 (let ((type (www-feature-type feature-name)))
75 (cond ((eq type 'relation)
76 'space-separated-char-list)
82 (if (find-charset feature-name)
83 (if (and (= (charset-dimension feature-name) 2)
84 (= (charset-chars feature-name) 94))
86 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
87 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
89 (defun char-feature-name-at-domain (feature-name domain)
91 (let ((name (symbol-name feature-name)))
93 ((string-match "@[^*]+$" name)
94 (intern (format "%s/%s" name domain))
97 (intern (format "%s@%s" name domain))
101 (defun char-feature-name-parent (feature-name)
102 (let ((name (symbol-name feature-name)))
103 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
104 (intern (substring name 0 (car (last (match-data) 2)))))))
106 (defun char-feature-name-domain (feature-name)
107 (let ((name (symbol-name feature-name)))
108 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
109 (intern (substring name (1+ (match-beginning 0)))))))
111 (defun char-feature-name-sans-versions (feature)
112 (let ((feature-name (symbol-name feature)))
113 (if (string-match "[@/]\\$rev=latest$" feature-name)
114 (intern (substring feature-name 0 (match-beginning 0)))
117 (defun www-char-feature (character feature)
118 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
119 (mount-char-attribute-table latest-feature)
120 (or (char-feature character latest-feature)
121 (char-feature character feature))))
123 (defun get-previous-code-point (ccs code)
124 (let ((chars (charset-chars ccs))
125 (dim (charset-dimension ccs))
127 mask byte-min byte-max
150 (setq bytes (make-vector dim 0))
152 (aset bytes i (logand (lsh code (* i -8)) mask))
155 (while (and (< i dim)
157 (aset bytes i (1- (aref bytes i)))
158 (< (aref bytes i) byte-min)))
159 (aset bytes i byte-max)
162 (setq dest (aref bytes 0)
165 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
169 (defun get-next-code-point (ccs code)
170 (let ((chars (charset-chars ccs))
171 (dim (charset-dimension ccs))
173 mask byte-min byte-max
196 (setq bytes (make-vector dim 0))
198 (aset bytes i (logand (lsh code (* i -8)) mask))
201 (while (and (< i dim)
203 (aset bytes i (1+ (aref bytes i)))
204 (> (aref bytes i) byte-max)))
205 (aset bytes i byte-min)
208 (setq dest (aref bytes 0)
211 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
215 (defun find-previous-defined-code-point (ccs code)
216 (let ((i (get-previous-code-point ccs code))
219 ((eq ccs '=jis-x0208)
220 (setq ccs '=jis-x0208@1990))
221 ((eq ccs '=jis-x0213-1)
222 (setq ccs '=jis-x0213-1@2004)))
225 (null (setq char (decode-char ccs i
226 (unless (eq ccs '=ucs)
228 (setq i (get-previous-code-point ccs i)))
231 (defun find-next-defined-code-point (ccs code)
232 (let ((i (get-next-code-point ccs code))
234 (setq max (+ code 1000))
236 ((eq ccs '=jis-x0208)
237 (setq ccs '=jis-x0208@1990))
238 ((eq ccs '=jis-x0213-1)
239 (setq ccs '=jis-x0213-1@2004)))
242 (null (setq char (decode-char ccs i
243 (unless (eq ccs '=ucs)
245 (setq i (get-next-code-point ccs i)))
249 ;;; @ URI representation
252 (defun www-uri-decode-feature-name (uri-feature)
255 ((string-match "^from\\." uri-feature)
256 (intern (format "<-%s" (substring uri-feature (match-end 0))))
258 ((string-match "^to\\." uri-feature)
259 (intern (format "->%s" (substring uri-feature (match-end 0))))
261 ((string-match "^rep\\." uri-feature)
262 (intern (format "=%s" (substring uri-feature (match-end 0))))
264 ((string-match "^g\\." uri-feature)
265 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
267 ((string-match "^gi\\." uri-feature)
268 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
270 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
271 (intern (format "=>>%s%s"
272 (make-string (string-to-int
273 (match-string 1 uri-feature))
275 (substring uri-feature (match-end 0))))
277 ((string-match "^a\\." uri-feature)
278 (intern (format "=>%s" (substring uri-feature (match-end 0))))
280 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
281 (intern (format "%s>%s"
282 (make-string (string-to-int
283 (match-string 1 uri-feature))
285 (substring uri-feature (match-end 0))))
287 ((and (setq feature (intern (format "=>%s" uri-feature)))
288 (find-charset feature))
290 ((and (setq feature (intern (format "=>>%s" uri-feature)))
291 (find-charset feature))
293 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
294 (find-charset feature))
296 ((and (setq feature (intern (format "=%s" uri-feature)))
297 (find-charset feature))
299 (t (intern uri-feature)))))
301 (defun www-uri-encode-feature-name (feature-name)
302 (setq feature-name (symbol-name feature-name))
304 ((string-match "^=\\([^=>]+\\)" feature-name)
305 (concat "rep." (substring feature-name (match-beginning 1)))
307 ((string-match "^=>>\\([^=>]+\\)" feature-name)
308 (concat "g." (substring feature-name (match-beginning 1)))
310 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
311 (concat "gi." (substring feature-name (match-beginning 1)))
313 ((string-match "^=>>\\(>+\\)" feature-name)
315 (length (match-string 1 feature-name))
316 (substring feature-name (match-end 1)))
318 ((string-match "^=>\\([^=>]+\\)" feature-name)
319 (concat "a." (substring feature-name (match-beginning 1)))
321 ((string-match "^\\(=+\\)>" feature-name)
323 (length (match-string 1 feature-name))
324 (substring feature-name (match-end 0)))
326 ((string-match "^->" feature-name)
327 (concat "to." (substring feature-name (match-end 0)))
329 ((string-match "^<-" feature-name)
330 (concat "from." (substring feature-name (match-end 0)))
334 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
335 (format "%s?feature=%s&char=%s"
336 chise-wiki-view-url uri-feature-name uri-char))
338 (defun www-uri-decode-char (char-rep)
341 ((string-match "\\(%3A\\|:\\)" char-rep)
342 (setq ccs (substring char-rep 0 (match-beginning 0))
343 cpos (substring char-rep (match-end 0)))
344 (setq ccs (www-uri-decode-feature-name ccs))
346 ((string-match "^0x" cpos)
348 (string-to-number (substring cpos (match-end 0)) 16))
351 (setq cpos (string-to-number cpos))
354 (decode-char ccs cpos))
357 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
358 (when (= (length char-rep) 1)
362 (defun www-uri-encode-char (char)
363 (if (encode-char char '=ucs)
366 (format "%%%02X" byte))
367 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
369 (let ((ccs-list '(; =ucs
370 =cns11643-1 =cns11643-2 =cns11643-3
371 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
373 =jis-x0208 =jis-x0208@1990
376 =jis-x0213-1@2000 =jis-x0213-1@2004
377 =jis-x0208@1983 =jis-x0208@1978
378 =zinbun-oracle =>zinbun-oracle
381 =>>jis-x0208 =>>jis-x0213-1
382 =>jis-x0208 =>jis-x0213-1
389 (setq ccs (pop ccs-list))
390 (not (setq ret (encode-char char ccs 'defined-only)))))
393 (www-uri-encode-feature-name ccs)
395 ((and (setq ccs (car (split-char char)))
396 (setq ret (encode-char char ccs)))
398 (www-uri-encode-feature-name ccs)
401 (format "system-char-id:0x%X"
402 (encode-char char 'system-char-id))
406 ;;; @ Feature name presentation
409 (defun www-format-feature-name-default (feature-name)
413 (symbol-name feature-name)
417 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
418 (let ((str (symbol-name feature-name))
421 ((string-match "\\*[^*]+$" str)
422 (setq base (substring str 0 (match-beginning 0))
423 meta (substring str (match-beginning 0)))
424 (concat (www-format-feature-name* (intern base) lang)
427 (www-format-feature-name-default feature-name)
430 (defun www-format-feature-name-as-rel-to (feature-name)
431 (concat "\u2192" (substring (symbol-name feature-name) 2)))
433 (defun www-format-feature-name-as-rel-from (feature-name)
434 (concat "\u2190" (substring (symbol-name feature-name) 2)))
436 (defun www-format-feature-name-as-CCS (feature-name)
439 (symbol-name feature-name)
441 (dest (upcase (pop rest))))
442 (when (string-match "^=+>*" dest)
443 (setq dest (concat (substring dest 0 (match-end 0))
445 (substring dest (match-end 0)))))
449 (setq dest (concat dest " " (upcase (pop rest)))))
450 (if (string-match "^[0-9]+$" (car rest))
451 (concat dest "-" (car rest))
452 (concat dest " " (upcase (car rest))))
456 (defun www-format-feature-name* (feature-name &optional lang)
457 (let (name fn parent ret)
460 (char-feature-property
462 (intern (format "name@%s" lang))))
463 (char-feature-property
464 feature-name 'name)))
465 ((and (setq name (symbol-name feature-name))
466 (string-match "\\*" name))
467 (www-format-feature-name-as-metadata feature-name lang))
469 (setq fn feature-name)
470 (while (and (setq parent (char-feature-name-parent fn))
473 (char-feature-property
475 (intern (format "name@%s" lang))))
476 (char-feature-property
481 (concat ret (substring (symbol-name feature-name)
482 (length (symbol-name parent)))))
483 ((find-charset feature-name)
484 (www-format-feature-name-as-CCS feature-name))
485 ((string-match "^\\(->\\)" name)
486 (www-format-feature-name-as-rel-to feature-name))
487 ((string-match "^\\(<-\\)" name)
488 (www-format-feature-name-as-rel-from feature-name))
490 (www-format-feature-name-default feature-name)
494 (defun www-format-feature-name (feature-name &optional lang)
495 (www-format-encode-string
496 (www-format-feature-name* feature-name lang)))
499 ;;; @ Feature value presentation
502 (defun www-format-value-as-kuten (value)
504 (- (lsh value -8) 32)
505 (- (logand value 255) 32)))
507 (defun www-format-value-default (value &optional without-tags)
511 (www-format-encode-string
515 (www-format-encode-string (format "%S" value) without-tags)))
517 (defun www-format-value-as-char-list (value &optional without-tags)
522 (www-format-encode-string
523 (format (if (characterp unit)
529 (if (characterp unit)
530 (format "<a href=\"%s?char=%s\">%s</a>"
532 (www-uri-encode-char unit)
533 (www-format-encode-string (char-to-string unit)))
534 (www-format-encode-string (format "%s" unit)))))
536 (www-format-encode-string (format "%s" value) without-tags)))
538 (defun www-format-value-as-domain-list (value &optional without-tags)
539 (let (name source0 source num dest rest unit start end ddest)
548 (setq unit (pop rest))
550 (setq name (symbol-name unit)))
555 ((string-match "^zob1968=" name)
556 (setq source (intern (substring name 0 (match-end 0)))
557 num (substring name (match-end 0)))
558 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
559 (setq start (string-to-number
560 (match-string 1 num))
561 end (string-to-number
562 (match-string 2 num)))
563 (setq start (string-to-number num)
566 (if (eq source source0)
568 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
570 (setq source0 source)
572 " <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/\">%s</a>=<a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
573 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
575 (setq start (1+ start))
576 (while (<= start end)
581 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
583 (setq start (1+ start)))
587 (if (eq source source0)
589 (setq source0 source)
593 (www-format-encode-string (format "%s" value) without-tags))))
595 (defun www-format-value-as-ids (value &optional without-tags)
600 (www-format-encode-string
601 (format (if (characterp unit)
607 (if (characterp unit)
608 (format "<a href=\"%s?char=%s\">%s</a>"
610 (www-uri-encode-char unit)
611 (www-format-encode-string (char-to-string unit)))
612 (www-format-encode-string (format "%s" unit)))))
613 (ideographic-structure-to-ids value) " ")
614 (www-format-encode-string (format "%s" value) without-tags)))
616 (defun www-format-value-as-S-exp (value &optional without-tags)
617 (www-format-encode-string (format "%S" value) without-tags))
619 (defun www-format-value-as-HEX (value)
622 (www-format-value-as-S-exp value)))
624 (defun www-format-value-as-CCS-default (value)
627 (www-format-value-as-HEX value)
629 (www-format-value-as-S-exp value)))
631 (defun www-format-value-as-CCS-94x94 (value)
633 (format "0x%s [%s] (%d)"
634 (www-format-value-as-HEX value)
635 (www-format-value-as-kuten value)
637 (www-format-value-as-S-exp value)))
639 (defun www-format-value-as-kangxi-radical (value)
640 (if (and (integerp value)
643 (www-format-encode-string
644 (format "%c" (ideographic-radical value)))
645 (www-format-value-as-S-exp value)))
647 (defun www-format-value (object feature-name
648 &optional value format
649 without-tags without-edit)
651 (setq value (www-char-feature object feature-name)))
652 (www-format-apply-value object feature-name
653 format nil value nil nil
654 without-tags without-edit)
658 ;;; @ format evaluator
661 (defun www-format-encode-string (string &optional without-tags)
664 (let (plane code start end char variants ret rret)
665 (goto-char (point-min))
666 (while (search-forward "<" nil t)
667 (replace-match "<" nil t))
668 (goto-char (point-min))
669 (while (search-forward ">" nil t)
670 (replace-match ">" nil t))
672 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
673 (let ((coded-charset-entity-reference-alist
676 '(=cns11643-1 "C1-" 4 X)
677 '(=cns11643-2 "C2-" 4 X)
678 '(=cns11643-3 "C3-" 4 X)
679 '(=cns11643-4 "C4-" 4 X)
680 '(=cns11643-5 "C5-" 4 X)
681 '(=cns11643-6 "C6-" 4 X)
682 '(=cns11643-7 "C7-" 4 X)
684 '(=gb12345 "G1-" 4 X)
685 '(=jis-x0208@1990 "J90-" 4 X)
686 '(=jis-x0212 "JSP-" 4 X)
688 '(=jis-x0208@1997 "J97-" 4 X)
689 '(=jis-x0208@1978 "J78-" 4 X)
690 '(=jis-x0208@1983 "J83-" 4 X)
691 '(=ruimoku-v6 "RUI6-" 4 X)
692 '(=zinbun-oracle "ZOB-" 4 d)
693 '(=jef-china3 "JC3-" 4 X)
694 '(=daikanwa "M-" 5 d)
695 coded-charset-entity-reference-alist)))
696 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
698 (goto-char (point-min))
699 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
700 (setq code (string-to-int (match-string 1)))
702 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
704 chise-wiki-bitmap-glyphs-url
708 (goto-char (point-min))
709 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
710 (setq plane (match-string 1)
711 code (string-to-int (match-string 2) 16))
713 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
715 chise-wiki-bitmap-glyphs-url
718 (- (logand code 255) 32))
721 (goto-char (point-min))
722 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
723 (setq plane (string-to-int (match-string 1))
724 code (string-to-int (match-string 2) 16))
726 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
728 chise-wiki-bitmap-glyphs-url
731 (- (logand code 255) 32))
734 (goto-char (point-min))
735 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
736 (setq plane (string-to-int (match-string 1))
737 code (string-to-int (match-string 2) 16))
739 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
741 chise-wiki-bitmap-glyphs-url
745 (goto-char (point-min))
746 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
747 (setq code (string-to-int (match-string 1) 16))
749 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
753 (goto-char (point-min))
754 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
755 (setq code (string-to-int (match-string 2)))
757 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
759 chise-wiki-bitmap-glyphs-url
763 (goto-char (point-min))
764 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
765 (setq code (string-to-int (match-string 2)))
767 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
769 chise-wiki-glyph-cgi-url
773 (goto-char (point-min))
774 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
775 (setq code (string-to-int (match-string 2)))
777 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
779 chise-wiki-glyph-cgi-url
783 (goto-char (point-min))
784 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
785 (setq code (string-to-int (match-string 1) 16))
787 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
789 chise-wiki-glyph-cgi-url
793 (goto-char (point-min))
794 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
795 (setq code (string-to-int (match-string 1) 16))
797 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
799 chise-wiki-glyph-cgi-url
803 (goto-char (point-min))
804 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
805 (setq code (string-to-int (match-string 1) 16))
807 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
809 chise-wiki-glyph-cgi-url
813 (goto-char (point-min))
814 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
815 (setq code (string-to-int (match-string 2) 16))
817 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
822 (goto-char (point-min))
823 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
824 (setq code (string-to-int (match-string 1) 16))
825 (setq start (match-beginning 0)
827 (setq char (decode-char 'system-char-id code))
830 (or (www-char-feature char '->subsumptive)
831 (www-char-feature char '->denotational)))
834 (setq ret (www-format-encode-string
835 (char-to-string (car variants))))
836 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
837 (setq variants (cdr variants)))
839 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
841 (delete-region start end)
844 ((setq ret (or (www-char-feature char 'ideographic-combination)
845 (www-char-feature char 'ideographic-structure)))
850 (if (characterp (setq rret (find-char ch)))
853 (www-format-encode-string
854 (char-to-string ch) without-tags)
855 (www-format-encode-string
856 (format "%S" ch) without-tags)))
860 (delete-region start end)
864 ;; (goto-char (point-min))
865 ;; (while (search-forward ">-" nil t)
866 ;; (replace-match "&GT-" t 'literal))
869 (defun www-format-props-to-string (props &optional format)
871 (setq format (plist-get props :format)))
873 (plist-get props :flag)
874 ;; (if (plist-get props :zero-padding)
876 (if (plist-get props :len)
878 (let ((ret (plist-get props :len)))
883 ((eq format 'decimal) "d")
884 ((eq format 'hex) "x")
885 ((eq format 'HEX) "X")
886 ((eq format 'S-exp) "S")
889 (defun www-format-apply-value (object feature-name
891 &optional uri-char uri-feature
892 without-tags without-edit)
896 ((memq format '(decimal hex HEX))
898 (format (www-format-props-to-string props format)
900 (www-format-encode-string
904 ((eq format 'wiki-text)
906 (www-xml-format-list value)
907 (www-format-eval-list value object feature-name nil uri-char
908 without-tags without-edit))
911 (www-format-encode-string
912 (format (www-format-props-to-string props format)
916 (www-format-value-as-kuten value))
917 ((eq format 'kangxi-radical)
918 (www-format-value-as-kangxi-radical value))
919 ((eq format 'space-separated-char-list)
920 (www-format-value-as-char-list value without-tags))
921 ((eq format 'space-separated-ids)
922 (www-format-value-as-ids value without-tags))
923 ((eq format 'space-separated-domain-list)
924 (www-format-value-as-domain-list value without-tags))
926 (www-format-encode-string (format "%s" value) without-tags)
929 (www-format-value-default value without-tags)
934 (eq (plist-get props :mode) 'peek))
936 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
937 ><input type=\"submit\" value=\"edit\" /></a>"
940 uri-char uri-feature format))))
942 (defun www-format-eval-feature-value (char
944 &optional format lang uri-char value
945 without-tags without-edit)
947 (setq value (www-char-feature char feature-name)))
949 (setq format (www-feature-value-format feature-name)))
952 (www-format-apply-value
955 uri-char (www-uri-encode-feature-name feature-name)
956 without-tags without-edit)
959 (cond ((null (cdr format))
960 (setq format (car format))
961 (www-format-apply-value
963 (car format) (nth 1 format) value
964 uri-char (www-uri-encode-feature-name feature-name)
965 without-tags without-edit)
968 (www-format-eval-list format char feature-name lang uri-char
969 without-tags without-edit)
972 (defun www-format-eval-unit (exp char feature-name
973 &optional lang uri-char value
974 without-tags without-edit)
976 (setq value (www-char-feature char feature-name)))
978 (setq uri-char (www-uri-encode-char char)))
980 ((stringp exp) (www-format-encode-string exp))
984 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
985 S-exp string default))
986 (let ((fn (plist-get (nth 1 exp) :feature))
987 domain domain-fn ret)
990 (setq fn (intern fn)))
991 (setq domain (char-feature-name-domain feature-name))
992 (setq domain-fn (char-feature-name-at-domain fn domain))
993 (if (setq ret (www-char-feature char domain-fn))
994 (setq feature-name domain-fn
996 (setq feature-name fn
997 value (www-char-feature char fn)))
998 (push feature-name chise-wiki-displayed-features)
1000 (if (eq (car exp) 'value)
1001 (www-format-eval-feature-value char feature-name
1002 (plist-get (nth 1 exp) :format)
1004 without-tags without-edit)
1005 (www-format-apply-value
1007 (car exp) (nth 1 exp) value
1008 uri-char (www-uri-encode-feature-name feature-name)
1009 without-tags without-edit))
1011 ((eq (car exp) 'name)
1012 (let ((fn (plist-get (nth 1 exp) :feature))
1015 (setq domain (char-feature-name-domain feature-name))
1017 (setq fn (intern fn)))
1018 (setq domain-fn (char-feature-name-at-domain fn domain))
1019 (setq feature-name domain-fn)))
1021 (www-format-feature-name feature-name lang)
1022 (format "<a href=\"%s\">%s</a>"
1023 (www-uri-make-feature-name-url
1024 (www-uri-encode-feature-name feature-name)
1026 (www-format-feature-name feature-name lang))
1029 ((eq (car exp) 'name-url)
1030 (let ((fn (plist-get (nth 1 exp) :feature))
1033 (setq domain (char-feature-name-domain feature-name))
1035 (setq fn (intern fn)))
1036 (setq domain-fn (char-feature-name-at-domain fn domain))
1037 (setq feature-name domain-fn)))
1038 (www-uri-make-feature-name-url
1039 (www-uri-encode-feature-name feature-name)
1042 ((eq (car exp) 'domain-name)
1043 (let ((domain (char-feature-name-domain feature-name)))
1045 (format "@%s" domain))))
1046 ((eq (car exp) 'prev-char)
1049 (let ((prev-char (find-previous-defined-code-point
1050 feature-name value)))
1052 (format "\n<a href=\"%s?char=%s\">%s</a>"
1054 (www-uri-encode-char prev-char)
1055 "<input type=\"submit\" value=\"-\" />"
1056 ;; (www-format-encode-string
1057 ;; (char-to-string prev-char))
1061 ((eq (car exp) 'next-char)
1064 (let ((next-char (find-next-defined-code-point
1065 feature-name value)))
1067 (format "<a href=\"%s?char=%s\">%s</a>"
1069 (www-uri-encode-char next-char)
1070 "<input type=\"submit\" value=\"+\" />"
1071 ;; (www-format-encode-string
1072 ;; (char-to-string next-char))
1076 ((eq (car exp) 'link)
1078 (www-format-eval-list (nthcdr 2 exp)
1079 char feature-name lang uri-char
1080 without-tags without-edit)
1085 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1086 char feature-name lang uri-char
1087 'without-tags 'without-edit)
1088 (www-format-eval-list (nthcdr 2 exp)
1089 char feature-name lang uri-char
1090 without-tags without-edit)))
1097 (www-format-eval-list (nthcdr 2 exp) char feature-name
1099 without-tags without-edit)
1102 (defun www-format-eval-list (format-list char feature-name
1103 &optional lang uri-char
1104 without-tags without-edit)
1105 (if (consp format-list)
1108 (www-format-eval-unit exp char feature-name lang uri-char
1109 nil without-tags without-edit))
1111 (www-format-eval-unit format-list char feature-name lang uri-char
1112 nil without-tags without-edit)))
1118 (defun www-xml-format-props (props)
1122 (setq key (pop props)
1125 (setq key (symbol-name key)))
1126 (if (eq (aref key 0) ?:)
1127 (setq key (substring key 1)))
1129 (format "%s %s=\"%s\""
1131 (www-format-encode-string
1132 (format "%s" val) 'without-tags))))
1135 (defun www-xml-format-unit (format-unit)
1136 (let (name props children ret)
1138 ((stringp format-unit)
1139 (mapconcat (lambda (c)
1142 ;; ((eq c ?<) "&lt;")
1143 ;; ((eq c ?>) "&gt;")
1145 (char-to-string c))))
1146 (www-format-encode-string format-unit 'without-tags)
1149 ((consp format-unit)
1150 (setq name (car format-unit)
1151 props (nth 1 format-unit)
1152 children (nthcdr 2 format-unit))
1153 (when (eq name 'link)
1154 (setq ret (plist-get props :ref))
1155 (unless (stringp ret)
1156 (setq props (plist-remprop (copy-list props) :ref))
1158 (cons (list* 'ref nil ret)
1161 (format "<%s%s>%s</%s>"
1164 (www-xml-format-props props)
1166 (www-xml-format-list children)
1169 name (www-xml-format-props props)))
1172 (format "%s" format-unit)))))
1174 (defun www-xml-format-list (format-list)
1175 (if (atom format-list)
1176 (www-xml-format-unit format-list)
1177 (mapconcat #'www-xml-format-unit
1181 ;;; @ HTML generator
1184 (defun www-html-display-text (text)
1188 (goto-char (point-min))
1189 (while (search-forward "<" nil t)
1190 (replace-match "<" nil t))
1191 (goto-char (point-min))
1192 (while (search-forward ">" nil t)
1193 (replace-match ">" nil t))
1194 (goto-char (point-min))
1195 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1197 (format "<a href=\"%s\">%s</a>"
1201 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1202 (goto-char (point-min))
1203 (while (search-forward ">-" nil t)
1204 (replace-match "&GT-" nil t))
1207 (defun www-html-display-paragraph (text)
1209 (www-html-display-text text)
1216 (defvar coded-charset-GlyphWiki-id-alist
1217 '((=ucs "u" 4 x nil)
1218 (=ucs@JP "u" 4 x nil)
1219 (=ucs@jis "u" 4 x nil)
1220 (=ucs@gb "u" 4 x "-g")
1221 (=ucs@cns "u" 4 x "-t")
1222 (=ucs@ks "u" 4 x "-k")
1223 (=ucs@iso "u" 4 x "-u")
1224 (=ucs@unicode "u" 4 x "-us")
1225 (=adobe-japan1-6 "aj1-" 5 d nil)
1227 (=big5-cdp "cdp-" 4 x nil)
1228 (=cbeta "cb" 5 d nil)
1229 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1230 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1231 (=jis-x0208@1978 "j78-" 4 x nil)
1232 (=jis-x0208@1983 "j83-" 4 x nil)
1233 (=jis-x0208@1990 "j90-" 4 x nil)
1234 (=jis-x0212 "jsp-" 4 x nil)
1235 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1236 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1237 (=jis-x0213-2 "jx2-" 4 x nil)
1238 (=cns11643-1 "c1-" 4 x nil)
1239 (=cns11643-2 "c2-" 4 x nil)
1240 (=cns11643-3 "c3-" 4 x nil)
1241 (=cns11643-4 "c4-" 4 x nil)
1242 (=cns11643-5 "c5-" 4 x nil)
1243 (=cns11643-6 "c6-" 4 x nil)
1244 (=cns11643-7 "c7-" 4 x nil)
1245 (=daikanwa "dkw-" 5 d nil)
1246 (=gt-k "gt-k" 5 d nil)
1247 (=jef-china3 "jc3-" 4 x nil)
1248 (=big5 "b-" 4 x nil)
1249 (=ks-x1001 "k0-" 4 x nil)
1252 (defun char-GlyphWiki-id (char)
1253 (let ((rest coded-charset-GlyphWiki-id-alist)
1256 (setq spec (pop rest))
1257 (null (setq ret (char-feature char (car spec))))))
1260 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1262 ((and (or (encode-char char '=jis-x0208@1990)
1263 (encode-char char '=jis-x0212)
1264 (encode-char char '=jis-x0213-1))
1265 (setq code (encode-char char '=ucs@jis)))
1266 (format "u%04x" code)
1268 ((and (or (encode-char char '=gb2312)
1269 (encode-char char '=gb12345))
1270 (setq code (encode-char char '=ucs@gb)))
1271 (format "u%04x-g" code)
1273 ((and (or (encode-char char '=cns11643-1)
1274 (encode-char char '=cns11643-2)
1275 (encode-char char '=cns11643-3)
1276 (encode-char char '=cns11643-4)
1277 (encode-char char '=cns11643-5)
1278 (encode-char char '=cns11643-6)
1279 (encode-char char '=cns11643-7))
1280 (setq code (encode-char char '=ucs@cns)))
1281 (format "u%04x-t" code)
1283 ((and (encode-char char '=ks-x1001)
1284 (setq code (encode-char char '=ucs@ks)))
1285 (format "u%04x-k" code)
1287 (format (format "%s%%0%d%s%s"
1291 (or (nth 4 spec) ""))
1298 (provide 'cwiki-common)
1300 ;;; cwiki-common.el ends here