1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'cwiki-common)
8 (defun est-format-props (props)
15 (setq key (symbol-name key)))
16 (if (eq (aref key 0) ?:)
17 (setq key (substring key 1)))
19 (format "%s %s=\"%s\""
21 (www-format-encode-string
23 (est-format-unit val 'without-tags
24 'without-edit 'as-property))
28 (defun est-format-unit (format-unit
29 &optional output-format without-edit as-property
32 ((or (eq output-format 'without-tags)
34 (setq output-format 'plain-text)
36 ((eq output-format 'wiki-text)
38 ((eq output-format 'xml)
41 (setq output-format 'html)
43 (let (name props children ret object feature format value
46 ((stringp format-unit)
47 (www-format-encode-string format-unit
48 (not (eq output-format 'html))
51 ((characterp format-unit)
52 (www-format-encode-string (format "%S" format-unit)
53 (not (eq output-format 'html))
56 ((symbolp format-unit)
57 (www-format-encode-string (format "%s" format-unit)
58 (not (eq output-format 'html))
62 (setq name (car format-unit)
63 props (nth 1 format-unit)
64 children (nthcdr 2 format-unit))
68 ((or (eq output-format 'plain-text)
69 (eq output-format 'wiki-text))
71 (setq separator (plist-get props :separator)))
73 (est-format-list children output-format
74 without-edit as-property separator))
76 ((eq output-format 'html)
77 (setq props (list* :class name props)
83 ((eq output-format 'html)
85 (when (setq object (plist-get props :object))
89 (list :href (www-uri-make-object-url object))
92 ((eq output-format 'wiki-text)
93 (when (setq object (plist-get props :object))
96 (est-object-genre object)
97 (est-format-object object))))
100 ((eq name 'prev-char)
102 ((eq output-format 'wiki-text)
103 (setq output-string "{{prev-char}}")
105 ((and (eq output-format 'html)
106 (setq object (plist-get props :object))
107 (setq feature (plist-get props :feature))
108 (setq value (www-get-feature-value object feature))
109 (setq ret (find-previous-defined-code-point feature value)))
113 (list :href (www-uri-make-object-url ret))
117 ((eq name 'next-char)
119 ((eq output-format 'wiki-text)
120 (setq output-string "{{next-char}}")
122 ((and (eq output-format 'html)
123 (setq object (plist-get props :object))
124 (setq feature (plist-get props :feature))
125 (setq value (www-get-feature-value object feature))
126 (setq ret (find-next-defined-code-point feature value)))
130 (list :href (www-uri-make-object-url ret))
134 ((eq name 'feature-name)
136 (when (eq output-format 'html)
137 (when (and (setq object (plist-get props :object))
138 (setq feature (plist-get props :feature)))
143 (www-uri-make-feature-name-url
144 (est-object-genre object)
145 (www-uri-encode-feature-name feature)
146 (www-uri-encode-object object)))
151 ((eq output-format 'wiki-text)
153 (if (and (setq object (plist-get props :object))
154 (setq feature (plist-get props :feature)))
155 (format "{{value %s %s=%s}}"
157 (est-object-genre object)
158 (www-uri-encode-object object))
161 ((eq output-format 'html)
163 (if (consp (car children))
168 (list (list 'edit-value
170 (list* :format format props)
173 (:type "submit" :value "edit")))))))
175 props (list* :class "value" props))
178 ((or (and (eq name 'link)
179 (setq ret (plist-get props :ref)))
181 (setq ret (plist-get props :href))))
183 ((eq output-format 'wiki-text)
186 (est-format-list children output-format)
187 (est-format-unit ret output-format)
190 ((eq output-format 'html)
192 props (list* :href ret
193 (plist-remprop (copy-list props) :ref)))
195 ((eq output-format 'xml)
196 (unless (stringp ret)
197 (setq props (plist-remprop (copy-list props) :ref))
199 (cons (list 'ref nil ret)
203 ((and (eq name 'edit-value)
204 (setq object (plist-get props :object))
205 (setq feature (plist-get props :feature)))
206 (setq format (or (plist-get props :format) 'default))
208 props (list :href (format "%s?%s=%s&feature=%s&format=%s"
210 (est-object-genre object)
211 (www-uri-encode-object object)
212 (www-uri-encode-feature-name feature)
221 (when (eq output-format 'html)
222 (setq props (list* :class name props)
229 (setq separator (plist-get props :separator)))
231 (if (eq output-format 'plain-text)
232 (est-format-list children output-format as-property separator)
233 (format "<%s%s>%s</%s>"
236 (est-format-props props)
239 children output-format
240 without-edit as-property separator)
242 (if (eq output-format 'plain-text)
245 name (est-format-props props))))
249 (format "%s" format-unit)))))
251 (defun est-format-list (format-list
252 &optional output-format without-edit as-property
254 (if (atom format-list)
256 format-list output-format without-edit as-property separator)
257 (mapconcat (lambda (unit)
259 unit output-format without-edit as-property separator))
260 format-list separator)))
266 (provide 'est-format)
268 ;;; est-format.el ends here