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-format (feature-name)
51 (or (char-feature-property feature-name 'format)
53 (setq fn feature-name)
54 (while (and (setq parent (char-feature-name-parent fn))
56 (char-feature-property
60 '((name) " : " (value))))
62 (defun www-feature-value-format (feature-name)
63 (or (char-feature-property feature-name 'value-format)
65 (setq fn feature-name)
66 (while (and (setq parent (char-feature-name-parent fn))
68 (char-feature-property
69 parent 'value-format))))
72 (let ((type (www-feature-type feature-name)))
73 (cond ((eq type 'relation)
74 'space-separated-char-list)
80 (if (find-charset feature-name)
81 (if (and (= (charset-dimension feature-name) 2)
82 (= (charset-chars feature-name) 94))
84 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
85 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
87 (defun char-feature-name-at-domain (feature-name domain)
88 (let ((name (symbol-name feature-name)))
90 ((string-match "@[^*]+$" name)
91 (intern (format "%s/%s" name domain))
94 (intern (format "%s@%s" name domain))
97 (defun char-feature-name-parent (feature-name)
98 (let ((name (symbol-name feature-name)))
99 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
100 (intern (substring name 0 (car (last (match-data) 2)))))))
102 (defun char-feature-name-sans-versions (feature)
103 (let ((feature-name (symbol-name feature)))
104 (if (string-match "[@/]\\$rev=latest$" feature-name)
105 (intern (substring feature-name 0 (match-beginning 0)))
108 (defun www-char-feature (character feature)
109 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
110 (mount-char-attribute-table latest-feature)
111 (or (char-feature character latest-feature)
112 (char-feature character feature))))
114 (defun get-previous-code-point (ccs code)
115 (let ((chars (charset-chars ccs))
116 (dim (charset-dimension ccs))
118 mask byte-min byte-max
141 (setq bytes (make-vector dim 0))
143 (aset bytes i (logand (lsh code (* i -8)) mask))
146 (while (and (< i dim)
148 (aset bytes i (1- (aref bytes i)))
149 (< (aref bytes i) byte-min)))
150 (aset bytes i byte-max)
153 (setq dest (aref bytes 0)
156 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
160 (defun get-next-code-point (ccs code)
161 (let ((chars (charset-chars ccs))
162 (dim (charset-dimension ccs))
164 mask byte-min byte-max
187 (setq bytes (make-vector dim 0))
189 (aset bytes i (logand (lsh code (* i -8)) mask))
192 (while (and (< i dim)
194 (aset bytes i (1+ (aref bytes i)))
195 (> (aref bytes i) byte-max)))
196 (aset bytes i byte-min)
199 (setq dest (aref bytes 0)
202 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
206 (defun find-previous-defined-code-point (ccs code)
207 (let ((i (get-previous-code-point ccs code))
210 ((eq ccs '=jis-x0208)
211 (setq ccs '=jis-x0208@1990))
212 ((eq ccs '=jis-x0213-1)
213 (setq ccs '=jis-x0213-1@2004)))
216 (null (setq char (decode-char ccs i
217 (unless (eq ccs '=ucs)
219 (setq i (get-previous-code-point ccs i)))
222 (defun find-next-defined-code-point (ccs code)
223 (let ((i (get-next-code-point ccs code))
225 (setq max (+ code 1000))
227 ((eq ccs '=jis-x0208)
228 (setq ccs '=jis-x0208@1990))
229 ((eq ccs '=jis-x0213-1)
230 (setq ccs '=jis-x0213-1@2004)))
233 (null (setq char (decode-char ccs i
234 (unless (eq ccs '=ucs)
236 (setq i (get-next-code-point ccs i)))
240 ;;; @ URI representation
243 (defun www-uri-decode-feature-name (uri-feature)
246 ((string-match "^from\\." uri-feature)
247 (intern (format "<-%s" (substring uri-feature (match-end 0))))
249 ((string-match "^to\\." uri-feature)
250 (intern (format "->%s" (substring uri-feature (match-end 0))))
252 ((string-match "^rep\\." uri-feature)
253 (intern (format "=%s" (substring uri-feature (match-end 0))))
255 ((string-match "^g\\." uri-feature)
256 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
258 ((string-match "^gi\\." uri-feature)
259 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
261 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
262 (intern (format "=>>%s%s"
263 (make-string (string-to-int
264 (match-string 1 uri-feature))
266 (substring uri-feature (match-end 0))))
268 ((string-match "^a\\." uri-feature)
269 (intern (format "=>%s" (substring uri-feature (match-end 0))))
271 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
272 (intern (format "%s>%s"
273 (make-string (string-to-int
274 (match-string 1 uri-feature))
276 (substring uri-feature (match-end 0))))
278 ((and (setq feature (intern (format "=>%s" uri-feature)))
279 (find-charset feature))
281 ((and (setq feature (intern (format "=>>%s" uri-feature)))
282 (find-charset feature))
284 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
285 (find-charset feature))
287 ((and (setq feature (intern (format "=%s" uri-feature)))
288 (find-charset feature))
290 (t (intern uri-feature)))))
292 (defun www-uri-encode-feature-name (feature-name)
293 (setq feature-name (symbol-name feature-name))
295 ((string-match "^=\\([^=>]+\\)" feature-name)
296 (concat "rep." (substring feature-name (match-beginning 1)))
298 ((string-match "^=>>\\([^=>]+\\)" feature-name)
299 (concat "g." (substring feature-name (match-beginning 1)))
301 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
302 (concat "gi." (substring feature-name (match-beginning 1)))
304 ((string-match "^=>>\\(>+\\)" feature-name)
306 (length (match-string 1 feature-name))
307 (substring feature-name (match-end 1)))
309 ((string-match "^=>\\([^=>]+\\)" feature-name)
310 (concat "a." (substring feature-name (match-beginning 1)))
312 ((string-match "^\\(=+\\)>" feature-name)
314 (length (match-string 1 feature-name))
315 (substring feature-name (match-end 0)))
317 ((string-match "^->" feature-name)
318 (concat "to." (substring feature-name (match-end 0)))
320 ((string-match "^<-" feature-name)
321 (concat "from." (substring feature-name (match-end 0)))
325 (defun www-uri-decode-char (char-rep)
328 ((string-match "\\(%3A\\|:\\)" char-rep)
329 (setq ccs (substring char-rep 0 (match-beginning 0))
330 cpos (substring char-rep (match-end 0)))
331 (setq ccs (www-uri-decode-feature-name ccs))
333 ((string-match "^0x" cpos)
335 (string-to-number (substring cpos (match-end 0)) 16))
338 (setq cpos (string-to-number cpos))
341 (decode-char ccs cpos))
344 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
345 (when (= (length char-rep) 1)
349 (defun www-uri-encode-char (char)
350 (if (encode-char char '=ucs)
353 (format "%%%02X" byte))
354 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
356 (let ((ccs-list '(; =ucs
357 =cns11643-1 =cns11643-2 =cns11643-3
358 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
360 =jis-x0208 =jis-x0208@1990
363 =jis-x0213-1@2000 =jis-x0213-1@2004
364 =jis-x0208@1983 =jis-x0208@1978
365 =zinbun-oracle =>zinbun-oracle
368 =>>jis-x0208 =>>jis-x0213-1
369 =>jis-x0208 =>jis-x0213-1
376 (setq ccs (pop ccs-list))
377 (not (setq ret (encode-char char ccs 'defined-only)))))
380 (www-uri-encode-feature-name ccs)
382 ((and (setq ccs (car (split-char char)))
383 (setq ret (encode-char char ccs)))
385 (www-uri-encode-feature-name ccs)
388 (format "system-char-id:0x%X"
389 (encode-char char 'system-char-id))
393 ;;; @ Feature name presentation
396 (defun www-format-feature-name-default (feature-name)
400 (symbol-name feature-name)
404 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
405 (let ((str (symbol-name feature-name))
408 ((string-match "\\*[^*]+$" str)
409 (setq base (substring str 0 (match-beginning 0))
410 meta (substring str (match-beginning 0)))
411 (concat (www-format-feature-name* (intern base) lang)
414 (www-format-feature-name-default feature-name)
417 (defun www-format-feature-name-as-rel-to (feature-name)
418 (concat "\u2192" (substring (symbol-name feature-name) 2)))
420 (defun www-format-feature-name-as-rel-from (feature-name)
421 (concat "\u2190" (substring (symbol-name feature-name) 2)))
423 (defun www-format-feature-name-as-CCS (feature-name)
426 (symbol-name feature-name)
428 (dest (upcase (pop rest))))
429 (when (string-match "^=+>*" dest)
430 (setq dest (concat (substring dest 0 (match-end 0))
432 (substring dest (match-end 0)))))
436 (setq dest (concat dest " " (upcase (pop rest)))))
437 (if (string-match "^[0-9]+$" (car rest))
438 (concat dest "-" (car rest))
439 (concat dest " " (upcase (car rest))))
443 (defun www-format-feature-name* (feature-name &optional lang)
444 (let (name fn parent ret)
447 (char-feature-property
449 (intern (format "name@%s" lang))))
450 (char-feature-property
451 feature-name 'name)))
452 ((and (setq name (symbol-name feature-name))
453 (string-match "\\*" name))
454 (www-format-feature-name-as-metadata feature-name lang))
456 (setq fn feature-name)
457 (while (and (setq parent (char-feature-name-parent fn))
460 (char-feature-property
462 (intern (format "name@%s" lang))))
463 (char-feature-property
468 (concat ret (substring (symbol-name feature-name)
469 (length (symbol-name parent)))))
470 ((find-charset feature-name)
471 (www-format-feature-name-as-CCS feature-name))
472 ((string-match "^\\(->\\)" name)
473 (www-format-feature-name-as-rel-to feature-name))
474 ((string-match "^\\(<-\\)" name)
475 (www-format-feature-name-as-rel-from feature-name))
477 (www-format-feature-name-default feature-name)
481 (defun www-format-feature-name (feature-name &optional lang)
482 (www-format-encode-string
483 (www-format-feature-name* feature-name lang)))
486 ;;; @ Feature value presentation
489 (defun www-format-value-as-kuten (value)
491 (- (lsh value -8) 32)
492 (- (logand value 255) 32)))
494 (defun www-format-value-default (value &optional without-tags)
498 (www-format-encode-string
502 (www-format-encode-string (format "%S" value) without-tags)))
504 (defun www-format-value-as-char-list (value &optional without-tags)
509 (www-format-encode-string
510 (format (if (characterp unit)
516 (if (characterp unit)
517 (format "<a href=\"%s?char=%s\">%s</a>"
519 (www-uri-encode-char unit)
520 (www-format-encode-string (char-to-string unit)))
521 (www-format-encode-string (format "%s" unit)))))
523 (www-format-encode-string (format "%s" value) without-tags)))
525 (defun www-format-value-as-domain-list (value &optional without-tags)
526 (let (name source0 source num dest rest unit start end ddest)
535 (setq unit (pop rest))
537 (setq name (symbol-name unit)))
542 ((string-match "^zob1968=" name)
543 (setq source (intern (substring name 0 (match-end 0)))
544 num (substring name (match-end 0)))
545 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
546 (setq start (string-to-number
547 (match-string 1 num))
548 end (string-to-number
549 (match-string 2 num)))
550 (setq start (string-to-number num)
553 (if (eq source source0)
555 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
557 (setq source0 source)
559 " <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>"
560 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
562 (setq start (1+ start))
563 (while (<= start end)
568 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
570 (setq start (1+ start)))
574 (if (eq source source0)
576 (setq source0 source)
580 (www-format-encode-string (format "%s" value) without-tags))))
582 (defun www-format-value-as-ids (value &optional without-tags)
587 (www-format-encode-string
588 (format (if (characterp unit)
594 (if (characterp unit)
595 (format "<a href=\"%s?char=%s\">%s</a>"
597 (www-uri-encode-char unit)
598 (www-format-encode-string (char-to-string unit)))
599 (www-format-encode-string (format "%s" unit)))))
600 (ideographic-structure-to-ids value) " ")
601 (www-format-encode-string (format "%s" value) without-tags)))
603 (defun www-format-value-as-S-exp (value &optional without-tags)
604 (www-format-encode-string (format "%S" value) without-tags))
606 (defun www-format-value-as-HEX (value)
609 (www-format-value-as-S-exp value)))
611 (defun www-format-value-as-CCS-default (value)
614 (www-format-value-as-HEX value)
616 (www-format-value-as-S-exp value)))
618 (defun www-format-value-as-CCS-94x94 (value)
620 (format "0x%s [%s] (%d)"
621 (www-format-value-as-HEX value)
622 (www-format-value-as-kuten value)
624 (www-format-value-as-S-exp value)))
626 (defun www-format-value-as-kangxi-radical (value)
627 (if (and (integerp value)
630 (www-format-encode-string
631 (format "%c" (ideographic-radical value)))
632 (www-format-value-as-S-exp value)))
634 (defun www-format-value (object feature-name
635 &optional value format
636 without-tags without-edit)
638 (setq value (www-char-feature object feature-name)))
639 (www-format-apply-value object feature-name
640 format nil value nil nil
641 without-tags without-edit)
645 ;;; @ format evaluator
648 (defun www-format-encode-string (string &optional without-tags)
651 (let (plane code start end char variants ret rret)
652 (goto-char (point-min))
653 (while (search-forward "<" nil t)
654 (replace-match "<" nil t))
655 (goto-char (point-min))
656 (while (search-forward ">" nil t)
657 (replace-match ">" nil t))
659 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
660 (let ((coded-charset-entity-reference-alist
663 '(=cns11643-1 "C1-" 4 X)
664 '(=cns11643-2 "C2-" 4 X)
665 '(=cns11643-3 "C3-" 4 X)
666 '(=cns11643-4 "C4-" 4 X)
667 '(=cns11643-5 "C5-" 4 X)
668 '(=cns11643-6 "C6-" 4 X)
669 '(=cns11643-7 "C7-" 4 X)
671 '(=gb12345 "G1-" 4 X)
672 '(=jis-x0208@1990 "J90-" 4 X)
673 '(=jis-x0212 "JSP-" 4 X)
675 '(=jis-x0208@1997 "J97-" 4 X)
676 '(=jis-x0208@1978 "J78-" 4 X)
677 '(=jis-x0208@1983 "J83-" 4 X)
678 '(=ruimoku-v6 "RUI6-" 4 X)
679 '(=zinbun-oracle "ZOB-" 4 d)
680 '(=jef-china3 "JC3-" 4 X)
681 '(=daikanwa "M-" 5 d)
682 coded-charset-entity-reference-alist)))
683 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
685 (goto-char (point-min))
686 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
687 (setq code (string-to-int (match-string 1)))
689 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
691 chise-wiki-bitmap-glyphs-url
695 (goto-char (point-min))
696 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
697 (setq plane (match-string 1)
698 code (string-to-int (match-string 2) 16))
700 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
702 chise-wiki-bitmap-glyphs-url
705 (- (logand code 255) 32))
708 (goto-char (point-min))
709 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
710 (setq plane (string-to-int (match-string 1))
711 code (string-to-int (match-string 2) 16))
713 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
715 chise-wiki-bitmap-glyphs-url
718 (- (logand code 255) 32))
721 (goto-char (point-min))
722 (while (re-search-forward "&C\\([1-7]\\)-\\([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=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
728 chise-wiki-bitmap-glyphs-url
732 (goto-char (point-min))
733 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
734 (setq code (string-to-int (match-string 1) 16))
736 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
740 (goto-char (point-min))
741 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
742 (setq code (string-to-int (match-string 2)))
744 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
746 chise-wiki-bitmap-glyphs-url
750 (goto-char (point-min))
751 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
752 (setq code (string-to-int (match-string 2)))
754 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
756 chise-wiki-glyph-cgi-url
760 (goto-char (point-min))
761 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
762 (setq code (string-to-int (match-string 2)))
764 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
766 chise-wiki-glyph-cgi-url
770 (goto-char (point-min))
771 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
772 (setq code (string-to-int (match-string 1) 16))
774 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
776 chise-wiki-glyph-cgi-url
780 (goto-char (point-min))
781 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
782 (setq code (string-to-int (match-string 1) 16))
784 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
786 chise-wiki-glyph-cgi-url
790 (goto-char (point-min))
791 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
792 (setq code (string-to-int (match-string 1) 16))
794 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
796 chise-wiki-glyph-cgi-url
800 (goto-char (point-min))
801 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
802 (setq code (string-to-int (match-string 2) 16))
804 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
809 (goto-char (point-min))
810 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
811 (setq code (string-to-int (match-string 1) 16))
812 (setq start (match-beginning 0)
814 (setq char (decode-char 'system-char-id code))
817 (or (www-char-feature char '->subsumptive)
818 (www-char-feature char '->denotational)))
821 (setq ret (www-format-encode-string
822 (char-to-string (car variants))))
823 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
824 (setq variants (cdr variants)))
826 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
828 (delete-region start end)
831 ((setq ret (or (www-char-feature char 'ideographic-combination)
832 (www-char-feature char 'ideographic-structure)))
837 (if (characterp (setq rret (find-char ch)))
840 (www-format-encode-string
841 (char-to-string ch) without-tags)
842 (www-format-encode-string
843 (format "%S" ch) without-tags)))
847 (delete-region start end)
851 ;; (goto-char (point-min))
852 ;; (while (search-forward ">-" nil t)
853 ;; (replace-match "&GT-" t 'literal))
856 (defun www-format-props-to-string (props &optional format)
858 (setq format (plist-get props :format)))
860 (plist-get props :flag)
861 ;; (if (plist-get props :zero-padding)
863 (if (plist-get props :len)
864 (format "0%d" (plist-get props :len)))
866 ((eq format 'decimal) "d")
867 ((eq format 'hex) "x")
868 ((eq format 'HEX) "X")
869 ((eq format 'S-exp) "S")
872 (defun www-format-apply-value (object feature-name
874 &optional uri-char uri-feature
875 without-tags without-edit)
879 ((memq format '(decimal hex HEX))
881 (format (www-format-props-to-string props format)
883 (www-format-encode-string
887 ((eq format 'wiki-text)
889 (www-xml-format-list value)
890 (www-format-eval-list value object feature-name nil uri-char
891 without-tags without-edit))
894 (www-format-encode-string
895 (format (www-format-props-to-string props format)
899 (www-format-value-as-kuten value))
900 ((eq format 'kangxi-radical)
901 (www-format-value-as-kangxi-radical value))
902 ((eq format 'space-separated-char-list)
903 (www-format-value-as-char-list value without-tags))
904 ((eq format 'space-separated-ids)
905 (www-format-value-as-ids value without-tags))
906 ((eq format 'space-separated-domain-list)
907 (www-format-value-as-domain-list value without-tags))
909 (www-format-encode-string (format "%s" value) without-tags)
912 (www-format-value-default value without-tags)
917 (eq (plist-get props :mode) 'peek))
919 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
920 ><input type=\"submit\" value=\"edit\" /></a>"
923 uri-char uri-feature format))))
925 (defun www-format-eval-feature-value (char
927 &optional format lang uri-char value
928 without-tags without-edit)
930 (setq value (www-char-feature char feature-name)))
932 (setq format (www-feature-value-format feature-name)))
935 (www-format-apply-value
938 uri-char (www-uri-encode-feature-name feature-name)
939 without-tags without-edit)
942 (cond ((null (cdr format))
943 (setq format (car format))
944 (www-format-apply-value
946 (car format) (nth 1 format) value
947 uri-char (www-uri-encode-feature-name feature-name)
948 without-tags without-edit)
951 (www-format-eval-list format char feature-name lang uri-char
952 without-tags without-edit)
955 (defun www-format-eval-unit (exp char feature-name
956 &optional lang uri-char value
957 without-tags without-edit)
959 (setq value (www-char-feature char feature-name)))
961 (setq uri-char (www-uri-encode-char char)))
963 ((stringp exp) (www-format-encode-string exp))
967 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
968 S-exp string default))
969 (let ((fn (plist-get (nth 1 exp) :feature)))
972 (setq fn (intern fn)))
973 (setq feature-name fn
974 value (www-char-feature char feature-name))))
975 (if (eq (car exp) 'value)
976 (www-format-eval-feature-value char feature-name
977 (plist-get (nth 1 exp) :format)
979 without-tags without-edit)
980 (www-format-apply-value
982 (car exp) (nth 1 exp) value
983 uri-char (www-uri-encode-feature-name feature-name)
984 without-tags without-edit))
986 ((eq (car exp) 'name)
987 (let ((fn (plist-get (nth 1 exp) :feature)))
994 (www-format-feature-name feature-name lang)
995 (format "<a href=\"%s?feature=%s&char=%s\">%s</a>"
997 (www-uri-encode-feature-name feature-name)
999 (www-format-feature-name feature-name lang)))
1001 ((eq (car exp) 'prev-char)
1004 (let ((prev-char (find-previous-defined-code-point
1005 feature-name value)))
1007 (format "\n<a href=\"%s?char=%s\">%s</a>"
1009 (www-uri-encode-char prev-char)
1010 "<input type=\"submit\" value=\"-\" />"
1011 ;; (www-format-encode-string
1012 ;; (char-to-string prev-char))
1016 ((eq (car exp) 'next-char)
1019 (let ((next-char (find-next-defined-code-point
1020 feature-name value)))
1022 (format "<a href=\"%s?char=%s\">%s</a>"
1024 (www-uri-encode-char next-char)
1025 "<input type=\"submit\" value=\"+\" />"
1026 ;; (www-format-encode-string
1027 ;; (char-to-string next-char))
1031 ((eq (car exp) 'link)
1033 (www-format-eval-list (nthcdr 2 exp)
1034 char feature-name lang uri-char
1035 without-tags without-edit)
1040 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1041 char feature-name lang uri-char
1042 'without-tags 'without-edit)
1043 (www-format-eval-list (nthcdr 2 exp)
1044 char feature-name lang uri-char
1045 without-tags without-edit)))
1052 (www-format-eval-list (nthcdr 2 exp) char feature-name
1054 without-tags without-edit)
1057 (defun www-format-eval-list (format-list char feature-name
1058 &optional lang uri-char
1059 without-tags without-edit)
1060 (if (consp format-list)
1063 (www-format-eval-unit exp char feature-name lang uri-char
1064 nil without-tags without-edit))
1066 (www-format-eval-unit format-list char feature-name lang uri-char
1067 nil without-tags without-edit)))
1073 (defun www-xml-format-props (props)
1077 (setq key (pop props)
1080 (setq key (symbol-name key)))
1081 (if (eq (aref key 0) ?:)
1082 (setq key (substring key 1)))
1084 (format "%s %s=\"%s\""
1086 (www-format-encode-string
1087 (format "%s" val) 'without-tags))))
1090 (defun www-xml-format-unit (format-unit)
1091 (let (name props children ret)
1093 ((stringp format-unit)
1094 (mapconcat (lambda (c)
1097 ;; ((eq c ?<) "&lt;")
1098 ;; ((eq c ?>) "&gt;")
1100 (char-to-string c))))
1101 (www-format-encode-string format-unit 'without-tags)
1104 ((consp format-unit)
1105 (setq name (car format-unit)
1106 props (nth 1 format-unit)
1107 children (nthcdr 2 format-unit))
1108 (when (eq name 'link)
1109 (setq ret (plist-get props :ref))
1110 (unless (stringp ret)
1111 (setq props (plist-remprop (copy-list props) :ref))
1113 (cons (list* 'ref nil ret)
1116 (format "<%s%s>%s</%s>"
1119 (www-xml-format-props props)
1121 (www-xml-format-list children)
1124 name (www-xml-format-props props)))
1127 (format "%s" format-unit)))))
1129 (defun www-xml-format-list (format-list)
1130 (if (atom format-list)
1131 (www-xml-format-unit format-list)
1132 (mapconcat #'www-xml-format-unit
1136 ;;; @ HTML generator
1139 (defun www-html-display-text (text)
1143 (goto-char (point-min))
1144 (while (search-forward "<" nil t)
1145 (replace-match "<" nil t))
1146 (goto-char (point-min))
1147 (while (search-forward ">" nil t)
1148 (replace-match ">" nil t))
1149 (goto-char (point-min))
1150 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1152 (format "<a href=\"%s\">%s</a>"
1156 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1157 (goto-char (point-min))
1158 (while (search-forward ">-" nil t)
1159 (replace-match "&GT-" nil t))
1162 (defun www-html-display-paragraph (text)
1164 (www-html-display-text text)
1171 (defvar coded-charset-GlyphWiki-id-alist
1172 '((=ucs "u" 4 x nil)
1173 (=ucs@JP "u" 4 x nil)
1174 (=ucs@jis "u" 4 x nil)
1175 (=ucs@gb "u" 4 x "-g")
1176 (=ucs@cns "u" 4 x "-t")
1177 (=ucs@ks "u" 4 x "-k")
1178 (=ucs@iso "u" 4 x "-u")
1179 (=ucs@unicode "u" 4 x "-us")
1180 (=adobe-japan1-6 "aj1-" 5 d nil)
1182 (=big5-cdp "cdp-" 4 x nil)
1183 (=cbeta "cb" 5 d nil)
1184 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1185 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1186 (=jis-x0208@1978 "j78-" 4 x nil)
1187 (=jis-x0208@1983 "j83-" 4 x nil)
1188 (=jis-x0208@1990 "j90-" 4 x nil)
1189 (=jis-x0212 "jsp-" 4 x nil)
1190 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1191 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1192 (=jis-x0213-2 "jx2-" 4 x nil)
1193 (=cns11643-1 "c1-" 4 x nil)
1194 (=cns11643-2 "c2-" 4 x nil)
1195 (=cns11643-3 "c3-" 4 x nil)
1196 (=cns11643-4 "c4-" 4 x nil)
1197 (=cns11643-5 "c5-" 4 x nil)
1198 (=cns11643-6 "c6-" 4 x nil)
1199 (=cns11643-7 "c7-" 4 x nil)
1200 (=daikanwa "dkw-" 5 d nil)
1201 (=gt-k "gt-k" 5 d nil)
1202 (=jef-china3 "jc3-" 4 x nil)
1203 (=big5 "b-" 4 x nil)
1204 (=ks-x1001 "k0-" 4 x nil)
1207 (defun char-GlyphWiki-id (char)
1208 (let ((rest coded-charset-GlyphWiki-id-alist)
1211 (setq spec (pop rest))
1212 (null (setq ret (char-feature char (car spec))))))
1215 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1217 ((and (or (encode-char char '=jis-x0208@1990)
1218 (encode-char char '=jis-x0212)
1219 (encode-char char '=jis-x0213-1))
1220 (setq code (encode-char char '=ucs@jis)))
1221 (format "u%04x" code)
1223 ((and (or (encode-char char '=gb2312)
1224 (encode-char char '=gb12345))
1225 (setq code (encode-char char '=ucs@gb)))
1226 (format "u%04x-g" code)
1228 ((and (or (encode-char char '=cns11643-1)
1229 (encode-char char '=cns11643-2)
1230 (encode-char char '=cns11643-3)
1231 (encode-char char '=cns11643-4)
1232 (encode-char char '=cns11643-5)
1233 (encode-char char '=cns11643-6)
1234 (encode-char char '=cns11643-7))
1235 (setq code (encode-char char '=ucs@cns)))
1236 (format "u%04x-t" code)
1238 ((and (encode-char char '=ks-x1001)
1239 (setq code (encode-char char '=ucs@ks)))
1240 (format "u%04x-k" code)
1242 (format (format "%s%%0%d%s%s"
1246 (or (nth 4 spec) ""))
1253 (provide 'cwiki-common)
1255 ;;; cwiki-common.el ends here