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\""
22 (est-format-unit val 'without-tags
23 'without-edit 'as-property))
27 (defun est-format-unit (format-unit
28 &optional output-format without-edit as-property
31 ((or (eq output-format 'without-tags)
33 (setq output-format 'plain-text)
35 ((eq output-format 'wiki-text)
37 ((eq output-format 'xml)
40 (setq output-format 'html)
42 (let (name props children ret object feature format value
43 output-string subtype)
45 ((stringp format-unit)
46 (www-format-encode-string format-unit
47 (not (eq output-format 'html))
50 ((characterp format-unit)
51 (www-format-encode-string (format "%S" format-unit)
52 (not (eq output-format 'html))
55 ((symbolp format-unit)
56 (www-format-encode-string (format "%s" format-unit)
57 (not (eq output-format 'html))
61 (setq name (car format-unit)
62 props (nth 1 format-unit)
63 children (nthcdr 2 format-unit))
67 ((or (eq output-format 'plain-text)
68 (eq output-format 'wiki-text))
70 (setq separator (plist-get props :separator)))
71 (setq subtype (plist-get props :subtype))
73 (est-format-list children output-format
74 without-edit as-property separator subtype))
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))
136 ((eq output-format 'wiki-text)
137 (setq output-string "{{...}}")
139 ((and (eq output-format 'html)
140 (setq object (plist-get props :object))
141 (setq feature (plist-get props :feature)))
146 (concat (www-uri-make-object-url object)
147 (if est-hide-cgi-mode
150 (www-uri-encode-feature-name feature)))
154 ((eq name 'feature-name)
156 (when (eq output-format 'html)
157 (when (and (setq object (plist-get props :object))
158 (setq feature (plist-get props :feature)))
162 '(:class "feature-name")
165 (www-uri-make-feature-name-url
166 (est-object-genre object)
167 (www-uri-encode-feature-name feature)
168 (www-uri-encode-object object)))
173 ((eq output-format 'wiki-text)
175 (if (and (setq object (plist-get props :object))
176 (setq feature (plist-get props :feature)))
177 (format "{{value %s %s=%s}}"
179 (est-object-genre object)
180 (www-uri-encode-object object))
183 ((eq output-format 'html)
185 (if (consp (car children))
190 (list (list 'edit-value
192 (list* :format format props)
195 (:type "submit" :value "edit")))))))
197 props (list* :class "value" props))
200 ((or (and (eq name 'link)
201 (setq ret (plist-get props :ref)))
203 (setq ret (plist-get props :href))))
205 ((eq output-format 'wiki-text)
208 (est-format-list children output-format)
209 (est-format-unit ret output-format)
212 ((eq output-format 'html)
214 props (list* :href ret
215 (plist-remprop (copy-list props) :ref)))
217 ((eq output-format 'xml)
218 (unless (stringp ret)
219 (setq props (plist-remprop (copy-list props) :ref))
221 (cons (list 'ref nil ret)
225 ((and (eq name 'edit-value)
226 (setq object (plist-get props :object))
227 (setq feature (plist-get props :feature)))
228 (setq format (or (plist-get props :format) 'default))
230 props (list :href (format "%s?%s=%s&feature=%s&format=%s"
232 (est-object-genre object)
233 (www-uri-encode-object object)
234 (www-uri-encode-feature-name feature)
243 (when (eq output-format 'html)
244 (setq props (list* :class name props)
251 (setq separator (plist-get props :separator)))
252 (setq subtype (plist-get props :subtype))
255 ((eq output-format 'plain-text)
256 (est-format-list children output-format as-property separator
259 ((eq subtype 'unordered-list)
260 (format "<ul\n%s><li\n>%s</li></ul\n>"
262 (est-format-props props)
265 children output-format
266 without-edit as-property "</li\n><li\n>")
271 (format "<%s%s>%s</%s>"
274 (est-format-props props)
277 children output-format
278 without-edit as-property separator)
281 (if (eq output-format 'plain-text)
284 name (est-format-props props))))
288 (format "%s" format-unit)))))
290 (defun est-format-list (format-list
291 &optional output-format without-edit as-property
296 format-list output-format without-edit as-property separator)
298 ((eq subtype 'unordered-list)
300 (mapconcat (lambda (unit)
302 unit output-format without-edit as-property separator))
303 format-list "</li\n><li>")
307 (mapconcat (lambda (unit)
309 unit output-format without-edit as-property))
310 format-list separator)
317 (provide 'est-format)
319 ;;; est-format.el ends here