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-get-genre (object)
37 (if (characterp object)
41 (defun www-feature-type (feature-name)
42 (or (char-feature-property feature-name 'type)
43 (let ((str (symbol-name feature-name)))
45 ((string-match "\\*note\\(@[^*]+\\)?$" str)
47 ((string-match "\\*sources\\(@[^*]+\\)?$" str)
49 ((string-match "\\*" str)
51 ((string-match "^\\(->\\|<-\\)" str)
53 ((string-match "^ideographic-structure\\(@\\|$\\)" str)
57 (defun www-feature-format (feature-name)
58 (or (char-feature-property feature-name 'format)
60 (setq fn feature-name)
61 (while (and (setq parent (char-feature-name-parent fn))
63 (char-feature-property
67 '((name) " : " (value))))
69 (defun www-feature-value-format (feature-name)
70 (or (char-feature-property feature-name 'value-format)
72 (setq fn feature-name)
73 (while (and (setq parent (char-feature-name-parent fn))
75 (char-feature-property
76 parent 'value-format))))
79 (let ((type (www-feature-type feature-name)))
80 (cond ((eq type 'relation)
81 'space-separated-char-list)
87 (if (find-charset feature-name)
88 (if (and (= (charset-dimension feature-name) 2)
89 (= (charset-chars feature-name) 94))
91 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
92 '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))))
94 (defun char-feature-name-at-domain (feature-name domain)
96 (let ((name (symbol-name feature-name)))
98 ((string-match "@[^*]+$" name)
99 (intern (format "%s/%s" name domain))
102 (intern (format "%s@%s" name domain))
106 (defun char-feature-name-parent (feature-name)
107 (let ((name (symbol-name feature-name)))
108 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
109 (intern (substring name 0 (car (last (match-data) 2)))))))
111 (defun char-feature-name-domain (feature-name)
112 (let ((name (symbol-name feature-name)))
113 (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
114 (intern (substring name (1+ (match-beginning 0)))))))
116 (defun char-feature-name-sans-versions (feature)
117 (let ((feature-name (symbol-name feature)))
118 (if (string-match "[@/]\\$rev=latest$" feature-name)
119 (intern (substring feature-name 0 (match-beginning 0)))
122 (defun www-get-feature-value (object feature)
123 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
124 (mount-char-attribute-table latest-feature)
125 (or (char-feature object latest-feature)
126 (char-feature object feature))))
128 (defun get-previous-code-point (ccs code)
129 (let ((chars (charset-chars ccs))
130 (dim (charset-dimension ccs))
132 mask byte-min byte-max
155 (setq bytes (make-vector dim 0))
157 (aset bytes i (logand (lsh code (* i -8)) mask))
160 (while (and (< i dim)
162 (aset bytes i (1- (aref bytes i)))
163 (< (aref bytes i) byte-min)))
164 (aset bytes i byte-max)
167 (setq dest (aref bytes 0)
170 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
174 (defun get-next-code-point (ccs code)
175 (let ((chars (charset-chars ccs))
176 (dim (charset-dimension ccs))
178 mask byte-min byte-max
201 (setq bytes (make-vector dim 0))
203 (aset bytes i (logand (lsh code (* i -8)) mask))
206 (while (and (< i dim)
208 (aset bytes i (1+ (aref bytes i)))
209 (> (aref bytes i) byte-max)))
210 (aset bytes i byte-min)
213 (setq dest (aref bytes 0)
216 (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
220 (defun find-previous-defined-code-point (ccs code)
221 (let ((i (get-previous-code-point ccs code))
224 ((eq ccs '=jis-x0208)
225 (setq ccs '=jis-x0208@1990))
226 ((eq ccs '=jis-x0213-1)
227 (setq ccs '=jis-x0213-1@2004)))
230 (null (setq char (decode-char ccs i
231 (unless (eq ccs '=ucs)
233 (setq i (get-previous-code-point ccs i)))
236 (defun find-next-defined-code-point (ccs code)
237 (let ((i (get-next-code-point ccs code))
239 (setq max (+ code 1000))
241 ((eq ccs '=jis-x0208)
242 (setq ccs '=jis-x0208@1990))
243 ((eq ccs '=jis-x0213-1)
244 (setq ccs '=jis-x0213-1@2004)))
247 (null (setq char (decode-char ccs i
248 (unless (eq ccs '=ucs)
250 (setq i (get-next-code-point ccs i)))
254 ;;; @ URI representation
257 (defun www-uri-decode-feature-name (uri-feature)
260 ((string-match "^from\\." uri-feature)
261 (intern (format "<-%s" (substring uri-feature (match-end 0))))
263 ((string-match "^to\\." uri-feature)
264 (intern (format "->%s" (substring uri-feature (match-end 0))))
266 ((string-match "^rep\\." uri-feature)
267 (intern (format "=%s" (substring uri-feature (match-end 0))))
269 ((string-match "^g\\." uri-feature)
270 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
272 ((string-match "^gi\\." uri-feature)
273 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
275 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
276 (intern (format "=>>%s%s"
277 (make-string (string-to-int
278 (match-string 1 uri-feature))
280 (substring uri-feature (match-end 0))))
282 ((string-match "^a\\." uri-feature)
283 (intern (format "=>%s" (substring uri-feature (match-end 0))))
285 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
286 (intern (format "%s>%s"
287 (make-string (string-to-int
288 (match-string 1 uri-feature))
290 (substring uri-feature (match-end 0))))
292 ((and (setq feature (intern (format "=>%s" uri-feature)))
293 (find-charset feature))
295 ((and (setq feature (intern (format "=>>%s" uri-feature)))
296 (find-charset feature))
298 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
299 (find-charset feature))
301 ((and (setq feature (intern (format "=%s" uri-feature)))
302 (find-charset feature))
304 (t (intern uri-feature)))))
306 (defun www-uri-encode-feature-name (feature-name)
307 (setq feature-name (symbol-name feature-name))
309 ((string-match "^=\\([^=>]+\\)" feature-name)
310 (concat "rep." (substring feature-name (match-beginning 1)))
312 ((string-match "^=>>\\([^=>]+\\)" feature-name)
313 (concat "g." (substring feature-name (match-beginning 1)))
315 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
316 (concat "gi." (substring feature-name (match-beginning 1)))
318 ((string-match "^=>>\\(>+\\)" feature-name)
320 (length (match-string 1 feature-name))
321 (substring feature-name (match-end 1)))
323 ((string-match "^=>\\([^=>]+\\)" feature-name)
324 (concat "a." (substring feature-name (match-beginning 1)))
326 ((string-match "^\\(=+\\)>" feature-name)
328 (length (match-string 1 feature-name))
329 (substring feature-name (match-end 0)))
331 ((string-match "^->" feature-name)
332 (concat "to." (substring feature-name (match-end 0)))
334 ((string-match "^<-" feature-name)
335 (concat "from." (substring feature-name (match-end 0)))
339 (defun www-uri-make-feature-name-url (uri-feature-name uri-char)
340 (format "%s?feature=%s&char=%s"
341 chise-wiki-view-url uri-feature-name uri-char))
343 (defun www-uri-decode-object (genre char-rep)
346 ((string-match "\\(%3A\\|:\\)" char-rep)
347 (setq ccs (substring char-rep 0 (match-beginning 0))
348 cpos (substring char-rep (match-end 0)))
349 (setq ccs (www-uri-decode-feature-name ccs))
351 ((string-match "^0x" cpos)
353 (string-to-number (substring cpos (match-end 0)) 16))
356 (setq cpos (car (read-from-string cpos)))
358 (if (and (eq genre 'character)
360 (decode-char ccs cpos)
361 (concord-decode-object ccs cpos genre))
364 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
365 (if (eq genre 'character)
366 (when (= (length char-rep) 1)
368 (concord-decode-object '=id char-rep genre))))))
370 (defun www-uri-encode-char (char)
371 (if (encode-char char '=ucs)
374 (format "%%%02X" byte))
375 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
377 (let ((ccs-list '(; =ucs
378 =cns11643-1 =cns11643-2 =cns11643-3
379 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
381 =jis-x0208 =jis-x0208@1990
384 =jis-x0213-1@2000 =jis-x0213-1@2004
385 =jis-x0208@1983 =jis-x0208@1978
386 =zinbun-oracle =>zinbun-oracle
389 =>>jis-x0208 =>>jis-x0213-1
390 =>jis-x0208 =>jis-x0213-1
397 (setq ccs (pop ccs-list))
398 (not (setq ret (encode-char char ccs 'defined-only)))))
401 (www-uri-encode-feature-name ccs)
403 ((and (setq ccs (car (split-char char)))
404 (setq ret (encode-char char ccs)))
406 (www-uri-encode-feature-name ccs)
409 (format "system-char-id:0x%X"
410 (encode-char char 'system-char-id))
414 ;;; @ Feature name presentation
417 (defun www-format-feature-name-default (feature-name)
421 (symbol-name feature-name)
425 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
426 (let ((str (symbol-name feature-name))
429 ((string-match "\\*[^*]+$" str)
430 (setq base (substring str 0 (match-beginning 0))
431 meta (substring str (match-beginning 0)))
432 (concat (www-format-feature-name* (intern base) lang)
435 (www-format-feature-name-default feature-name)
438 (defun www-format-feature-name-as-rel-to (feature-name)
439 (concat "\u2192" (substring (symbol-name feature-name) 2)))
441 (defun www-format-feature-name-as-rel-from (feature-name)
442 (concat "\u2190" (substring (symbol-name feature-name) 2)))
444 (defun www-format-feature-name-as-CCS (feature-name)
447 (symbol-name feature-name)
449 (dest (upcase (pop rest))))
450 (when (string-match "^=+>*" dest)
451 (setq dest (concat (substring dest 0 (match-end 0))
453 (substring dest (match-end 0)))))
457 (setq dest (concat dest " " (upcase (pop rest)))))
458 (if (string-match "^[0-9]+$" (car rest))
459 (concat dest "-" (car rest))
460 (concat dest " " (upcase (car rest))))
464 (defun www-format-feature-name* (feature-name &optional lang)
465 (let (name fn parent ret)
468 (char-feature-property
470 (intern (format "name@%s" lang))))
471 (char-feature-property
472 feature-name 'name)))
473 ((and (setq name (symbol-name feature-name))
474 (string-match "\\*" name))
475 (www-format-feature-name-as-metadata feature-name lang))
477 (setq fn feature-name)
478 (while (and (setq parent (char-feature-name-parent fn))
481 (char-feature-property
483 (intern (format "name@%s" lang))))
484 (char-feature-property
489 (concat ret (substring (symbol-name feature-name)
490 (length (symbol-name parent)))))
491 ((find-charset feature-name)
492 (www-format-feature-name-as-CCS feature-name))
493 ((string-match "^\\(->\\)" name)
494 (www-format-feature-name-as-rel-to feature-name))
495 ((string-match "^\\(<-\\)" name)
496 (www-format-feature-name-as-rel-from feature-name))
498 (www-format-feature-name-default feature-name)
502 (defun www-format-feature-name (feature-name &optional lang)
503 (www-format-encode-string
504 (www-format-feature-name* feature-name lang)))
507 ;;; @ Feature value presentation
510 (defun www-format-value-as-kuten (value)
512 (- (lsh value -8) 32)
513 (- (logand value 255) 32)))
515 (defun www-format-value-default (value &optional without-tags)
519 (www-format-encode-string
523 (www-format-encode-string (format "%S" value) without-tags)))
525 (defun www-format-value-as-char-list (value &optional without-tags)
530 (www-format-encode-string
531 (format (if (characterp unit)
537 (if (characterp unit)
538 (format "<a href=\"%s?char=%s\">%s</a>"
540 (www-uri-encode-char unit)
541 (www-format-encode-string (char-to-string unit)))
542 (www-format-encode-string (format "%s" unit)))))
544 (www-format-encode-string (format "%s" value) without-tags)))
546 (defun www-format-value-as-domain-list (value &optional without-tags)
547 (let (name source0 source num dest rest unit start end ddest)
556 (setq unit (pop rest))
558 (setq name (symbol-name unit)))
563 ((string-match "^zob1968=" name)
564 (setq source (intern (substring name 0 (match-end 0)))
565 num (substring name (match-end 0)))
566 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
567 (setq start (string-to-number
568 (match-string 1 num))
569 end (string-to-number
570 (match-string 2 num)))
571 (setq start (string-to-number num)
574 (if (eq source source0)
576 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
578 (setq source0 source)
580 " <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>"
581 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
583 (setq start (1+ start))
584 (while (<= start end)
589 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
591 (setq start (1+ start)))
595 (if (eq source source0)
597 (setq source0 source)
601 (www-format-encode-string (format "%s" value) without-tags))))
603 (defun www-format-value-as-ids (value &optional without-tags)
608 (www-format-encode-string
609 (format (if (characterp unit)
615 (if (characterp unit)
616 (format "<a href=\"%s?char=%s\">%s</a>"
618 (www-uri-encode-char unit)
619 (www-format-encode-string (char-to-string unit)))
620 (www-format-encode-string (format "%s" unit)))))
621 (ideographic-structure-to-ids value) " ")
622 (www-format-encode-string (format "%s" value) without-tags)))
624 (defun www-format-value-as-S-exp (value &optional without-tags)
625 (www-format-encode-string (format "%S" value) without-tags))
627 (defun www-format-value-as-HEX (value)
630 (www-format-value-as-S-exp value)))
632 (defun www-format-value-as-CCS-default (value)
635 (www-format-value-as-HEX value)
637 (www-format-value-as-S-exp value)))
639 (defun www-format-value-as-CCS-94x94 (value)
641 (format "0x%s [%s] (%d)"
642 (www-format-value-as-HEX value)
643 (www-format-value-as-kuten value)
645 (www-format-value-as-S-exp value)))
647 (defun www-format-value-as-kangxi-radical (value)
648 (if (and (integerp value)
651 (www-format-encode-string
652 (format "%c" (ideographic-radical value)))
653 (www-format-value-as-S-exp value)))
655 (defun www-format-value (object feature-name
656 &optional value format
657 without-tags without-edit)
659 (setq value (www-get-feature-value object feature-name)))
660 (www-format-apply-value object feature-name
661 format nil value nil nil
662 without-tags without-edit)
666 ;;; @ format evaluator
669 (defun www-format-encode-string (string &optional without-tags)
672 (let (plane code start end char variants ret rret)
673 (goto-char (point-min))
674 (while (search-forward "<" nil t)
675 (replace-match "<" nil t))
676 (goto-char (point-min))
677 (while (search-forward ">" nil t)
678 (replace-match ">" nil t))
680 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
681 (let ((coded-charset-entity-reference-alist
684 '(=cns11643-1 "C1-" 4 X)
685 '(=cns11643-2 "C2-" 4 X)
686 '(=cns11643-3 "C3-" 4 X)
687 '(=cns11643-4 "C4-" 4 X)
688 '(=cns11643-5 "C5-" 4 X)
689 '(=cns11643-6 "C6-" 4 X)
690 '(=cns11643-7 "C7-" 4 X)
692 '(=gb12345 "G1-" 4 X)
693 '(=jis-x0208@1990 "J90-" 4 X)
694 '(=jis-x0212 "JSP-" 4 X)
696 '(=jis-x0208@1997 "J97-" 4 X)
697 '(=jis-x0208@1978 "J78-" 4 X)
698 '(=jis-x0208@1983 "J83-" 4 X)
699 '(=ruimoku-v6 "RUI6-" 4 X)
700 '(=zinbun-oracle "ZOB-" 4 d)
701 '(=jef-china3 "JC3-" 4 X)
702 '(=daikanwa "M-" 5 d)
703 coded-charset-entity-reference-alist)))
704 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
706 (goto-char (point-min))
707 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
708 (setq code (string-to-int (match-string 1)))
710 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
712 chise-wiki-bitmap-glyphs-url
716 (goto-char (point-min))
717 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
718 (setq plane (match-string 1)
719 code (string-to-int (match-string 2) 16))
721 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
723 chise-wiki-bitmap-glyphs-url
726 (- (logand code 255) 32))
729 (goto-char (point-min))
730 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
731 (setq plane (string-to-int (match-string 1))
732 code (string-to-int (match-string 2) 16))
734 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
736 chise-wiki-bitmap-glyphs-url
739 (- (logand code 255) 32))
742 (goto-char (point-min))
743 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
744 (setq plane (string-to-int (match-string 1))
745 code (string-to-int (match-string 2) 16))
747 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
749 chise-wiki-bitmap-glyphs-url
753 (goto-char (point-min))
754 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
755 (setq code (string-to-int (match-string 1) 16))
757 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
761 (goto-char (point-min))
762 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
763 (setq code (string-to-int (match-string 2)))
765 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
767 chise-wiki-bitmap-glyphs-url
771 (goto-char (point-min))
772 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
773 (setq code (string-to-int (match-string 2)))
775 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
777 chise-wiki-glyph-cgi-url
781 (goto-char (point-min))
782 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
783 (setq code (string-to-int (match-string 2)))
785 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
787 chise-wiki-glyph-cgi-url
791 (goto-char (point-min))
792 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
793 (setq code (string-to-int (match-string 1) 16))
795 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
797 chise-wiki-glyph-cgi-url
801 (goto-char (point-min))
802 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
803 (setq code (string-to-int (match-string 1) 16))
805 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
807 chise-wiki-glyph-cgi-url
811 (goto-char (point-min))
812 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
813 (setq code (string-to-int (match-string 1) 16))
815 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
817 chise-wiki-glyph-cgi-url
821 (goto-char (point-min))
822 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
823 (setq code (string-to-int (match-string 2) 16))
825 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
830 (goto-char (point-min))
831 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
832 (setq code (string-to-int (match-string 1) 16))
833 (setq start (match-beginning 0)
835 (setq char (decode-char 'system-char-id code))
838 (or (www-get-feature-value char '->subsumptive)
839 (www-get-feature-value char '->denotational)))
842 (setq ret (www-format-encode-string
843 (char-to-string (car variants))))
844 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
845 (setq variants (cdr variants)))
847 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
849 (delete-region start end)
852 ((setq ret (or (www-get-feature-value char 'ideographic-combination)
853 (www-get-feature-value char 'ideographic-structure)))
858 (if (characterp (setq rret (find-char ch)))
861 (www-format-encode-string
862 (char-to-string ch) without-tags)
863 (www-format-encode-string
864 (format "%S" ch) without-tags)))
868 (delete-region start end)
872 ;; (goto-char (point-min))
873 ;; (while (search-forward ">-" nil t)
874 ;; (replace-match "&GT-" t 'literal))
877 (defun www-format-props-to-string (props &optional format)
879 (setq format (plist-get props :format)))
881 (plist-get props :flag)
882 ;; (if (plist-get props :zero-padding)
884 (if (plist-get props :len)
886 (let ((ret (plist-get props :len)))
891 ((eq format 'decimal) "d")
892 ((eq format 'hex) "x")
893 ((eq format 'HEX) "X")
894 ((eq format 'S-exp) "S")
897 (defun www-format-apply-value (object feature-name
899 &optional uri-char uri-feature
900 without-tags without-edit)
904 ((memq format '(decimal hex HEX))
906 (format (www-format-props-to-string props format)
908 (www-format-encode-string
912 ((eq format 'wiki-text)
914 (www-xml-format-list value)
915 (www-format-eval-list value object feature-name nil uri-char
916 without-tags without-edit))
919 (www-format-encode-string
920 (format (www-format-props-to-string props format)
924 (www-format-value-as-kuten value))
925 ((eq format 'kangxi-radical)
926 (www-format-value-as-kangxi-radical value))
927 ((eq format 'space-separated-char-list)
928 (www-format-value-as-char-list value without-tags))
929 ((eq format 'space-separated-ids)
930 (www-format-value-as-ids value without-tags))
931 ((eq format 'space-separated-domain-list)
932 (www-format-value-as-domain-list value without-tags))
934 (www-format-encode-string (format "%s" value) without-tags)
937 (www-format-value-default value without-tags)
942 (eq (plist-get props :mode) 'peek))
944 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
945 ><input type=\"submit\" value=\"edit\" /></a>"
948 uri-char uri-feature format))))
950 (defun www-format-eval-feature-value (char
952 &optional format lang uri-char value
953 without-tags without-edit)
955 (setq value (www-get-feature-value char feature-name)))
957 (setq format (www-feature-value-format feature-name)))
960 (www-format-apply-value
963 uri-char (www-uri-encode-feature-name feature-name)
964 without-tags without-edit)
967 (cond ((null (cdr format))
968 (setq format (car format))
969 (www-format-apply-value
971 (car format) (nth 1 format) value
972 uri-char (www-uri-encode-feature-name feature-name)
973 without-tags without-edit)
976 (www-format-eval-list format char feature-name lang uri-char
977 without-tags without-edit)
980 (defun www-format-eval-unit (exp char feature-name
981 &optional lang uri-char value
982 without-tags without-edit)
984 (setq value (www-get-feature-value char feature-name)))
986 (setq uri-char (www-uri-encode-char char)))
988 ((stringp exp) (www-format-encode-string exp))
992 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
993 S-exp string default))
994 (let ((fn (plist-get (nth 1 exp) :feature))
995 domain domain-fn ret)
998 (setq fn (intern fn)))
999 (setq domain (char-feature-name-domain feature-name))
1000 (setq domain-fn (char-feature-name-at-domain fn domain))
1001 (if (setq ret (www-get-feature-value char domain-fn))
1002 (setq feature-name domain-fn
1004 (setq feature-name fn
1005 value (www-get-feature-value char fn)))
1006 (push feature-name chise-wiki-displayed-features)
1008 (if (eq (car exp) 'value)
1009 (www-format-eval-feature-value char feature-name
1010 (plist-get (nth 1 exp) :format)
1012 without-tags without-edit)
1013 (www-format-apply-value
1015 (car exp) (nth 1 exp) value
1016 uri-char (www-uri-encode-feature-name feature-name)
1017 without-tags without-edit))
1019 ((eq (car exp) 'name)
1020 (let ((fn (plist-get (nth 1 exp) :feature))
1023 (setq domain (char-feature-name-domain feature-name))
1025 (setq fn (intern fn)))
1026 (setq domain-fn (char-feature-name-at-domain fn domain))
1027 (setq feature-name domain-fn)))
1029 (www-format-feature-name feature-name lang)
1030 (format "<a href=\"%s\">%s</a>"
1031 (www-uri-make-feature-name-url
1032 (www-uri-encode-feature-name feature-name)
1034 (www-format-feature-name feature-name lang))
1037 ((eq (car exp) 'name-url)
1038 (let ((fn (plist-get (nth 1 exp) :feature))
1041 (setq domain (char-feature-name-domain feature-name))
1043 (setq fn (intern fn)))
1044 (setq domain-fn (char-feature-name-at-domain fn domain))
1045 (setq feature-name domain-fn)))
1046 (www-uri-make-feature-name-url
1047 (www-uri-encode-feature-name feature-name)
1050 ((eq (car exp) 'domain-name)
1051 (let ((domain (char-feature-name-domain feature-name)))
1053 (format "@%s" domain))))
1054 ((eq (car exp) 'prev-char)
1057 (let ((prev-char (find-previous-defined-code-point
1058 feature-name value)))
1060 (format "\n<a href=\"%s?char=%s\">%s</a>"
1062 (www-uri-encode-char prev-char)
1063 "<input type=\"submit\" value=\"-\" />"
1064 ;; (www-format-encode-string
1065 ;; (char-to-string prev-char))
1069 ((eq (car exp) 'next-char)
1072 (let ((next-char (find-next-defined-code-point
1073 feature-name value)))
1075 (format "<a href=\"%s?char=%s\">%s</a>"
1077 (www-uri-encode-char next-char)
1078 "<input type=\"submit\" value=\"+\" />"
1079 ;; (www-format-encode-string
1080 ;; (char-to-string next-char))
1084 ((eq (car exp) 'link)
1086 (www-format-eval-list (nthcdr 2 exp)
1087 char feature-name lang uri-char
1088 without-tags without-edit)
1093 (www-format-eval-list (plist-get (nth 1 exp) :ref)
1094 char feature-name lang uri-char
1095 'without-tags 'without-edit)
1096 (www-format-eval-list (nthcdr 2 exp)
1097 char feature-name lang uri-char
1098 without-tags without-edit)))
1105 (www-format-eval-list (nthcdr 2 exp) char feature-name
1107 without-tags without-edit)
1110 (defun www-format-eval-list (format-list char feature-name
1111 &optional lang uri-char
1112 without-tags without-edit)
1113 (if (consp format-list)
1116 (www-format-eval-unit exp char feature-name lang uri-char
1117 nil without-tags without-edit))
1119 (www-format-eval-unit format-list char feature-name lang uri-char
1120 nil without-tags without-edit)))
1126 (defun www-xml-format-props (props)
1130 (setq key (pop props)
1133 (setq key (symbol-name key)))
1134 (if (eq (aref key 0) ?:)
1135 (setq key (substring key 1)))
1137 (format "%s %s=\"%s\""
1139 (www-format-encode-string
1140 (format "%s" val) 'without-tags))))
1143 (defun www-xml-format-unit (format-unit)
1144 (let (name props children ret)
1146 ((stringp format-unit)
1147 (mapconcat (lambda (c)
1150 ;; ((eq c ?<) "&lt;")
1151 ;; ((eq c ?>) "&gt;")
1153 (char-to-string c))))
1154 (www-format-encode-string format-unit 'without-tags)
1157 ((consp format-unit)
1158 (setq name (car format-unit)
1159 props (nth 1 format-unit)
1160 children (nthcdr 2 format-unit))
1161 (when (eq name 'link)
1162 (setq ret (plist-get props :ref))
1163 (unless (stringp ret)
1164 (setq props (plist-remprop (copy-list props) :ref))
1166 (cons (list* 'ref nil ret)
1169 (format "<%s%s>%s</%s>"
1172 (www-xml-format-props props)
1174 (www-xml-format-list children)
1177 name (www-xml-format-props props)))
1180 (format "%s" format-unit)))))
1182 (defun www-xml-format-list (format-list)
1183 (if (atom format-list)
1184 (www-xml-format-unit format-list)
1185 (mapconcat #'www-xml-format-unit
1189 ;;; @ HTML generator
1192 (defun www-html-display-text (text)
1196 (goto-char (point-min))
1197 (while (search-forward "<" nil t)
1198 (replace-match "<" nil t))
1199 (goto-char (point-min))
1200 (while (search-forward ">" nil t)
1201 (replace-match ">" nil t))
1202 (goto-char (point-min))
1203 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1205 (format "<a href=\"%s\">%s</a>"
1209 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1210 (goto-char (point-min))
1211 (while (search-forward ">-" nil t)
1212 (replace-match "&GT-" nil t))
1215 (defun www-html-display-paragraph (text)
1217 (www-html-display-text text)
1224 (defvar coded-charset-GlyphWiki-id-alist
1225 '((=ucs "u" 4 x nil)
1226 (=ucs@JP "u" 4 x nil)
1227 (=ucs@jis "u" 4 x nil)
1228 (=ucs@gb "u" 4 x "-g")
1229 (=ucs@cns "u" 4 x "-t")
1230 (=ucs@ks "u" 4 x "-k")
1231 (=ucs@iso "u" 4 x "-u")
1232 (=ucs@unicode "u" 4 x "-us")
1233 (=adobe-japan1-6 "aj1-" 5 d nil)
1235 (=big5-cdp "cdp-" 4 x nil)
1236 (=cbeta "cb" 5 d nil)
1237 (=jis-x0208@1978/1pr "j78-" 4 x nil)
1238 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1239 (=jis-x0208@1978 "j78-" 4 x nil)
1240 (=jis-x0208@1983 "j83-" 4 x nil)
1241 (=jis-x0208@1990 "j90-" 4 x nil)
1242 (=jis-x0212 "jsp-" 4 x nil)
1243 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
1244 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
1245 (=jis-x0213-2 "jx2-" 4 x nil)
1246 (=cns11643-1 "c1-" 4 x nil)
1247 (=cns11643-2 "c2-" 4 x nil)
1248 (=cns11643-3 "c3-" 4 x nil)
1249 (=cns11643-4 "c4-" 4 x nil)
1250 (=cns11643-5 "c5-" 4 x nil)
1251 (=cns11643-6 "c6-" 4 x nil)
1252 (=cns11643-7 "c7-" 4 x nil)
1253 (=daikanwa "dkw-" 5 d nil)
1254 (=gt-k "gt-k" 5 d nil)
1255 (=jef-china3 "jc3-" 4 x nil)
1256 (=big5 "b-" 4 x nil)
1257 (=ks-x1001 "k0-" 4 x nil)
1260 (defun char-GlyphWiki-id (char)
1261 (let ((rest coded-charset-GlyphWiki-id-alist)
1264 (setq spec (pop rest))
1265 (null (setq ret (char-feature char (car spec))))))
1268 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1270 ((and (or (encode-char char '=jis-x0208@1990)
1271 (encode-char char '=jis-x0212)
1272 (encode-char char '=jis-x0213-1))
1273 (setq code (encode-char char '=ucs@jis)))
1274 (format "u%04x" code)
1276 ((and (or (encode-char char '=gb2312)
1277 (encode-char char '=gb12345))
1278 (setq code (encode-char char '=ucs@gb)))
1279 (format "u%04x-g" code)
1281 ((and (or (encode-char char '=cns11643-1)
1282 (encode-char char '=cns11643-2)
1283 (encode-char char '=cns11643-3)
1284 (encode-char char '=cns11643-4)
1285 (encode-char char '=cns11643-5)
1286 (encode-char char '=cns11643-6)
1287 (encode-char char '=cns11643-7))
1288 (setq code (encode-char char '=ucs@cns)))
1289 (format "u%04x-t" code)
1291 ((and (encode-char char '=ks-x1001)
1292 (setq code (encode-char char '=ucs@ks)))
1293 (format "u%04x-k" code)
1295 (format (format "%s%%0%d%s%s"
1299 (or (nth 4 spec) ""))
1306 (provide 'cwiki-common)
1308 ;;; cwiki-common.el ends here