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))
135 ((eq name 'feature-name)
137 (when (eq output-format 'html)
138 (when (and (setq object (plist-get props :object))
139 (setq feature (plist-get props :feature)))
144 (www-uri-make-feature-name-url
145 (est-object-genre object)
146 (www-uri-encode-feature-name feature)
147 (www-uri-encode-object object)))
152 ((eq output-format 'wiki-text)
154 (if (and (setq object (plist-get props :object))
155 (setq feature (plist-get props :feature)))
156 (format "{{value %s %s=%s}}"
158 (est-object-genre object)
159 (www-uri-encode-object object))
162 ((eq output-format 'html)
164 (if (consp (car children))
169 (list (list 'edit-value
171 (list* :format format props)
174 (:type "submit" :value "edit")))))))
176 props (list* :class "value" props))
179 ((or (and (eq name 'link)
180 (setq ret (plist-get props :ref)))
182 (setq ret (plist-get props :href))))
184 ((eq output-format 'wiki-text)
187 (est-format-list children output-format)
188 (est-format-unit ret output-format)
191 ((eq output-format 'html)
193 props (list* :href ret
194 (plist-remprop (copy-list props) :ref)))
196 ((eq output-format 'xml)
197 (unless (stringp ret)
198 (setq props (plist-remprop (copy-list props) :ref))
200 (cons (list 'ref nil ret)
204 ((and (eq name 'edit-value)
205 (setq object (plist-get props :object))
206 (setq feature (plist-get props :feature)))
207 (setq format (or (plist-get props :format) 'default))
209 props (list :href (format "%s?%s=%s&feature=%s&format=%s"
211 (est-object-genre object)
212 (www-uri-encode-object object)
213 (www-uri-encode-feature-name feature)
222 (when (eq output-format 'html)
223 (setq props (list* :class name props)
230 (setq separator (plist-get props :separator)))
231 (setq subtype (plist-get props :subtype))
234 ((eq output-format 'plain-text)
235 (est-format-list children output-format as-property separator
238 ((eq subtype 'unordered-list)
239 (format "<ul\n%s><li\n>%s</li></ul\n>"
241 (est-format-props props)
244 children output-format
245 without-edit as-property "</li\n><li\n>")
250 (format "<%s%s>%s</%s>"
253 (est-format-props props)
256 children output-format
257 without-edit as-property separator)
260 (if (eq output-format 'plain-text)
263 name (est-format-props props))))
267 (format "%s" format-unit)))))
269 (defun est-format-list (format-list
270 &optional output-format without-edit as-property
275 format-list output-format without-edit as-property separator)
277 ((eq subtype 'unordered-list)
279 (mapconcat (lambda (unit)
281 unit output-format without-edit as-property separator))
282 format-list "</li\n><li>")
286 (mapconcat (lambda (unit)
288 unit output-format without-edit as-property))
289 format-list separator)
296 (provide 'est-format)
298 ;;; est-format.el ends here