Mercurial > hg > xemacs-beta
comparison lisp/w3/css.el @ 82:6a378aca36af r20-0b91
Import from CVS: tag r20-0b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:07:36 +0200 |
parents | 0293115a14e9 |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
81:ebca3d831cea | 82:6a378aca36af |
---|---|
1 ;;; css.el -- Cascading Style Sheet parser | 1 ;;; css.el -- Cascading Style Sheet parser |
2 ;; Author: wmperry | 2 ;; Author: wmperry |
3 ;; Created: 1996/12/26 16:49:58 | 3 ;; Created: 1997/01/17 14:30:54 |
4 ;; Version: 1.18 | 4 ;; Version: 1.25 |
5 ;; Keywords: | 5 ;; Keywords: |
6 | 6 |
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu) | 8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu) |
9 ;;; Copyright (c) 1996 Free Software Foundation, Inc. | 9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc. |
10 ;;; | 10 ;;; |
11 ;;; This file is not part of GNU Emacs, but the same permissions apply. | 11 ;;; This file is not part of GNU Emacs, but the same permissions apply. |
12 ;;; | 12 ;;; |
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify | 13 ;;; GNU Emacs is free software; you can redistribute it and/or modify |
14 ;;; it under the terms of the GNU General Public License as published by | 14 ;;; it under the terms of the GNU General Public License as published by |
36 ;; NYI = Not Yet Implemented - due to limitations of space/time | 36 ;; NYI = Not Yet Implemented - due to limitations of space/time |
37 ;; NYPI = Not Yet Partially Implemented - possible partial support, eventually | 37 ;; NYPI = Not Yet Partially Implemented - possible partial support, eventually |
38 | 38 |
39 (defconst css-properties | 39 (defconst css-properties |
40 '(;; Property name Inheritable? Type of data | 40 '(;; Property name Inheritable? Type of data |
41 [font-family nil string-list] | 41 ;; Base CSS level 1 properties: http://www.w3.org/pub/WWW/TR/REC-CSS1 |
42 [font-style nil string] | 42 ;; Font properties, Section 5.2 |
43 [font-variant nil symbol-list] | 43 [font-family t string-list] |
44 [font-weight nil weight] | 44 [font-style t symbol] |
45 [font-size nil length] | 45 [font-variant t symbol] |
46 [font-weight t weight] | |
47 [font-size t length] | |
46 [font nil font] | 48 [font nil font] |
47 [color nil color] | 49 |
48 [background nil color] | 50 ;; Color and background properties, Section 5.3 |
49 [word-spacing nil length] ; CBI | 51 [color t color] |
50 [letter-spacing nil length] ; CBI | 52 [background nil color-shorthand] |
51 [text-decoration nil symbol-list] | 53 [background-color nil color] |
52 [vertical-align nil symbol] ; CBI | 54 [background-image nil url] ; NYI |
53 [text-transform nil string] | 55 [background-repeat nil symbol] ; CBI |
56 [background-attachment nil symbol] ; CBI | |
57 [background-position nil symbol] ; CBI | |
58 | |
59 ;; Text properties, Section 5.4 | |
60 [word-spacing t length] ; CBI | |
61 [letter-spacing t length] ; CBI | |
62 [text-decoration t symbol-list] | |
63 [vertical-align nil symbol] | |
64 [text-transform t symbol] | |
54 [text-align t symbol] | 65 [text-align t symbol] |
55 [text-indent t length] ; NYI | 66 [text-indent t length] ; NYI |
56 [line-height t length] ; CBI | 67 [line-height t length] ; CBI |
57 [margin nil margin] | 68 |
58 [margin-left nil margin] | 69 ;; Box properties, Section 5.5 |
59 [margin-right nil margin] | 70 [margin nil boundary-shorthand] |
60 [margin-top nil margin] | 71 [margin-left nil length] |
61 [margin-bottom nil margin] | 72 [margin-right nil length] |
62 [padding nil padding] | 73 [margin-top nil length] |
63 [padding-left nil padding] | 74 [margin-bottom nil length] |
64 [padding-right nil padding] | 75 [padding nil boundary-shorthand] |
65 [padding-top nil padding] | 76 [padding-left nil length] |
66 [padding-bottom nil padding] | 77 [padding-right nil length] |
67 [border nil border] | 78 [padding-top nil length] |
79 [padding-bottom nil length] | |
80 [border nil border-shorthand] | |
68 [border-left nil border] | 81 [border-left nil border] |
69 [border-right nil border] | 82 [border-right nil border] |
70 [border-top nil border] | 83 [border-top nil border] |
71 [border-bottom nil border] | 84 [border-bottom nil border] |
85 [border-top-width nil nil] | |
86 [border-right-width nil nil] | |
87 [border-bottom-width nil nil] | |
88 [border-left-width nil nil] | |
89 [border-width nil boundary-shorthand] | |
90 [border-color nil color] | |
91 [border-style nil symbol] | |
72 [width nil length] ; NYPI | 92 [width nil length] ; NYPI |
73 [height nil length] ; NYPI | 93 [height nil length] ; NYPI |
74 [float nil symbol] | 94 [float nil symbol] |
75 [clear nil symbol] | 95 [clear nil symbol] |
96 | |
97 ;; Classification properties, Section 5.6 | |
76 [display nil symbol] | 98 [display nil symbol] |
77 [list-style t symbol] ;!! can't specify 'inside|outside' | 99 [list-style-type t symbol] |
100 [list-style-image t url] | |
101 [list-style-position t symbol] | |
102 [list-style nil list-style] | |
78 [white-space t symbol] | 103 [white-space t symbol] |
79 | 104 |
80 ;; These are for specifying speech properties | 105 ;; These are for specifying speech properties (ACSS-style) |
106 ;; http://www.w3.org/pub/WWW/Style/CSS/Speech/NOTE-ACSS | |
107 | |
108 ;; General audio properties, Section 3 | |
109 [volume t string] ; Needs its own type? | |
110 [pause-before nil time] | |
111 [pause-after nil time] | |
112 [pause nil pause] | |
113 [cue-before nil string] | |
114 [cue-after nil string] | |
115 [cue-during nil string] | |
116 [cue nil string] ; Needs its own type? | |
117 | |
118 ;; Spatial properties, Section 4 | |
119 [azimuth t angle] | |
120 [elevation t elevation] | |
121 | |
122 ;; Speech properties, Section 5 | |
123 [speed t string] | |
124 [voice-family t string-list] | |
125 [pitch t string] | |
126 [pitch-range t percentage] | |
127 [stress t percentage] | |
128 [richness t percentage] | |
129 [speak-punctuation t symbol] | |
130 [speak-date t symbol] | |
131 [speak-numeral t symbol] | |
132 [speak-time t symbol] | |
133 | |
134 ;; Proposed printing extensions | |
135 ;; http://www.w3.org/pub/WWW/Style/Group/WD-PRINT-961220 | |
136 ;; These apply only to pages (@page directive) | |
137 [size nil symbol] | |
138 [orientation nil symbol] | |
139 [margin-inside nil length] | |
140 ;; These apply to the document | |
141 [page-break-before nil symbol] | |
142 [page-break-after nil symbol] | |
143 | |
144 ;; These are for specifying speech properties (Raman-style) | |
81 [voice-family t string] | 145 [voice-family t string] |
82 [gain t integer] | 146 [gain t integer] |
83 [left-volume t integer] | 147 [left-volume t integer] |
84 [right-volume t integer] | 148 [right-volume t integer] |
85 [pitch t integer] | 149 [pitch t integer] |
86 [pitch-range t integer] | 150 [pitch-range t integer] |
87 [stress t integer] | 151 [stress t integer] |
88 [richness t integer] | 152 [richness t integer] |
89 ) | 153 ) |
90 "A description of the various CSS properties and how to interpret them.") | 154 "A description of the various CSS properties and how to interpret them.") |
155 | |
156 (put 'font 'css-shorthand t) | |
157 (put 'background 'css-shorthand t) | |
158 (put 'margin 'css-shorthand t) | |
159 (put 'padding 'css-shorthand t) | |
160 (put 'border 'css-shorthand t) | |
161 (put 'list-style 'css-shorthand t) | |
91 | 162 |
92 (mapcar | 163 (mapcar |
93 (lambda (entry) | 164 (lambda (entry) |
94 (put (aref entry 0) 'css-inherit (aref entry 1)) | 165 (put (aref entry 0) 'css-inherit (aref entry 1)) |
95 (put (aref entry 0) 'css-type (aref entry 2))) | 166 (put (aref entry 0) 'css-type (aref entry 2))) |
130 ) | 201 ) |
131 | 202 |
132 (defconst css-running-xemacs | 203 (defconst css-running-xemacs |
133 (string-match "XEmacs" (emacs-version)) | 204 (string-match "XEmacs" (emacs-version)) |
134 "Whether we are running in XEmacs or not.") | 205 "Whether we are running in XEmacs or not.") |
135 | |
136 (defvar css-ie-compatibility t | |
137 "Whether we want to do Internet Explorer 3.0 compatible parsing of | |
138 CSS stylesheets.") | |
139 | 206 |
140 (defsubst css-replace-regexp (regexp to-string) | 207 (defsubst css-replace-regexp (regexp to-string) |
141 (goto-char (point-min)) | 208 (goto-char (point-min)) |
142 (while (re-search-forward regexp nil t) | 209 (while (re-search-forward regexp nil t) |
143 (replace-match to-string t nil))) | 210 (replace-match to-string t nil))) |
325 (setq rval (+ rval | 392 (setq rval (+ rval |
326 (* (css-pow 16 (- (length x) ord)) | 393 (* (css-pow 16 (- (length x) ord)) |
327 (css-unhex-char (aref x (1- ord))))) | 394 (css-unhex-char (aref x (1- ord))))) |
328 ord (1- ord))) | 395 ord (1- ord))) |
329 rval)) | 396 rval)) |
397 | |
398 (defmacro css-symbol-list-as-regexp (&rest keys) | |
399 (` (eval-when-compile | |
400 (concat "^\\(" | |
401 (mapconcat 'symbol-name | |
402 (quote (, keys)) | |
403 "\\|") "\\)$")))) | |
330 | 404 |
331 (defun css-expand-color (color) | 405 (defun css-expand-color (color) |
332 (cond | 406 (cond |
333 ((string-match "^#" color) | 407 ((string-match "^#" color) |
334 (let (r g b) | 408 (let (r g b) |
368 (b (min (string-to-number (match-string 3 color)) 100.0))) | 442 (b (min (string-to-number (match-string 3 color)) 100.0))) |
369 (setq r (round (* r 2.55)) | 443 (setq r (round (* r 2.55)) |
370 g (round (* g 2.55)) | 444 g (round (* g 2.55)) |
371 b (round (* b 2.55)) | 445 b (round (* b 2.55)) |
372 color (vector 'rgb r g b)))) | 446 color (vector 'rgb r g b)))) |
373 ((string-match "url *(\\([^ )]+\\) *)" color) | |
374 ;; A picture in the background | |
375 (let ((pixmap (match-string 1 color)) | |
376 (attributes nil)) | |
377 (setq color (concat (substring color 0 (match-beginning 0)) | |
378 (substring color (match-end 0) nil)) | |
379 attributes (split-string color " ")) | |
380 ) | |
381 ) | |
382 (t | 447 (t |
383 ;; Hmmm... pass it through unmangled and hope the underlying | 448 ;; Hmmm... pass it through unmangled and hope the underlying |
384 ;; windowing system can handle it. | 449 ;; windowing system can handle it. |
385 ) | 450 ) |
386 ) | 451 ) |
387 color | 452 color |
388 ) | 453 ) |
389 | 454 |
390 (defun css-expand-value (type value) | 455 (defun css-expand-value (type value) |
391 (case type | 456 (if value |
392 ((symbol integer) ; Read it in | 457 (case type |
393 (setq value (read (downcase value)))) | 458 (length ; CSS, Section 6.1 |
394 (symbol-list | 459 (setq value (css-expand-length value))) |
395 (setq value (downcase value) | 460 (percentage ; CSS, Section 6.2 |
396 value (split-string value "[ ,]+") | 461 (setq value (/ (string-to-number value) |
397 value (mapcar 'intern value))) | 462 (if (fboundp 'float) (float 100) 1)))) |
398 (string-list | 463 (color ; CSS, Section 6.3 |
399 (setq value (split-string value " *, *"))) | 464 (setq value (css-expand-color value))) |
400 (color ; A color, possibly with URLs | 465 (url ; CSS, Section 6.4 |
401 (setq value (css-expand-color value))) | 466 (declare (special url purl)) |
402 (length ; Pixels, picas, ems, etc. | 467 (if (string-match "url *(\\([^ )]+\\) *)" value) |
403 (setq value (css-expand-length value))) | 468 (setq value (match-string 1 value))) |
404 (font ; Font shorthand | 469 (if (string-match " *\\([^ ]+\\) *" value) |
405 (setq value (css-split-font-shorthand value))) | 470 (setq value (match-string 1 value))) |
406 ((margin padding) ; length|percentage|auto {1,4} | 471 (setq value (url-expand-file-name value (or url purl)))) |
407 (setq value (split-string value "[ ,]+")) | 472 (angle ; ACSS, Section 2.2.1 |
408 (if (/= 1 (length value)) | 473 ) |
409 ;; More than one value - a shortcut | 474 (time ; ACSS, Section 2.2.2 |
475 (let ((val (string-to-number value)) | |
476 (units 'ms)) | |
477 (if (string-match "^[0-9]+ *\\([a-zA-Z.]+\\)" value) | |
478 (setq units (intern (downcase (match-string 1 value))))) | |
479 (setq value (case units | |
480 ((s second seconds) | |
481 val) | |
482 ((min minute minutes) | |
483 (* val 60)) | |
484 ((hr hour hours) | |
485 (* val 60 60)) | |
486 ((day days) | |
487 (* val 24 60 60)) | |
488 (otherwise | |
489 (/ val (float 1000))))))) | |
490 (elevation ; ACSS, Section 4.2 | |
491 (if (string-match | |
492 (css-symbol-list-as-regexp below level above higher lower) value) | |
493 (setq value (intern (downcase (match-string value 1))) | |
494 value (case value | |
495 (below -90) | |
496 (above 90) | |
497 (level 0) | |
498 (higher 45) | |
499 (lower -45) | |
500 )) | |
501 (setq value (css-expand-value 'angle value)))) | |
502 (color-shorthand ; CSS, Section 5.3.7 | |
503 ;; color|image|repeat|attach|position | |
504 (let ((keys (split-string value " +")) | |
505 cur color image repeat attach position) | |
506 (while (setq cur (pop keys)) | |
507 (cond | |
508 ((string-match "url" cur) ; Only image can have a URL | |
509 (setq image (css-expand-value 'url cur))) | |
510 ((string-match "%" cur) ; Only position can have a perc. | |
511 (setq position (css-expand-value 'percentage cur))) | |
512 ((string-match "repeat" cur) ; Only repeat | |
513 (setq repeat (intern (downcase cur)))) | |
514 ((string-match "scroll\\|fixed" cur) | |
515 (setq attach (intern (downcase (substring cur | |
516 (match-beginning 0) | |
517 (match-end 0)))))) | |
518 ((string-match (css-symbol-list-as-regexp | |
519 top center bottom left right) cur) | |
520 ) | |
521 (t | |
522 (setq color cur)))) | |
523 (setq value (list (cons 'background-color color) | |
524 (cons 'background-image image) | |
525 (cons 'background-repeat repeat) | |
526 (cons 'background-attachment attach) | |
527 (cons 'background-position position))))) | |
528 (font ; CSS, Section 5.2.7 | |
529 ;; [style | variant | weight]? size[/line-height]? family | |
530 (setq value (css-split-font-shorthand value))) | |
531 (border ; width | style | color | |
532 ;; FIX | |
533 ) | |
534 (border-shorthand ; width | style | color | |
535 ;; FIX | |
536 ) | |
537 (list-style ; CSS, Section 5.6.6 | |
538 ;; keyword | position | url | |
539 (setq value (split-string value "[ ,]+")) | |
540 (if (= (length value) 1) | |
541 (setq value (list (cons 'list-style-type | |
542 (intern (downcase (car value)))))) | |
543 (setq value (list (cons 'list-style-type | |
544 (css-expand-value 'symbol (nth 0 value))) | |
545 (cons 'list-style-position | |
546 (css-expand-value 'symbol (nth 1 value))) | |
547 (cons 'list-style-image | |
548 (css-expand-value 'url (nth 2 value))))))) | |
549 (boundary-shorthand ; CSS, Section 5.5.x | |
550 ;; length|percentage|auto {1,4} | |
551 (setq value (split-string value "[ ,]+")) | |
410 (let* ((top (intern (format "%s-top" type))) | 552 (let* ((top (intern (format "%s-top" type))) |
411 (bottom (intern (format "%s-bottom" type))) | 553 (bottom (intern (format "%s-bottom" type))) |
412 (left (intern (format "%s-left" type))) | 554 (left (intern (format "%s-left" type))) |
413 (right (intern (format "%s-right" type)))) | 555 (right (intern (format "%s-right" type)))) |
414 (setq top (cons top (css-expand-length (nth 0 value))) | 556 (setq top (cons top (css-expand-value (get top 'css-type) |
415 right (cons right (css-expand-length (nth 1 value))) | 557 (nth 0 value))) |
416 bottom (cons bottom (css-expand-length (nth 2 value))) | 558 right (cons right (css-expand-value (get right 'css-type) |
417 left (cons left (css-expand-length (nth 3 value))) | 559 (nth 1 value))) |
418 value (list top right bottom left))) | 560 bottom (cons bottom (css-expand-value (get bottom 'css-type) |
419 (setq value (css-expand-length (car value))))) | 561 (nth 2 value))) |
420 (border | 562 left (cons left (css-expand-value (get left 'css-type) |
421 (cond | 563 (nth 3 value))) |
422 ((member (downcase value) '("none" "dotted" "dashed" "solid" | 564 value (list top right bottom left)))) |
423 "double" "groove" "ridge" "inset" "outset")) | 565 (weight ; CSS, Section 5.2.5 |
424 (setq value (intern (downcase value)))) | 566 ;; normal|bold|bolder|lighter|[1-9]00 |
425 ((string-match "^[0-9]+" value) | 567 (cond |
426 (setq value (font-spatial-to-canonical value))) | 568 ((string-match "^[0-9]+" value) |
427 (t nil))) | 569 (setq value (/ (string-to-number value) 100) |
428 (weight ; normal|bold|bolder|lighter|[1-9]00 | 570 value (or (nth value css-weights) :bold))) |
429 (if (string-match "^[0-9]+" value) | 571 ((string-match (css-symbol-list-as-regexp normal bold bolder lighter) |
430 (setq value (/ (read value) 100) | 572 value) |
431 value (or (nth value css-weights) :bold)) | 573 (setq value (intern (downcase (concat ":" value))))) |
432 (setq value (intern (downcase (concat ":" value)))))) | 574 (t setq value (intern ":bold")))) |
433 (otherwise ; Leave it as is | 575 |
434 t) | 576 ;; The rest of these deal with how we handle things internally |
577 ((symbol integer) ; Read it in | |
578 (setq value (read (downcase value)))) | |
579 (symbol-list ; A space/comma delimited symlist | |
580 (setq value (downcase value) | |
581 value (split-string value "[ ,]+") | |
582 value (mapcar 'intern value))) | |
583 (string-list ; A space/comma delimited list | |
584 (setq value (split-string value " *, *"))) | |
585 (otherwise ; Leave it as is | |
586 t) | |
587 ) | |
435 ) | 588 ) |
436 value | 589 value |
437 ) | 590 ) |
438 | 591 |
439 (defun css-parse-args (st &optional nd) | 592 (defun css-parse-args (st &optional nd) |
483 (skip-chars-forward "^ \t\n") | 636 (skip-chars-forward "^ \t\n") |
484 (point))))) | 637 (point))))) |
485 (t | 638 (t |
486 (buffer-substring val-pos | 639 (buffer-substring val-pos |
487 (progn | 640 (progn |
488 (if css-ie-compatibility | 641 (skip-chars-forward "^;") |
489 (skip-chars-forward "^;") | |
490 (skip-chars-forward "^,;")) | |
491 (skip-chars-backward " \t") | 642 (skip-chars-backward " \t") |
492 (point))))))) | 643 (point))))))) |
493 (setq value (css-expand-value (get name 'css-type) value)) | 644 (setq value (css-expand-value (get name 'css-type) value)) |
494 (if (eq (get name 'css-type) 'font) | 645 (if (get name 'css-shorthand) |
495 (setq results (append value results)) | 646 (setq results (append value results)) |
496 (setq results (cons (cons name value) results))) | 647 (setq results (cons (cons name value) results))) |
497 (skip-chars-forward ";, \n\t")) | 648 (skip-chars-forward ";, \n\t")) |
498 results)))) | 649 results)))) |
499 | 650 |
500 (defun css-handle-import () | 651 (defun css-handle-media-directive (data active) |
501 (let ((url nil) | 652 (let (type) |
502 (save-pos (point))) | 653 (if (string-match "\\([^ \t\r\n{]+\\)" data) |
503 (if (looking-at "'\"") | 654 (setq type (intern (downcase (substring data (match-beginning 1) |
504 (condition-case () | 655 (match-end 1)))) |
505 (forward-sexp 1) | 656 data (substring data (match-end 1))) |
506 (error (skip-chars-forward "^ \t\r\n;"))) | 657 (setq type 'unknown)) |
507 (skip-chars-forward "^ \t\r\n;")) | 658 (if (string-match "^[ \t\r\n]*{" data) |
508 (setq url (url-expand-file-name (buffer-substring save-pos (point)))) | 659 (setq data (substring data (match-end 0)))) |
509 (skip-chars-forward "\"; \t\r\n") | 660 (if (memq type active) |
510 (setq save-pos (point)) | 661 (save-excursion |
511 (let ((url-working-buffer (generate-new-buffer-name " *styleimport*")) | 662 (insert data))))) |
512 (url-mime-accept-string | 663 |
513 "text/css ; level=2") | 664 (defun css-handle-import (data) |
514 (sheet nil)) | 665 (let (url) |
515 (save-excursion | 666 (setq url (css-expand-value 'url data)) |
516 (set-buffer (get-buffer-create url-working-buffer)) | 667 (and url |
517 (setq url-be-asynchronous nil) | 668 (let ((url-working-buffer (generate-new-buffer-name " *styleimport*")) |
518 (url-retrieve url) | 669 (url-mime-accept-string |
519 (css-clean-buffer) | 670 "text/css ; level=2") |
520 (setq sheet (buffer-string)) | 671 (sheet nil)) |
521 (set-buffer-modified-p nil) | 672 (save-excursion |
522 (kill-buffer (current-buffer))) | 673 (set-buffer (get-buffer-create url-working-buffer)) |
523 (insert sheet) | 674 (setq url-be-asynchronous nil) |
524 (goto-char save-pos)))) | 675 (url-retrieve url) |
676 (css-clean-buffer) | |
677 (setq sheet (buffer-string)) | |
678 (set-buffer-modified-p nil) | |
679 (kill-buffer (current-buffer))) | |
680 (insert sheet))))) | |
525 | 681 |
526 (defun css-clean-buffer () | 682 (defun css-clean-buffer () |
527 ;; Nuke comments, etc. | 683 ;; Nuke comments, etc. |
528 (goto-char (point-min)) | 684 (goto-char (point-min)) |
529 (let ((save-pos nil)) | 685 (let ((save-pos nil)) |
539 (css-replace-regexp "^[ \t\r]+" "") ; Nuke whitespace at beg. of line | 695 (css-replace-regexp "^[ \t\r]+" "") ; Nuke whitespace at beg. of line |
540 (css-replace-regexp "[ \t\r]+$" "") ; Nuke whitespace at end of line | 696 (css-replace-regexp "[ \t\r]+$" "") ; Nuke whitespace at end of line |
541 (goto-char (point-min))) | 697 (goto-char (point-min))) |
542 | 698 |
543 (defun css-active-device-types (&optional device) | 699 (defun css-active-device-types (&optional device) |
544 (let ((types (list 'normal 'default (if css-running-xemacs 'xemacs 'emacs))) | 700 (let ((types (list 'all (if css-running-xemacs 'xemacs 'emacs))) |
545 (type (device-type device))) | 701 (type (device-type device))) |
546 (cond | 702 (cond |
547 ((featurep 'emacspeak) | 703 ((featurep 'emacspeak) |
548 (setq types (cons 'speech types))) | 704 (setq types (cons 'speech types))) |
549 ((eq type 'tty) | 705 ((eq type 'tty) |
632 ) | 788 ) |
633 ) | 789 ) |
634 ) | 790 ) |
635 ) | 791 ) |
636 | 792 |
637 (defun css-parse (fname &optional string inherit) | 793 (defun css-parse (url &optional string inherit) |
638 (let ( | 794 (let ( |
639 (url-mime-accept-string | 795 (url-mime-accept-string |
640 "text/css ; level=2") | 796 "text/css ; level=2") |
641 (save-pos nil) | 797 (save-pos nil) |
642 (applies-to nil) ; List of tags to apply style to | 798 (applies-to nil) ; List of tags to apply style to |
643 (attrs nil) ; List of name/value pairs | 799 (attrs nil) ; List of name/value pairs |
644 (att nil) | 800 (att nil) |
645 (cur nil) | 801 (cur nil) |
646 (val nil) | 802 (val nil) |
647 (device-type nil) | 803 (device-type nil) |
804 (purl (url-view-url t)) | |
648 (active-device-types (css-active-device-types (selected-device))) | 805 (active-device-types (css-active-device-types (selected-device))) |
649 (sheet inherit)) | 806 (sheet inherit)) |
650 (if (not sheet) | 807 (if (not sheet) |
651 (setq sheet (make-hash-table :size 13 :test 'eq))) | 808 (setq sheet (make-hash-table :size 13 :test 'eq))) |
652 (save-excursion | 809 (save-excursion |
653 (set-buffer (get-buffer-create | 810 (set-buffer (get-buffer-create |
654 (generate-new-buffer-name " *style*"))) | 811 (generate-new-buffer-name " *style*"))) |
655 (set-syntax-table css-syntax-table) | 812 (set-syntax-table css-syntax-table) |
656 (erase-buffer) | 813 (erase-buffer) |
657 (if fname (url-insert-file-contents fname)) | 814 (if url (url-insert-file-contents url)) |
658 (goto-char (point-max)) | 815 (goto-char (point-max)) |
659 (if string (insert string)) | 816 (if string (insert string)) |
660 (css-clean-buffer) | 817 (css-clean-buffer) |
661 (goto-char (point-min)) | 818 (goto-char (point-min)) |
662 (while (not (eobp)) | 819 (while (not (eobp)) |
666 ;; with the <style> tag from older browsers. | 823 ;; with the <style> tag from older browsers. |
667 ((or (looking-at "<!--+") ; begin | 824 ((or (looking-at "<!--+") ; begin |
668 (looking-at "--+>")) ; end | 825 (looking-at "--+>")) ; end |
669 (goto-char (match-end 0))) | 826 (goto-char (match-end 0))) |
670 ;; C++ style comments, and we are doing IE compatibility | 827 ;; C++ style comments, and we are doing IE compatibility |
671 ((and (looking-at "//") css-ie-compatibility) | 828 ((looking-at "//") |
672 (end-of-line)) | 829 (end-of-line)) |
673 ;; Pre-Processor directives | 830 ;; Pre-Processor directives |
674 ((looking-at "[ \t\r]*@\\([^ \t\r\n]\\)") | 831 ((looking-at "[ \t\r]*@\\([^ \t\r\n]\\)") |
675 (let ((directive nil)) | 832 (let (data directive) |
676 (skip-chars-forward " @\t\r") ; Past any leading whitespace | 833 (skip-chars-forward " @\t\r") ; Past any leading whitespace |
677 (setq save-pos (point)) | 834 (setq save-pos (point)) |
678 (skip-chars-forward "^ \t\r\n") ; Past the @ directive | 835 (skip-chars-forward "^ \t\r\n") ; Past the @ directive |
679 (downcase-region save-pos (point)) | 836 (downcase-region save-pos (point)) |
680 (setq directive (buffer-substring save-pos (point))) | 837 (setq directive (intern (buffer-substring save-pos (point)))) |
681 (skip-chars-forward " \t\r") ; Past any trailing whitespace | 838 (skip-chars-forward " \t\r") |
682 (setq save-pos (point)) | 839 (setq save-pos (point)) |
683 (cond | 840 (cond |
684 ((string= directive "import") | 841 ((looking-at ".*\\({\\)") |
685 (css-handle-import)) | 842 (goto-char (match-beginning 1)) |
843 (forward-sexp 1) | |
844 (setq data (buffer-substring save-pos (1- (point))))) | |
845 ((looking-at "[\"']+") | |
846 (setq save-pos (1+ save-pos)) | |
847 (forward-sexp 1) | |
848 (setq data (buffer-substring save-pos (1- (point))))) | |
686 (t | 849 (t |
687 (message "Unknown directive in stylesheet: @%s" directive))))) | 850 (skip-chars-forward "^;"))) |
851 (if (not data) | |
852 (setq data (buffer-substring save-pos (point)))) | |
853 (setq save-pos (point)) | |
854 (case directive | |
855 (import (css-handle-import data)) | |
856 (media (css-handle-media-directive data active-device-types)) | |
857 (t (message "Unknown directive in stylesheet: @%s" directive))))) | |
688 ;; Giving us some output device information | 858 ;; Giving us some output device information |
689 ((looking-at "[ \t\r]*:\\([^: \n]+\\):") | 859 ((looking-at "[ \t\r]*:\\([^: \n]+\\):") |
860 (message "You are using the old way of specifying device-dependent stylesheets! Please upgrade!") | |
861 (sleep-for 2) | |
690 (downcase-region (match-beginning 1) (match-end 1)) | 862 (downcase-region (match-beginning 1) (match-end 1)) |
691 (setq device-type (intern (buffer-substring (match-beginning 1) | 863 (setq device-type (intern (buffer-substring (match-beginning 1) |
692 (match-end 1)))) | 864 (match-end 1)))) |
693 (goto-char (match-end 0)) | 865 (goto-char (match-end 0)) |
694 (if (not (memq device-type active-device-types)) | 866 (if (not (memq device-type active-device-types)) |