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)
52 (let ((type (www-feature-type feature-name)))
53 (cond ((eq type 'relation)
54 'space-separated-char-list)
60 (if (find-charset feature-name)
61 (if (and (= (charset-dimension feature-name) 2)
62 (= (charset-chars feature-name) 94))
64 " (" (decimal) ") <" (ku-ten) ">")
65 '("0x" (HEX) " (" (decimal) ")")))))
67 (defun char-feature-name-at-domain (feature-name domain)
68 (let ((name (symbol-name feature-name)))
70 ((string-match "@[^*]+$" name)
71 (intern (format "%s/%s" name domain))
74 (intern (format "%s@%s" name domain))
77 (defun char-feature-name-sans-versions (feature)
78 (let ((feature-name (symbol-name feature)))
79 (if (string-match "[@/]\\$rev=latest$" feature-name)
80 (intern (substring feature-name 0 (match-beginning 0)))
83 (defun www-char-feature (character feature)
84 (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
85 (mount-char-attribute-table latest-feature)
86 (or (char-feature character latest-feature)
87 (char-feature character feature))))
90 ;;; @ URI representation
93 (defun www-uri-decode-feature-name (uri-feature)
96 ((string-match "^from\\." uri-feature)
97 (intern (format "<-%s" (substring uri-feature (match-end 0))))
99 ((string-match "^to\\." uri-feature)
100 (intern (format "->%s" (substring uri-feature (match-end 0))))
102 ((string-match "^rep\\." uri-feature)
103 (intern (format "=%s" (substring uri-feature (match-end 0))))
105 ((string-match "^g\\." uri-feature)
106 (intern (format "=>>%s" (substring uri-feature (match-end 0))))
108 ((string-match "^gi\\." uri-feature)
109 (intern (format "=>>>%s" (substring uri-feature (match-end 0))))
111 ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
112 (intern (format "=>>%s%s"
113 (make-string (string-to-int
114 (match-string 1 uri-feature))
116 (substring uri-feature (match-end 0))))
118 ((string-match "^a\\." uri-feature)
119 (intern (format "=>%s" (substring uri-feature (match-end 0))))
121 ((string-match "^a\\([0-9]+\\)\\." uri-feature)
122 (intern (format "%s>%s"
123 (make-string (string-to-int
124 (match-string 1 uri-feature))
126 (substring uri-feature (match-end 0))))
128 ((and (setq feature (intern (format "=>%s" uri-feature)))
129 (find-charset feature))
131 ((and (setq feature (intern (format "=>>%s" uri-feature)))
132 (find-charset feature))
134 ((and (setq feature (intern (format "=>>>%s" uri-feature)))
135 (find-charset feature))
137 ((and (setq feature (intern (format "=%s" uri-feature)))
138 (find-charset feature))
140 (t (intern uri-feature)))))
142 (defun www-uri-encode-feature-name (feature-name)
143 (setq feature-name (symbol-name feature-name))
145 ((string-match "^=\\([^=>]+\\)" feature-name)
146 (concat "rep." (substring feature-name (match-beginning 1)))
148 ((string-match "^=>>\\([^=>]+\\)" feature-name)
149 (concat "g." (substring feature-name (match-beginning 1)))
151 ((string-match "^=>>>\\([^=>]+\\)" feature-name)
152 (concat "gi." (substring feature-name (match-beginning 1)))
154 ((string-match "^=>>\\(>+\\)" feature-name)
156 (length (match-string 1 feature-name))
157 (substring feature-name (match-end 1)))
159 ((string-match "^=>\\([^=>]+\\)" feature-name)
160 (concat "a." (substring feature-name (match-beginning 1)))
162 ((string-match "^\\(=+\\)>" feature-name)
164 (length (match-string 1 feature-name))
165 (substring feature-name (match-end 0)))
167 ((string-match "^->" feature-name)
168 (concat "to." (substring feature-name (match-end 0)))
170 ((string-match "^<-" feature-name)
171 (concat "from." (substring feature-name (match-end 0)))
175 (defun www-uri-decode-char (char-rep)
178 ((string-match "\\(%3A\\|:\\)" char-rep)
179 (setq ccs (substring char-rep 0 (match-beginning 0))
180 cpos (substring char-rep (match-end 0)))
181 (setq ccs (www-uri-decode-feature-name ccs))
183 ((string-match "^0x" cpos)
185 (string-to-number (substring cpos (match-end 0)) 16))
188 (setq cpos (string-to-number cpos))
191 (decode-char ccs cpos))
194 (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
195 (when (= (length char-rep) 1)
199 (defun www-uri-encode-char (char)
200 (if (encode-char char '=ucs)
203 (format "%%%02X" byte))
204 (encode-coding-string (char-to-string char) 'utf-8-mcs-er)
206 (let ((ccs-list '(; =ucs
207 =cns11643-1 =cns11643-2 =cns11643-3
208 =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
210 =jis-x0208 =jis-x0208@1990
213 =jis-x0213-1@2000 =jis-x0213-1@2004
214 =jis-x0208@1983 =jis-x0208@1978
215 =zinbun-oracle =>zinbun-oracle
218 =>>jis-x0208 =>>jis-x0213-1
219 =>jis-x0208 =>jis-x0213-1
226 (setq ccs (pop ccs-list))
227 (not (setq ret (encode-char char ccs 'defined-only)))))
230 (www-uri-encode-feature-name ccs)
232 ((and (setq ccs (car (split-char char)))
233 (setq ret (encode-char char ccs)))
235 (www-uri-encode-feature-name ccs)
238 (format "system-char-id:0x%X"
239 (encode-char char 'system-char-id))
243 ;;; @ Feature name presentation
246 (defun www-format-feature-name-default (feature-name)
250 (symbol-name feature-name)
254 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
255 (let ((str (symbol-name feature-name))
258 ((string-match "\\*[^*]+$" str)
259 (setq base (substring str 0 (match-beginning 0))
260 meta (substring str (match-beginning 0)))
261 (concat (www-format-feature-name* (intern base) lang)
264 (www-format-feature-name-default feature-name)
267 (defun www-format-feature-name-as-rel-to (feature-name)
268 (concat "\u2192" (substring (symbol-name feature-name) 2)))
270 (defun www-format-feature-name-as-rel-from (feature-name)
271 (concat "\u2190" (substring (symbol-name feature-name) 2)))
273 (defun www-format-feature-name-as-CCS (feature-name)
276 (symbol-name feature-name)
278 (dest (upcase (pop rest))))
279 (when (string-match "^=+>*" dest)
280 (setq dest (concat (substring dest 0 (match-end 0))
282 (substring dest (match-end 0)))))
286 (setq dest (concat dest " " (upcase (pop rest)))))
287 (if (string-match "^[0-9]+$" (car rest))
288 (concat dest "-" (car rest))
289 (concat dest " " (upcase (car rest))))
293 (defun www-format-feature-name* (feature-name &optional lang)
297 (char-feature-property
299 (intern (format "name@%s" lang))))
300 (char-feature-property
301 feature-name 'name)))
302 ((find-charset feature-name)
303 (www-format-feature-name-as-CCS feature-name))
304 ((and (setq name (symbol-name feature-name))
305 (string-match "\\*" name))
306 (www-format-feature-name-as-metadata feature-name lang))
307 ((string-match "^\\(->\\)" name)
308 (www-format-feature-name-as-rel-to feature-name))
309 ((string-match "^\\(<-\\)" name)
310 (www-format-feature-name-as-rel-from feature-name))
312 (www-format-feature-name-default feature-name)))))
314 (defun www-format-feature-name (feature-name &optional lang)
315 (www-format-encode-string
316 (www-format-feature-name* feature-name lang)))
319 ;;; @ Feature value presentation
322 (defun www-format-value-as-kuten (value)
324 (- (lsh value -8) 32)
325 (- (logand value 255) 32)))
327 (defun www-format-value-default (value &optional without-tags)
331 (www-format-encode-string
335 (www-format-encode-string (format "%S" value) without-tags)))
337 (defun www-format-value-as-char-list (value &optional without-tags)
342 (www-format-encode-string
343 (format (if (characterp unit)
349 (if (characterp unit)
350 (format "<a href=\"%s?char=%s\">%s</a>"
352 (www-uri-encode-char unit)
353 (www-format-encode-string (char-to-string unit)))
354 (www-format-encode-string (format "%s" unit)))))
356 (www-format-encode-string (format "%s" value) without-tags)))
358 (defun www-format-value-as-domain-list (value &optional without-tags)
359 (let (name source0 source num dest rest unit start end ddest)
368 (setq unit (pop rest))
370 (setq name (symbol-name unit)))
375 ((string-match "^zob1968=" name)
376 (setq source (intern (substring name 0 (match-end 0)))
377 num (substring name (match-end 0)))
378 (if (string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" num)
379 (setq start (string-to-number
380 (match-string 1 num))
381 end (string-to-number
382 (match-string 2 num)))
383 (setq start (string-to-number num)
386 (if (eq source source0)
388 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
390 (setq source0 source)
392 " <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>"
393 (www-format-encode-string "\u4EAC大人\u6587ç ”ç”²\u9AA8")
395 (setq start (1+ start))
396 (while (<= start end)
401 ", <a href=\"http://chise.zinbun.kyoto-u.ac.jp/koukotsu/rubbings/%04d\">%04d</a>"
403 (setq start (1+ start)))
407 (if (eq source source0)
409 (setq source0 source)
413 (www-format-encode-string (format "%s" value) without-tags))))
415 (defun www-format-value-as-ids (value &optional without-tags)
420 (www-format-encode-string
421 (format (if (characterp unit)
427 (if (characterp unit)
428 (format "<a href=\"%s?char=%s\">%s</a>"
430 (www-uri-encode-char unit)
431 (www-format-encode-string (char-to-string unit)))
432 (www-format-encode-string (format "%s" unit)))))
433 (ideographic-structure-to-ids value) " ")
434 (www-format-encode-string (format "%s" value) without-tags)))
436 (defun www-format-value-as-S-exp (value &optional without-tags)
437 (www-format-encode-string (format "%S" value) without-tags))
439 (defun www-format-value-as-HEX (value)
442 (www-format-value-as-S-exp value)))
444 (defun www-format-value-as-CCS-default (value)
447 (www-format-value-as-HEX value)
449 (www-format-value-as-S-exp value)))
451 (defun www-format-value-as-CCS-94x94 (value)
453 (format "0x%s [%s] (%d)"
454 (www-format-value-as-HEX value)
455 (www-format-value-as-kuten value)
457 (www-format-value-as-S-exp value)))
459 (defun www-format-value-as-kangxi-radical (value)
460 (if (and (integerp value)
463 (www-format-encode-string
464 (format "%c" (ideographic-radical value)))
465 (www-format-value-as-S-exp value)))
467 (defun www-format-value (object feature-name
468 &optional value format
469 without-tags without-edit)
471 (setq value (www-char-feature object feature-name)))
472 (www-format-apply-value object feature-name
473 format nil value nil nil
474 without-tags without-edit)
478 ;;; @ format evaluator
481 (defun www-format-encode-string (string &optional without-tags)
484 (let (plane code start end char variants ret rret)
485 (goto-char (point-min))
486 (while (search-forward "<" nil t)
487 (replace-match "<" nil t))
488 (goto-char (point-min))
489 (while (search-forward ">" nil t)
490 (replace-match ">" nil t))
492 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
493 (let ((coded-charset-entity-reference-alist
496 '(=cns11643-1 "C1-" 4 X)
497 '(=cns11643-2 "C2-" 4 X)
498 '(=cns11643-3 "C3-" 4 X)
499 '(=cns11643-4 "C4-" 4 X)
500 '(=cns11643-5 "C5-" 4 X)
501 '(=cns11643-6 "C6-" 4 X)
502 '(=cns11643-7 "C7-" 4 X)
504 '(=gb12345 "G1-" 4 X)
505 '(=jis-x0208@1990 "J90-" 4 X)
506 '(=jis-x0212 "JSP-" 4 X)
508 '(=jis-x0208@1997 "J97-" 4 X)
509 '(=jis-x0208@1978 "J78-" 4 X)
510 '(=jis-x0208@1983 "J83-" 4 X)
511 '(=ruimoku-v6 "RUI6-" 4 X)
512 '(=zinbun-oracle "ZOB-" 4 d)
513 '(=jef-china3 "JC3-" 4 X)
514 '(=daikanwa "M-" 5 d)
515 coded-charset-entity-reference-alist)))
516 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
518 (goto-char (point-min))
519 (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
520 (setq code (string-to-int (match-string 1)))
522 (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\">"
524 chise-wiki-bitmap-glyphs-url
528 (goto-char (point-min))
529 (while (re-search-forward "&J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
530 (setq plane (match-string 1)
531 code (string-to-int (match-string 2) 16))
533 (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\">"
535 chise-wiki-bitmap-glyphs-url
538 (- (logand code 255) 32))
541 (goto-char (point-min))
542 (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
543 (setq plane (string-to-int (match-string 1))
544 code (string-to-int (match-string 2) 16))
546 (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\">"
548 chise-wiki-bitmap-glyphs-url
551 (- (logand code 255) 32))
554 (goto-char (point-min))
555 (while (re-search-forward "&C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
556 (setq plane (string-to-int (match-string 1))
557 code (string-to-int (match-string 2) 16))
559 (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\">"
561 chise-wiki-bitmap-glyphs-url
565 (goto-char (point-min))
566 (while (re-search-forward "&JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
567 (setq code (string-to-int (match-string 1) 16))
569 (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
573 (goto-char (point-min))
574 (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
575 (setq code (string-to-int (match-string 2)))
577 (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\">"
579 chise-wiki-bitmap-glyphs-url
583 (goto-char (point-min))
584 (while (re-search-forward "&\\(G-\\)?GT-\\([0-9]+\\);" nil t)
585 (setq code (string-to-int (match-string 2)))
587 (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\">"
589 chise-wiki-glyph-cgi-url
593 (goto-char (point-min))
594 (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
595 (setq code (string-to-int (match-string 2)))
597 (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\">"
599 chise-wiki-glyph-cgi-url
603 (goto-char (point-min))
604 (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
605 (setq code (string-to-int (match-string 1) 16))
607 (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\">"
609 chise-wiki-glyph-cgi-url
613 (goto-char (point-min))
614 (while (re-search-forward "&CDP-\\([0-9A-F]+\\);" nil t)
615 (setq code (string-to-int (match-string 1) 16))
617 (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\">"
619 chise-wiki-glyph-cgi-url
623 (goto-char (point-min))
624 (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
625 (setq code (string-to-int (match-string 1) 16))
627 (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\">"
629 chise-wiki-glyph-cgi-url
633 (goto-char (point-min))
634 (while (re-search-forward "&\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
635 (setq code (string-to-int (match-string 2) 16))
637 (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\">"
642 (goto-char (point-min))
643 (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
644 (setq code (string-to-int (match-string 1) 16))
645 (setq start (match-beginning 0)
647 (setq char (decode-char 'system-char-id code))
650 (or (www-char-feature char '->subsumptive)
651 (www-char-feature char '->denotational)))
654 (setq ret (www-format-encode-string
655 (char-to-string (car variants))))
656 (string-match "&MCS-\\([0-9A-F]+\\);" ret))
657 (setq variants (cdr variants)))
659 (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
661 (delete-region start end)
664 ((setq ret (or (www-char-feature char 'ideographic-combination)
665 (www-char-feature char 'ideographic-structure)))
670 (if (characterp (setq rret (find-char ch)))
673 (www-format-encode-string
674 (char-to-string ch) without-tags)
675 (www-format-encode-string
676 (format "%S" ch) without-tags)))
680 (delete-region start end)
684 ;; (goto-char (point-min))
685 ;; (while (search-forward ">-" nil t)
686 ;; (replace-match "&GT-" t 'literal))
689 (defun www-format-props-to-string (props &optional format)
691 (setq format (plist-get props :format)))
693 (plist-get props :flag)
694 ;; (if (plist-get props :zero-padding)
696 (if (plist-get props :len)
697 (format "0%d" (plist-get props :len)))
699 ((eq format 'decimal) "d")
700 ((eq format 'hex) "x")
701 ((eq format 'HEX) "X")
702 ((eq format 'S-exp) "S")
705 (defun www-format-apply-value (object feature-name
707 &optional uri-char uri-feature
708 without-tags without-edit)
712 ((memq format '(decimal hex HEX))
714 (format (www-format-props-to-string props format)
716 (www-format-encode-string
720 ((eq format 'wiki-text)
722 (www-xml-format-list value)
723 (www-format-eval-list value object feature-name nil uri-char
724 without-tags without-edit))
727 (www-format-encode-string
728 (format (www-format-props-to-string props format)
732 (www-format-value-as-kuten value))
733 ((eq format 'kangxi-radical)
734 (www-format-value-as-kangxi-radical value))
735 ((eq format 'space-separated-char-list)
736 (www-format-value-as-char-list value without-tags))
737 ((eq format 'space-separated-ids)
738 (www-format-value-as-ids value without-tags))
739 ((eq format 'space-separated-domain-list)
740 (www-format-value-as-domain-list value without-tags))
742 (www-format-encode-string (format "%s" value) without-tags)
745 (www-format-value-default value without-tags)
750 (eq (plist-get props :mode) 'peek))
752 (format "%s <a href=\"%s?char=%s&feature=%s&format=%s\"
753 ><input type=\"submit\" value=\"edit\" /></a>"
756 uri-char uri-feature format))))
758 (defun www-format-eval-feature-value (char
760 &optional format lang uri-char value
761 without-tags without-edit)
763 (setq value (www-char-feature char feature-name)))
765 (setq format (www-feature-value-format feature-name)))
768 (www-format-apply-value
771 uri-char (www-uri-encode-feature-name feature-name)
772 without-tags without-edit)
775 (cond ((null (cdr format))
776 (setq format (car format))
777 (www-format-apply-value
779 (car format) (nth 1 format) value
780 uri-char (www-uri-encode-feature-name feature-name)
781 without-tags without-edit)
784 (www-format-eval-list format char feature-name lang uri-char
785 without-tags without-edit)
788 (defun www-format-eval-unit (exp char feature-name
789 &optional lang uri-char value
790 without-tags without-edit)
792 (setq value (www-char-feature char feature-name)))
794 (setq uri-char (www-uri-encode-char char)))
796 ((stringp exp) (www-format-encode-string exp))
800 ((memq (car exp) '(value decimal hex HEX ku-ten kangxi-radical
801 S-exp string default))
802 (if (eq (car exp) 'value)
803 (www-format-eval-feature-value char feature-name
804 (plist-get (nth 1 exp) :format)
806 without-tags without-edit)
807 (www-format-apply-value
809 (car exp) (nth 1 exp) value
810 uri-char (www-uri-encode-feature-name feature-name)
811 without-tags without-edit))
813 ((eq (car exp) 'name)
814 (format "<a href=\"%s?feature=%s&char=%s\">%s</a>"
816 (www-uri-encode-feature-name feature-name)
818 (www-format-feature-name feature-name lang))
820 ((eq (car exp) 'link)
825 (www-format-eval-list (plist-get (nth 1 exp) :ref)
826 char feature-name lang uri-char
827 'without-tags 'without-edit)
828 (www-format-eval-list (nthcdr 2 exp)
829 char feature-name lang uri-char
830 without-tags without-edit)))
836 (www-format-eval-list (nthcdr 2 exp) char feature-name
838 without-tags without-edit)
841 (defun www-format-eval-list (format-list char feature-name
842 &optional lang uri-char
843 without-tags without-edit)
844 (if (consp format-list)
847 (www-format-eval-unit exp char feature-name lang uri-char
848 nil without-tags without-edit))
850 (www-format-eval-unit format-list char feature-name lang uri-char
851 nil without-tags without-edit)))
857 (defun www-xml-format-props (props)
861 (setq key (pop props)
864 (setq key (symbol-name key)))
865 (if (eq (aref key 0) ?:)
866 (setq key (substring key 1)))
868 (format "%s %s=\"%s\""
870 (www-format-encode-string
871 (format "%s" val) 'without-tags))))
874 (defun www-xml-format-unit (format-unit)
875 (let (name props children ret)
877 ((stringp format-unit)
878 (mapconcat (lambda (c)
881 ;; ((eq c ?<) "&lt;")
882 ;; ((eq c ?>) "&gt;")
884 (char-to-string c))))
885 (www-format-encode-string format-unit 'without-tags)
889 (setq name (car format-unit)
890 props (nth 1 format-unit)
891 children (nthcdr 2 format-unit))
892 (when (eq name 'link)
893 (setq ret (plist-get props :ref))
894 (unless (stringp ret)
895 (setq props (plist-remprop (copy-list props) :ref))
897 (cons (list* 'ref nil ret)
900 (format "<%s%s>%s</%s>"
903 (www-xml-format-props props)
905 (www-xml-format-list children)
908 name (www-xml-format-props props)))
911 (format "%s" format-unit)))))
913 (defun www-xml-format-list (format-list)
914 (if (atom format-list)
915 (www-xml-format-unit format-list)
916 (mapconcat #'www-xml-format-unit
923 (defun www-html-display-text (text)
927 (goto-char (point-min))
928 (while (search-forward "<" nil t)
929 (replace-match "<" nil t))
930 (goto-char (point-min))
931 (while (search-forward ">" nil t)
932 (replace-match ">" nil t))
933 (goto-char (point-min))
934 (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
936 (format "<a href=\"%s\">%s</a>"
940 (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
941 (goto-char (point-min))
942 (while (search-forward ">-" nil t)
943 (replace-match "&GT-" nil t))
946 (defun www-html-display-paragraph (text)
948 (www-html-display-text text)
955 (defvar coded-charset-GlyphWiki-id-alist
957 (=ucs@JP "u" 4 x nil)
958 (=ucs@jis "u" 4 x nil)
959 (=ucs@gb "u" 4 x "-g")
960 (=ucs@cns "u" 4 x "-t")
961 (=ucs@ks "u" 4 x "-k")
962 (=ucs@iso "u" 4 x "-u")
963 (=ucs@unicode "u" 4 x "-us")
964 (=adobe-japan1-6 "aj1-" 5 d nil)
966 (=big5-cdp "cdp-" 4 x nil)
967 (=cbeta "cb" 5 d nil)
968 (=jis-x0208@1978/1pr "j78-" 4 x nil)
969 (=jis-x0208@1978/-4pr "j78-" 4 x nil)
970 (=jis-x0208@1978 "j78-" 4 x nil)
971 (=jis-x0208@1983 "j83-" 4 x nil)
972 (=jis-x0208@1990 "j90-" 4 x nil)
973 (=jis-x0212 "jsp-" 4 x nil)
974 (=jis-x0213-1@2000 "jx1-2000-" 4 x nil)
975 (=jis-x0213-1@2004 "jx1-2004-" 4 x nil)
976 (=jis-x0213-2 "jx2-" 4 x nil)
977 (=cns11643-1 "c1-" 4 x nil)
978 (=cns11643-2 "c2-" 4 x nil)
979 (=cns11643-3 "c3-" 4 x nil)
980 (=cns11643-4 "c4-" 4 x nil)
981 (=cns11643-5 "c5-" 4 x nil)
982 (=cns11643-6 "c6-" 4 x nil)
983 (=cns11643-7 "c7-" 4 x nil)
984 (=daikanwa "dkw-" 5 d nil)
985 (=gt-k "gt-k" 5 d nil)
986 (=jef-china3 "jc3-" 4 x nil)
988 (=ks-x1001 "k0-" 4 x nil)
991 (defun char-GlyphWiki-id (char)
992 (let ((rest coded-charset-GlyphWiki-id-alist)
995 (setq spec (pop rest))
996 (null (setq ret (char-feature char (car spec))))))
999 (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1001 ((and (or (encode-char char '=jis-x0208@1990)
1002 (encode-char char '=jis-x0212)
1003 (encode-char char '=jis-x0213-1))
1004 (setq code (encode-char char '=ucs@jis)))
1005 (format "u%04x" code)
1007 ((and (or (encode-char char '=gb2312)
1008 (encode-char char '=gb12345))
1009 (setq code (encode-char char '=ucs@gb)))
1010 (format "u%04x-g" code)
1012 ((and (or (encode-char char '=cns11643-1)
1013 (encode-char char '=cns11643-2)
1014 (encode-char char '=cns11643-3)
1015 (encode-char char '=cns11643-4)
1016 (encode-char char '=cns11643-5)
1017 (encode-char char '=cns11643-6)
1018 (encode-char char '=cns11643-7))
1019 (setq code (encode-char char '=ucs@cns)))
1020 (format "u%04x-t" code)
1022 ((and (encode-char char '=ks-x1001)
1023 (setq code (encode-char char '=ucs@ks)))
1024 (format "u%04x-k" code)
1026 (format (format "%s%%0%d%s%s"
1030 (or (nth 4 spec) ""))
1037 (provide 'cwiki-common)
1039 ;;; cwiki-common.el ends here