1 ;;; xhtml-help.el --- Browse XHTML reference sites
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
5 ;; Last-Updated: Wed Aug 01 14:24:07 2007 (7200 +0200)
6 (defconst xhtml-help:version "0.57") ;; Version:
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 ;; Use when editing XHTML file to get tag references or CSS property
14 ;; name references (like background-color) from web sources.
20 ;; Then call `xhtml-help-show-tag-ref' or `xhtml-help-show-css-ref'.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; 2005-12-02: Corrected fetching margin-*.
28 ;; 2006-01-08: Prompt for tag and property name before fetching help.
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; This file is not part of Emacs
35 ;; This program is free software; you can redistribute it and/or
36 ;; modify it under the terms of the GNU General Public License as
37 ;; published by the Free Software Foundation; either version 2, or (at
38 ;; your option) any later version.
40 ;; This program is distributed in the hope that it will be useful, but
41 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
42 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43 ;; General Public License for more details.
45 ;; You should have received a copy of the GNU General Public License
46 ;; along with this program; see the file COPYING. If not, write to
47 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
48 ;; Boston, MA 02111-1307, USA.
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 (defun xhtml-help-css-prop-at-point ()
56 "Get possible css name property at point."
58 (let ((ch (char-after))
60 (when (and (not (bolp))
62 (member ch '(10 9 32 ?\:))))
64 (setq ch (char-after)))
65 (while (string-match "[a-z-]" (char-to-string ch))
68 (setq ch (char-after)))
71 (when (looking-at "[a-z-]+")
72 (match-string-no-properties 0))))))
75 (defun xhtml-help-show-css-ref ()
76 "Show CSS reference for CSS property name at point."
78 (let ((css-prop (xhtml-help-css-prop-at-point)))
79 (setq css-prop (read-from-minibuffer "Get help for CSS property: " css-prop))
81 (xhtml-help-browse-css css-prop))))
84 (defun xhtml-help-tag-at-point ()
85 "Get xhtml tag name at or before point."
87 (when (eq (following-char) ?<)
89 (when (and (search-backward "<" nil t)
90 (looking-at "</?\\([[:alnum:]]+\\)"))
91 (match-string-no-properties 1))))
94 (defun xhtml-help-show-tag-ref ()
95 "Show xhtml reference for tag name at or before point."
97 (let ((tag (xhtml-help-tag-at-point)))
98 (setq tag (read-from-minibuffer "Get help for tag name: " tag))
99 (when (< 0 (length tag))
100 (xhtml-help-browse-tag tag))))
103 (defgroup xhtml-help nil
104 "Customization group for xhtml-help."
108 (defcustom xhtml-help-refurl "http://www.w3.org/"
109 "Web url to get references from."
111 (const "http://www.w3.org/")
112 (const "http://xhtml.com/")
113 (const "http://www.w3schools.com/")
114 ;;(const "http://learningforlife.fsu.edu/")
118 (defcustom xhtml-help-query-refurl t
119 "Query for reference url.
120 This is used in `xhtml-help-browse-tag' and `xhtml-help-browse-css'."
124 (defun xhtml-help-query-refurl (prompt &optional notvalid)
125 (let ((choices (get 'xhtml-help-refurl 'custom-type))
126 (default xhtml-help-refurl))
127 (unless (eq 'choice (car choices))
128 (error "Custom type of xhtml-help-refurl is not choices"))
129 (setq choices (cdr choices))
130 (setq choices (mapcar (lambda (elt)
134 (setq choices (delete elt choices)))
136 (when (member default notvalid)
137 (setq default (car choices)))
138 (completing-read (concat "Fetch " prompt " reference from: ")
145 (defun xhtml-match (target str)
146 (let ((len (length target)))
147 (when (<= len (length str))
148 (equal target (substring str 0 len)))))
150 (defun xhtml-match-member (target str-list)
153 (when (xhtml-match elt target)
158 (defun xhtml-help-browse-css (css-prop)
159 (let* ((refurl (if xhtml-help-query-refurl
160 (xhtml-help-query-refurl (concat "CSS property '" css-prop "'")
161 (list "http://xhtml.com/"))
165 ( (equal refurl "http://www.w3schools.com/")
169 ( (member css-prop '("clear" "cursor" "display" "float" "position" "visibility"))
171 ( (member css-prop '("height" "line-height" "max-width" "min-height" "min-width" "width"))
173 ( (xhtml-match "font-weight" css-prop)
174 (setq css-prop "") "font_weight")
175 ( (xhtml-match "font" css-prop)
177 ( (member css-prop '("content" "counter-increment" "counter-reset" "quotes"))
179 ( (xhtml-match "list" css-prop)
181 ( (xhtml-match "margin" css-prop)
183 ( (xhtml-match "outline" css-prop)
185 ( (equal "padding" css-prop)
187 ( (xhtml-match "padding" css-prop)
189 ( (member css-prop '("bottom" "clip" "left" "overflow" "right" "top"
190 "vertical-align" "z-index"))
192 ( (member css-prop '("border-collapse"))
194 ( (member css-prop '("color" "direction" "letter-spacing" "text-align"
195 "text-decoration" "text-indent" "text-transform"
196 "white-space" "word-spacing"))
200 ;; ( (equal refurl "http://learningforlife.fsu.edu/")
201 ;; (let ((css-prop2 css-prop)
204 ;; (while (< ii (length css-prop))
205 ;; (setq cc (substring css-prop2 ii (1+ ii)))
206 ;; (when (equal cc "-")
207 ;; (store-substring css-prop2 ii "_"))
208 ;; (setq ii (1+ ii)))
210 ;; refurl "webmaster/references/css/" css-prop2 ".cfm")))
211 ( (equal refurl "http://www.w3.org/")
212 (let ((properties "")
215 refurl "TR/REC-CSS2/"
217 ( (xhtml-match-member css-prop '("margin" "padding" "border"))
219 ( (member css-prop '("display" "position"
220 "top" "right" "bottom" "left"
223 "direction" "unicode-bidi"))
224 "visuren.html#propdef-")
225 ( (member css-prop '("width" "min-width" "max-width"
226 "height" "min-height" "max-height"
227 "line-height" "vertical-align"))
228 "visudet.html#propdef-")
229 ( (member css-prop '("overflow" "clip" "visibility"))
230 "visufx.html#propdef-")
231 ( (member css-prop '("content" "quotes"))
232 "generate.html#propdef-")
233 ( (or (xhtml-match css-prop "counter")
234 (member css-prop '("marker-offset")))
236 "generate.html#counters")
237 ( (xhtml-match-member css-prop '("list"))
238 "generate.html#propdef-")
239 ( (member css-prop '("size" "marks"
240 "page-break-before" "page-break-after" "page-break-inside"
244 "page.html#propdef-")
245 ( (member css-prop '("color"
246 "background-color" "background-image" "background-repeat"
247 "background-attachment" "background-position" "background"
249 "colors.html#propdef-")
250 ( (xhtml-match "font" css-prop)
251 "fonts.html#propdef-")
252 ( (xhtml-match "text" css-prop)
254 ( (member css-prop '("letter-spacing" "word-spacing"))
257 ( (member css-prop '("cursor"))
259 ( (xhtml-match "outline" css-prop)
260 "ui.html#dynamic-outlines")
261 ( (or (xhtml-match "speak" css-prop)
262 (xhtml-match "pause" css-prop)
263 (xhtml-match "cue" css-prop)
264 (xhtml-match "pitch" css-prop)
265 (member css-prop '("volume" "play-during" "azimuth" "elevation"
266 "speech-rate" "voice-family" "richness")))
267 "aural.html#propdef-")
271 ( t (error "Bad value for xhtml-help-refurl: %s" refurl)))))
278 (defun xhtml-help-browse-tag (tag)
279 (let* ((refurl (if xhtml-help-query-refurl
280 (xhtml-help-query-refurl (concat "XHTML tag '" tag "'")
281 (list "http://www.w3.org/"))
285 ( (equal refurl "http://xhtml.com/")
287 refurl "en/xhtml/reference/"
291 ( (equal refurl "http://www.w3schools.com/")
295 ( (member tag '("tt" "i" "b" "big" "small"))
296 "tag_font_style.asp")
297 ( (member tag '("em" "strong" "dfn" "code" "samp" "kbd" "var" "cite"))
298 "tag_phrase_elements.asp")
299 ( (member tag '("h1" "h2" "h3" "h4" "h5" "h6"))
301 ( (member tag '("sub" "sup"))
304 (concat "tag_" tag ".asp")
306 ;; ( (equal refurl "http://learningforlife.fsu.edu/")
308 ;; refurl "webmaster/references/xhtml/tags/"
310 ;; ( (member tag '("body" "head" "html" "title"))
312 ;; ( (member tag '("abbr" "acronym" "address" "blockquote" "br" "cite"
313 ;; "code" "dfn" "div" "em" "h1" "h2" "h3" "h4" "h5" "h6"
314 ;; "kbd" "p" "pre" "q" "samp" "span" "strong" "var"))
316 ;; ( (member tag '("a"))
318 ;; ( (member tag '("dl" "dd" "dt" "ol" "ul" "li"))
320 ;; ( (member tag '("object" "param"))
322 ;; ( (member tag '("b" "big" "hr" "i" "small" "sub" "sup" "tt"))
324 ;; ( (member tag '("del" "ins"))
326 ;; ( (member tag '("bdo"))
328 ;; ( (member tag '("button" "fieldset" "form" "input" "label" "legend"
329 ;; "select" "optgroup" "option" "textarea"))
331 ;; ( (member tag '("caption" "col" "colgroup" "table" "tbody" "td"
332 ;; "tfoot" "th" "thead" "tr"))
334 ;; ( (member tag '("img"))
336 ;; ( (member tag '("area" "map"))
338 ;; ( (member tag '("area" "map"))
340 ;; ( (member tag '("meta"))
342 ;; ( (member tag '("noscript" "script"))
344 ;; ( (member tag '("style"))
346 ;; ( (member tag '("link"))
348 ;; ( (member tag '("base"))
350 ;; ( (member tag '("base"))
352 ;; ( (member tag '("ruby" "rbc" "rtc" "rb" "rt" "rp"))
356 ( t (error "Bad value for xhtml-help-refurl: %s" refurl))
360 (defconst xhtml-help-mode-keymap
361 (let ((map (make-sparse-keymap "XHTML Help")))
362 (define-key map [menu-bar xh-help] (cons "XHTML Help" (make-sparse-keymap "second")))
363 (define-key map [menu-bar xh-help css-help] '("CSS Help" . xhtml-help-show-css-ref))
364 (define-key map [menu-bar xh-help tag-help] '("XHTML Tag Help" . xhtml-help-show-tag-ref))
367 (define-minor-mode xhtml-help-mode
368 "Minor mode that adds keys for accessing xhtml and css help."
369 :keymap xhtml-help-mode-keymap)
371 (provide 'xhtml-help)
373 ;;; xhtml-help.el ends here