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
44 output-string subtype)
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)))
72 (setq subtype (plist-get props :subtype))
74 (est-format-list children output-format
75 without-edit as-property separator subtype))
77 ((eq output-format 'html)
78 (setq props (list* :class name props)
84 ((eq output-format 'html)
86 (when (setq object (plist-get props :object))
90 (list :href (www-uri-make-object-url object))
93 ((eq output-format 'wiki-text)
94 (when (setq object (plist-get props :object))
97 (est-object-genre object)
98 (est-format-object object))))
101 ((eq name 'prev-char)
103 ((eq output-format 'wiki-text)
104 (setq output-string "{{prev-char}}")
106 ((and (eq output-format 'html)
107 (setq object (plist-get props :object))
108 (setq feature (plist-get props :feature))
109 (setq value (www-get-feature-value object feature))
110 (setq ret (find-previous-defined-code-point feature value)))
114 (list :href (www-uri-make-object-url ret))
118 ((eq name 'next-char)
120 ((eq output-format 'wiki-text)
121 (setq output-string "{{next-char}}")
123 ((and (eq output-format 'html)
124 (setq object (plist-get props :object))
125 (setq feature (plist-get props :feature))
126 (setq value (www-get-feature-value object feature))
127 (setq ret (find-next-defined-code-point feature value)))
131 (list :href (www-uri-make-object-url ret))
137 ((eq output-format 'wiki-text)
138 (setq output-string "{{...}}")
140 ((and (eq output-format 'html)
141 (setq object (plist-get props :object))
142 (setq feature (plist-get props :feature)))
147 (concat (www-uri-make-object-url object)
149 (www-uri-encode-feature-name feature)))
153 ((eq name 'feature-name)
155 (when (eq output-format 'html)
156 (when (and (setq object (plist-get props :object))
157 (setq feature (plist-get props :feature)))
162 (www-uri-make-feature-name-url
163 (est-object-genre object)
164 (www-uri-encode-feature-name feature)
165 (www-uri-encode-object object)))
170 ((eq output-format 'wiki-text)
172 (if (and (setq object (plist-get props :object))
173 (setq feature (plist-get props :feature)))
174 (format "{{value %s %s=%s}}"
176 (est-object-genre object)
177 (www-uri-encode-object object))
180 ((eq output-format 'html)
182 (if (consp (car children))
187 (list (list 'edit-value
189 (list* :format format props)
192 (:type "submit" :value "edit")))))))
194 props (list* :class "value" props))
197 ((or (and (eq name 'link)
198 (setq ret (plist-get props :ref)))
200 (setq ret (plist-get props :href))))
202 ((eq output-format 'wiki-text)
205 (est-format-list children output-format)
206 (est-format-unit ret output-format)
209 ((eq output-format 'html)
211 props (list* :href ret
212 (plist-remprop (copy-list props) :ref)))
214 ((eq output-format 'xml)
215 (unless (stringp ret)
216 (setq props (plist-remprop (copy-list props) :ref))
218 (cons (list 'ref nil ret)
222 ((and (eq name 'edit-value)
223 (setq object (plist-get props :object))
224 (setq feature (plist-get props :feature)))
225 (setq format (or (plist-get props :format) 'default))
227 props (list :href (format "%s?%s=%s&feature=%s&format=%s"
229 (est-object-genre object)
230 (www-uri-encode-object object)
231 (www-uri-encode-feature-name feature)
240 (when (eq output-format 'html)
241 (setq props (list* :class name props)
248 (setq separator (plist-get props :separator)))
249 (setq subtype (plist-get props :subtype))
252 ((eq output-format 'plain-text)
253 (est-format-list children output-format as-property separator
256 ((eq subtype 'unordered-list)
257 (format "<ul\n%s><li\n>%s</li></ul\n>"
259 (est-format-props props)
262 children output-format
263 without-edit as-property "</li\n><li\n>")
268 (format "<%s%s>%s</%s>"
271 (est-format-props props)
274 children output-format
275 without-edit as-property separator)
278 (if (eq output-format 'plain-text)
281 name (est-format-props props))))
285 (format "%s" format-unit)))))
287 (defun est-format-list (format-list
288 &optional output-format without-edit as-property
293 format-list output-format without-edit as-property separator)
295 ((eq subtype 'unordered-list)
297 (mapconcat (lambda (unit)
299 unit output-format without-edit as-property separator))
300 format-list "</li\n><li>")
304 (mapconcat (lambda (unit)
306 unit output-format without-edit as-property))
307 format-list separator)
314 (provide 'est-format)
316 ;;; est-format.el ends here