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 (defun decode-uri-string (string &optional coding-system)
14 (if (> (length string) 0)
18 (mapconcat (lambda (char)
21 (char-to-string char)))
23 (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
24 (setq dest (concat dest
25 (substring string i (match-beginning 0))
28 (string-to-int (match-string 1 string) 16))))
31 (concat dest (substring string i))
34 (defun www-feature-type (feature-name)
35 (or (char-feature-property feature-name 'type)
36 (let ((str (symbol-name feature-name)))
38 ((string-match "\\*note\\(@[^*]+\\)?$" str)
40 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
42 ((string-match "\\*" str)
44 ((string-match "^\\(->\\|<-\\)" str)
46 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
50 (defun www-feature-value-format (feature-name)
51 (or (char-feature-property feature-name 'value-format)
53 (setq fn feature-name)
54 (while (and (setq parent (char-feature-name-parent fn))
56 (char-feature-property
57 parent 'value-format))))
60 (let ((type (www-feature-type feature-name)))
61 (cond ((eq type 'relation)
62 'space-separated-char-list)
68 (if (find-charset feature-name)
69 (if (and (= (charset-dimension feature-name) 2)
70 (= (charset-chars feature-name) 94))
72 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
73 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
75 (defun char-feature-name-at-domain (feature-name domain)
76 (let ((name (symbol-name feature-name)))
78 ((string-match "@[^*]+$" name)
79 (intern (format "%s/%s" name domain))
82 (intern (format "%s@%s" name domain))
85 (defun char-feature-name-parent (feature-name)
86 (let ((name (symbol-name feature-name)))
87 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
88 (intern (substring name 0 (car (last (match-data) 2)))))))
90 (defun char-feature-name-sans-versions (feature)
91 (let ((feature-name (symbol-name feature)))
92 (if (string-match "[@/]\\$rev=latest$" feature-name)
93 (intern (substring feature-name 0 (match-beginning 0)))
96 (defun www-char-feature (character feature)
97 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
98 (mount-char-attribute-table latest-feature)
99 (or (char-feature character latest-feature)
100 (char-feature character feature))))
102 (defun get-previous-code-point (ccs code)
103 (let ((chars (charset-chars ccs))
104 (dim (charset-dimension ccs))
106 mask byte-min byte-max
129 (setq bytes (make-vector dim 0))
131 (aset bytes i (logand (lsh code (* i -8)) mask))
134 (while (and (< i dim)
136 (aset bytes i (1- (aref bytes i)))
137 (< (aref bytes i) byte-min)))
138 (aset bytes i byte-max)
141 (setq dest (aref bytes 0)
144 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
148 (defun get-next-code-point (ccs code)
149 (let ((chars (charset-chars ccs))
150 (dim (charset-dimension ccs))
152 mask byte-min byte-max
175 (setq bytes (make-vector dim 0))
177 (aset bytes i (logand (lsh code (* i -8)) mask))
180 (while (and (< i dim)
182 (aset bytes i (1+ (aref bytes i)))
183 (> (aref bytes i) byte-max)))
184 (aset bytes i byte-min)
187 (setq dest (aref bytes 0)
190 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
194 (defun find-previous-defined-code-point (ccs code)
195 (let ((i (get-previous-code-point ccs code))
198 ((eq ccs '=jis-x0208)
199 (setq ccs '=jis-x0208@1990))
200 ((eq ccs '=jis-x0213-1)
201 (setq ccs '=jis-x0213-1@2004)))
204 (null (setq char (decode-char ccs i
205 (unless (eq ccs '=ucs)
207 (setq i (get-previous-code-point ccs i)))
210 (defun find-next-defined-code-point (ccs code)
211 (let ((i (get-next-code-point ccs code))
213 (setq max (+ code 1000))
215 ((eq ccs '=jis-x0208)
216 (setq ccs '=jis-x0208@1990))
217 ((eq ccs '=jis-x0213-1)
218 (setq ccs '=jis-x0213-1@2004)))
221 (null (setq char (decode-char ccs i
222 (unless (eq ccs '=ucs)
224 (setq i (get-next-code-point ccs i)))
228 ;;; @ URI representation
231 (defun www-uri-decode-feature-name (uri-feature)
234 ((string-match "^from\\." uri-feature)
235 (intern (format "<-%s" (substring uri-feature (match-end 0))))
237 ((string-match "^to\\." uri-feature)
238 (intern (format "->%s" (substring uri-feature (match-end 0))))
240 ((string-match "^rep\\." uri-feature)
241 (intern (format "=%s" (substring uri-feature (match-end 0))))
243 ((string-match "^g\\." uri-feature)
244 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
246 ((string-match "^gi\\." uri-feature)
247 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
249 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
250 (intern (format "=>>%s%s"
251 (make-string (string-to-int
252 (match-string 1 uri-feature))
254 (substring uri-feature (match-end 0))))
256 ((string-match "^a\\." uri-feature)
257 (intern (format "=>%s" (substring uri-feature (match-end 0))))
259 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
260 (intern (format "%s>%s"
261 (make-string (string-to-int
262 (match-string 1 uri-feature))
264 (substring uri-feature (match-end 0))))
266 ((and (setq feature (intern (format "=>%s" uri-feature)))
267 (find-charset feature))
269 ((and (setq feature (intern (format "=>>%s" uri-feature)))
270 (find-charset feature))
272 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
273 (find-charset feature))
275 ((and (setq feature (intern (format "=%s" uri-feature)))
276 (find-charset feature))
278 (t (intern uri-feature)))))
280 (defun www-uri-encode-feature-name (feature-name)
281 (setq feature-name (symbol-name feature-name))
283 ((string-match "^=\\([^=>]+\\)" feature-name)
284 (concat "rep." (substring feature-name (match-beginning 1)))
286 ((string-match "^=>>\\([^=>]+\\)" feature-name)
287 (concat "g." (substring feature-name (match-beginning 1)))
289 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
290 (concat "gi." (substring feature-name (match-beginning 1)))
292 ((string-match "^=>>\\(>+\\)" feature-name)
294 (length (match-string 1 feature-name))
295 (substring feature-name (match-end 1)))
297 ((string-match "^=>\\([^=>]+\\)" feature-name)
298 (concat "a." (substring feature-name (match-beginning 1)))
300 ((string-match "^\\(=+\\)>" feature-name)
302 (length (match-string 1 feature-name))
303 (substring feature-name (match-end 0)))
305 ((string-match "^->" feature-name)
306 (concat "to." (substring feature-name (match-end 0)))
308 ((string-match "^<-" feature-name)
309 (concat "from." (substring feature-name (match-end 0)))
313 (defun www-uri-decode-char (char-rep)
316 ((string-match "\\(%3A\\|:\\)" char-rep)
317 (setq ccs (substring char-rep 0 (match-beginning 0))
318 cpos (substring char-rep (match-end 0)))
319 (setq ccs (www-uri-decode-feature-name ccs))
321 ((string-match "^0x" cpos)
323 (string-to-number (substring cpos (match-end 0)) 16))
326 (setq cpos (string-to-number cpos))
329 (decode-char ccs cpos))
332 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
333 (when (= (length char-rep) 1)
337 (defun www-uri-encode-char (char)
338 (if (encode-char char '=ucs)
341 (format "%%%02X" byte))
342 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
344 (let ((ccs-list '(; =ucs
345 =cns11643-1 =cns11643-2 =cns11643-3
346 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
348 =jis-x0208 =jis-x0208@1990
351 =jis-x0213-1@2000 =jis-x0213-1@2004
352 =jis-x0208@1983 =jis-x0208@1978
353 =zinbun-oracle =>zinbun-oracle
356 =>>jis-x0208 =>>jis-x0213-1
357 =>jis-x0208 =>jis-x0213-1
364 (setq ccs (pop ccs-list))
365 (not (setq ret (encode-char char ccs 'defined-only)))))
368 (www-uri-encode-feature-name ccs)
370 ((and (setq ccs (car (split-char char)))
371 (setq ret (encode-char char ccs)))
373 (www-uri-encode-feature-name ccs)
376 (format "system-char-id:0x%X"
377 (encode-char char 'system-char-id))
381 ;;; @ Feature name presentation
384 (defun www-format-feature-name-default (feature-name)
388 (symbol-name feature-name)
392 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
393 (let ((str (symbol-name feature-name))
396 ((string-match "\\*[^*]+$" str)
397 (setq base (substring str 0 (match-beginning 0))
398 meta (substring str (match-beginning 0)))
399 (concat (www-format-feature-name* (intern base) lang)
402 (www-format-feature-name-default feature-name)
405 (defun www-format-feature-name-as-rel-to (feature-name)
406 (concat "\u2192" (substring (symbol-name feature-name) 2)))
408 (defun www-format-feature-name-as-rel-from (feature-name)
409 (concat "\u2190" (substring (symbol-name feature-name) 2)))
411 (defun www-format-feature-name-as-CCS (feature-name)
414 (symbol-name feature-name)
416 (dest (upcase (pop rest))))
417 (when (string-match "^=+>*" dest)
418 (setq dest (concat (substring dest 0 (match-end 0))
420 (substring dest (match-end 0)))))
424 (setq dest (concat dest " " (upcase (pop rest)))))
425 (if (string-match "^[0-9]+$" (car rest))
426 (concat dest "-" (car rest))
427 (concat dest " " (upcase (car rest))))
431 (defun www-format-feature-name* (feature-name &optional lang)
432 (let (name fn parent ret)
435 (char-feature-property
437 (intern (format "name@%s" lang))))
438 (char-feature-property
439 feature-name 'name)))
440 ((and (setq name (symbol-name feature-name))
441 (string-match "\\*" name))
442 (www-format-feature-name-as-metadata feature-name lang))
444 (setq fn feature-name)
445 (while (and (setq parent (char-feature-name-parent fn))
448 (char-feature-property
450 (intern (format "name@%s" lang))))
451 (char-feature-property
456 (concat ret (substring (symbol-name feature-name)
457 (length (symbol-name parent)))))
458 ((find-charset feature-name)
459 (www-format-feature-name-as-CCS feature-name))
460 ((string-match "^\\(->\\)" name)
461 (www-format-feature-name-as-rel-to feature-name))
462 ((string-match "^\\(<-\\)" name)
463 (www-format-feature-name-as-rel-from feature-name))
465 (www-format-feature-name-default feature-name)
469 (defun www-format-feature-name (feature-name &optional lang)
470 (www-format-encode-string
471 (www-format-feature-name* feature-name lang)))
474 ;;; @ Feature value presentation
477 (defun www-format-value-as-kuten (value)
479 (- (lsh value -8) 32)
480 (- (logand value 255) 32)))
482 (defun www-format-value-default (value &optional without-tags)
486 (www-format-encode-string
490 (www-format-encode-string (format "%S" value) without-tags)))
492 (defun www-format-value-as-char-list (value &optional without-tags)
497 (www-format-encode-string
498 (format (if (characterp unit)
504 (if (characterp unit)
505 (format "<a href=\"%s?char=%s\">%s</a>"
507 (www-uri-encode-char unit)
508 (www-format-encode-string (char-to-string unit)))
509 (www-format-encode-string (format "%s" unit)))))
511 (www-format-encode-string (format "%s" value) without-tags)))
513 (defun www-format-value-as-domain-list (value &optional without-tags)
514 (let (name source0 source num dest rest unit start end ddest)
523 (setq unit (pop rest))
525 (setq name (symbol-name unit)))
530 ((string-match "^zob1968=" name)
531 (setq source (intern (substring name 0 (match-end 0)))
532 num (substring name (match-end 0)))
533 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
534 (setq start (string-to-number
535 (match-string 1 num))
536 end (string-to-number
537 (match-string 2 num)))
538 (setq start (string-to-number num)
541 (if (eq source source0)
543 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
545 (setq source0 source)
547 " <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>"
548 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
550 (setq start (1+ start))
551 (while (<= start end)
556 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
558 (setq start (1+ start)))
562 (if (eq source source0)
564 (setq source0 source)
568 (www-format-encode-string (format "%s" value) without-tags))))
570 (defun www-format-value-as-ids (value &optional without-tags)
575 (www-format-encode-string
576 (format (if (characterp unit)
582 (if (characterp unit)
583 (format "<a href=\"%s?char=%s\">%s</a>"
585 (www-uri-encode-char unit)
586 (www-format-encode-string (char-to-string unit)))
587 (www-format-encode-string (format "%s" unit)))))
588 (ideographic-structure-to-ids value) " ")
589 (www-format-encode-string (format "%s" value) without-tags)))
591 (defun www-format-value-as-S-exp (value &optional without-tags)
592 (www-format-encode-string (format "%S" value) without-tags))
594 (defun www-format-value-as-HEX (value)
597 (www-format-value-as-S-exp value)))
599 (defun www-format-value-as-CCS-default (value)
602 (www-format-value-as-HEX value)
604 (www-format-value-as-S-exp value)))
606 (defun www-format-value-as-CCS-94x94 (value)
608 (format "0x%s [%s] (%d)"
609 (www-format-value-as-HEX value)
610 (www-format-value-as-kuten value)
612 (www-format-value-as-S-exp value)))
614 (defun www-format-value-as-kangxi-radical (value)
615 (if (and (integerp value)
618 (www-format-encode-string
619 (format "%c" (ideographic-radical value)))
620 (www-format-value-as-S-exp value)))
622 (defun www-format-value (object feature-name
623 &optional value format
624 without-tags without-edit)
626 (setq value (www-char-feature object feature-name)))
627 (www-format-apply-value object feature-name
628 format nil value nil nil
629 without-tags without-edit)
633 ;;; @ format evaluator
636 (defun www-format-encode-string (string &optional without-tags)
639 (let (plane code start end char variants ret rret)
640 (goto-char (point-min))
641 (while (search-forward "<" nil t)
642 (replace-match "<" nil t))
643 (goto-char (point-min))
644 (while (search-forward ">" nil t)
645 (replace-match ">" nil t))
647 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
648 (let ((coded-charset-entity-reference-alist
651 '(=cns11643-1 "C1-" 4 X)
652 '(=cns11643-2 "C2-" 4 X)
653 '(=cns11643-3 "C3-" 4 X)
654 '(=cns11643-4 "C4-" 4 X)
655 '(=cns11643-5 "C5-" 4 X)
656 '(=cns11643-6 "C6-" 4 X)
657 '(=cns11643-7 "C7-" 4 X)
659 '(=gb12345 "G1-" 4 X)
660 '(=jis-x0208@1990 "J90-" 4 X)
661 '(=jis-x0212 "JSP-" 4 X)
663 '(=jis-x0208@1997 "J97-" 4 X)
664 '(=jis-x0208@1978 "J78-" 4 X)
665 '(=jis-x0208@1983 "J83-" 4 X)
666 '(=ruimoku-v6 "RUI6-" 4 X)
667 '(=zinbun-oracle "ZOB-" 4 d)
668 '(=jef-china3 "JC3-" 4 X)
669 '(=daikanwa "M-" 5 d)
670 coded-charset-entity-reference-alist)))
671 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
673 (goto-char (point-min))
674 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
675 (setq code (string-to-int (match-string 1)))
677 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
679 chise-wiki-bitmap-glyphs-url
683 (goto-char (point-min))
684 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
685 (setq plane (match-string 1)
686 code (string-to-int (match-string 2) 16))
688 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
690 chise-wiki-bitmap-glyphs-url
693 (- (logand code 255) 32))
696 (goto-char (point-min))
697 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
698 (setq plane (string-to-int (match-string 1))
699 code (string-to-int (match-string 2) 16))
701 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
703 chise-wiki-bitmap-glyphs-url
706 (- (logand code 255) 32))
709 (goto-char (point-min))
710 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
711 (setq plane (string-to-int (match-string 1))
712 code (string-to-int (match-string 2) 16))
714 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
716 chise-wiki-bitmap-glyphs-url
720 (goto-char (point-min))
721 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
722 (setq code (string-to-int (match-string 1) 16))
724 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
728 (goto-char (point-min))
729 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
730 (setq code (string-to-int (match-string 2)))
732 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
734 chise-wiki-bitmap-glyphs-url
738 (goto-char (point-min))
739 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
740 (setq code (string-to-int (match-string 2)))
742 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
744 chise-wiki-glyph-cgi-url
748 (goto-char (point-min))
749 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
750 (setq code (string-to-int (match-string 2)))
752 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
754 chise-wiki-glyph-cgi-url
758 (goto-char (point-min))
759 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
760 (setq code (string-to-int (match-string 1) 16))
762 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
764 chise-wiki-glyph-cgi-url
768 (goto-char (point-min))
769 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
770 (setq code (string-to-int (match-string 1) 16))
772 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
774 chise-wiki-glyph-cgi-url
778 (goto-char (point-min))
779 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
780 (setq code (string-to-int (match-string 1) 16))
782 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
784 chise-wiki-glyph-cgi-url
788 (goto-char (point-min))
789 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
790 (setq code (string-to-int (match-string 2) 16))
792 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
797 (goto-char (point-min))
798 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
799 (setq code (string-to-int (match-string 1) 16))
800 (setq start (match-beginning 0)
802 (setq char (decode-char 'system-char-id code))
805 (or (www-char-feature char '->subsumptive)
806 (www-char-feature char '->denotational)))
809 (setq ret (www-format-encode-string
810 (char-to-string (car variants))))
811 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
812 (setq variants (cdr variants)))
814 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
816 (delete-region start end)
819 ((setq ret (or (www-char-feature char 'ideographic-combination)
820 (www-char-feature char 'ideographic-structure)))
825 (if (characterp (setq rret (find-char ch)))
828 (www-format-encode-string
829 (char-to-string ch) without-tags)
830 (www-format-encode-string
831 (format "%S" ch) without-tags)))
835 (delete-region start end)
839 ;; (goto-char (point-min))
840 ;; (while (search-forward ">-" nil t)
841 ;; (replace-match "&GT-" t 'literal))
844 (defun www-format-props-to-string (props &optional format)
846 (setq format (plist-get props :format)))
848 (plist-get props :flag)
849 ;; (if (plist-get props :zero-padding)
851 (if (plist-get props :len)
852 (format "0%d" (plist-get props :len)))
854 ((eq format 'decimal) "d")
855 ((eq format 'hex) "x")
856 ((eq format 'HEX) "X")
857 ((eq format 'S-exp) "S")
860 (defun www-format-apply-value (object feature-name
862 &optional uri-char uri-feature
863 without-tags without-edit)
867 ((memq format '(decimal hex HEX))
869 (format (www-format-props-to-string props format)
871 (www-format-encode-string
875 ((eq format 'wiki-text)
877 (www-xml-format-list value)
878 (www-format-eval-list value object feature-name nil uri-char
879 without-tags without-edit))
882 (www-format-encode-string
883 (format (www-format-props-to-string props format)
887 (www-format-value-as-kuten value))
888 ((eq format 'kangxi-radical)
889 (www-format-value-as-kangxi-radical value))
890 ((eq format 'space-separated-char-list)
891 (www-format-value-as-char-list value without-tags))
892 ((eq format 'space-separated-ids)
893 (www-format-value-as-ids value without-tags))
894 ((eq format 'space-separated-domain-list)
895 (www-format-value-as-domain-list value without-tags))
897 (www-format-encode-string (format "%s" value) without-tags)
900 (www-format-value-default value without-tags)
905 (eq (plist-get props :mode) 'peek))
907 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
908 ><input type=\"submit\" value=\"edit\" /></a>"
911 uri-char uri-feature format))))
913 (defun www-format-eval-feature-value (char
915 &optional format lang uri-char value
916 without-tags without-edit)
918 (setq value (www-char-feature char feature-name)))
920 (setq format (www-feature-value-format feature-name)))
923 (www-format-apply-value
926 uri-char (www-uri-encode-feature-name feature-name)
927 without-tags without-edit)
930 (cond ((null (cdr format))
931 (setq format (car format))
932 (www-format-apply-value
934 (car format) (nth 1 format) value
935 uri-char (www-uri-encode-feature-name feature-name)
936 without-tags without-edit)
939 (www-format-eval-list format char feature-name lang uri-char
940 without-tags without-edit)
943 (defun www-format-eval-unit (exp char feature-name
944 &optional lang uri-char value
945 without-tags without-edit)
947 (setq value (www-char-feature char feature-name)))
949 (setq uri-char (www-uri-encode-char char)))
951 ((stringp exp) (www-format-encode-string exp))
955 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
956 S-exp string default))
957 (if (eq (car exp) 'value)
958 (www-format-eval-feature-value char feature-name
959 (plist-get (nth 1 exp) :format)
961 without-tags without-edit)
962 (www-format-apply-value
964 (car exp) (nth 1 exp) value
965 uri-char (www-uri-encode-feature-name feature-name)
966 without-tags without-edit))
968 ((eq (car exp) 'name)
970 (www-format-feature-name feature-name lang)
971 (format "<a href=\"%s?feature=%s&char=%s\">%s</a>"
973 (www-uri-encode-feature-name feature-name)
975 (www-format-feature-name feature-name lang)))
977 ((eq (car exp) 'prev-char)
980 (let ((prev-char (find-previous-defined-code-point
981 feature-name value)))
983 (format "\n<a href=\"%s?char=%s\">%s</a>"
985 (www-uri-encode-char prev-char)
986 "<input type=\"submit\" value=\"-\" />"
987 ;; (www-format-encode-string
988 ;; (char-to-string prev-char))
992 ((eq (car exp) 'next-char)
995 (let ((next-char (find-next-defined-code-point
996 feature-name value)))
998 (format "<a href=\"%s?char=%s\">%s</a>"
1000 (www-uri-encode-char next-char)
1001 "<input type=\"submit\" value=\"+\" />"
1002 ;; (www-format-encode-string
1003 ;; (char-to-string next-char))
1007 ((eq (car exp) 'link)
1009 (www-format-eval-list (nthcdr 2 exp)
1010 char feature-name lang uri-char
1011 without-tags without-edit)
1016 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1017 char feature-name lang uri-char
1018 'without-tags 'without-edit)
1019 (www-format-eval-list (nthcdr 2 exp)
1020 char feature-name lang uri-char
1021 without-tags without-edit)))
1028 (www-format-eval-list (nthcdr 2 exp) char feature-name
1030 without-tags without-edit)
1033 (defun www-format-eval-list (format-list char feature-name
1034 &optional lang uri-char
1035 without-tags without-edit)
1036 (if (consp format-list)
1039 (www-format-eval-unit exp char feature-name lang uri-char
1040 nil without-tags without-edit))
1042 (www-format-eval-unit format-list char feature-name lang uri-char
1043 nil without-tags without-edit)))
1049 (defun www-xml-format-props (props)
1053 (setq key (pop props)
1056 (setq key (symbol-name key)))
1057 (if (eq (aref key 0) ?:)
1058 (setq key (substring key 1)))
1060 (format "%s %s=\"%s\""
1062 (www-format-encode-string
1063 (format "%s" val) 'without-tags))))
1066 (defun www-xml-format-unit (format-unit)
1067 (let (name props children ret)
1069 ((stringp format-unit)
1070 (mapconcat (lambda (c)
1073 ;; ((eq c ?<) "&lt;")
1074 ;; ((eq c ?>) "&gt;")
1076 (char-to-string c))))
1077 (www-format-encode-string format-unit 'without-tags)
1080 ((consp format-unit)
1081 (setq name (car format-unit)
1082 props (nth 1 format-unit)
1083 children (nthcdr 2 format-unit))
1084 (when (eq name 'link)
1085 (setq ret (plist-get props :ref))
1086 (unless (stringp ret)
1087 (setq props (plist-remprop (copy-list props) :ref))
1089 (cons (list* 'ref nil ret)
1092 (format "<%s%s>%s</%s>"
1095 (www-xml-format-props props)
1097 (www-xml-format-list children)
1100 name (www-xml-format-props props)))
1103 (format "%s" format-unit)))))
1105 (defun www-xml-format-list (format-list)
1106 (if (atom format-list)
1107 (www-xml-format-unit format-list)
1108 (mapconcat #'www-xml-format-unit
1112 ;;; @ HTML generator
1115 (defun www-html-display-text (text)
1119 (goto-char (point-min))
1120 (while (search-forward "<" nil t)
1121 (replace-match "<" nil t))
1122 (goto-char (point-min))
1123 (while (search-forward ">" nil t)
1124 (replace-match ">" nil t))
1125 (goto-char (point-min))
1126 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1128 (format "<a href=\"%s\">%s</a>"
1132 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1133 (goto-char (point-min))
1134 (while (search-forward ">-" nil t)
1135 (replace-match "&GT-" nil t))
1138 (defun www-html-display-paragraph (text)
1140 (www-html-display-text text)
1147 (defvar coded-charset-GlyphWiki-id-alist
1148 '((=ucs "u" 4 x nil)
1149 (=ucs@JP "u" 4 x nil)
1150 (=ucs@jis "u" 4 x nil)
1151 (=ucs@gb "u" 4 x "-g")
1152 (=ucs@cns "u" 4 x "-t")
1153 (=ucs@ks "u" 4 x "-k")
1154 (=ucs@iso "u" 4 x "-u")
1155 (=ucs@unicode "u" 4 x "-us")
1156 (=adobe-japan1-6 "aj1-" 5 d nil)
1158 (=big5-cdp "cdp-" 4 x nil)
1159 (=cbeta "cb" 5 d nil)
1160 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1161 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1162 (=jis-x0208@1978 "j78-" 4 x nil)
1163 (=jis-x0208@1983 "j83-" 4 x nil)
1164 (=jis-x0208@1990 "j90-" 4 x nil)
1165 (=jis-x0212 "jsp-" 4 x nil)
1166 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1167 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1168 (=jis-x0213-2 "jx2-" 4 x nil)
1169 (=cns11643-1 "c1-" 4 x nil)
1170 (=cns11643-2 "c2-" 4 x nil)
1171 (=cns11643-3 "c3-" 4 x nil)
1172 (=cns11643-4 "c4-" 4 x nil)
1173 (=cns11643-5 "c5-" 4 x nil)
1174 (=cns11643-6 "c6-" 4 x nil)
1175 (=cns11643-7 "c7-" 4 x nil)
1176 (=daikanwa "dkw-" 5 d nil)
1177 (=gt-k "gt-k" 5 d nil)
1178 (=jef-china3 "jc3-" 4 x nil)
1179 (=big5 "b-" 4 x nil)
1180 (=ks-x1001 "k0-" 4 x nil)
1183 (defun char-GlyphWiki-id (char)
1184 (let ((rest coded-charset-GlyphWiki-id-alist)
1187 (setq spec (pop rest))
1188 (null (setq ret (char-feature char (car spec))))))
1191 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1193 ((and (or (encode-char char '=jis-x0208@1990)
1194 (encode-char char '=jis-x0212)
1195 (encode-char char '=jis-x0213-1))
1196 (setq code (encode-char char '=ucs@jis)))
1197 (format "u%04x" code)
1199 ((and (or (encode-char char '=gb2312)
1200 (encode-char char '=gb12345))
1201 (setq code (encode-char char '=ucs@gb)))
1202 (format "u%04x-g" code)
1204 ((and (or (encode-char char '=cns11643-1)
1205 (encode-char char '=cns11643-2)
1206 (encode-char char '=cns11643-3)
1207 (encode-char char '=cns11643-4)
1208 (encode-char char '=cns11643-5)
1209 (encode-char char '=cns11643-6)
1210 (encode-char char '=cns11643-7))
1211 (setq code (encode-char char '=ucs@cns)))
1212 (format "u%04x-t" code)
1214 ((and (encode-char char '=ks-x1001)
1215 (setq code (encode-char char '=ucs@ks)))
1216 (format "u%04x-k" code)
1218 (format (format "%s%%0%d%s%s"
1222 (or (nth 4 spec) ""))
1229 (provide 'cwiki-common)
1231 ;;; cwiki-common.el ends here