HTML を編集しているバッファの HTML を解析して、 CSS を吐き出します。 ネストしたやつも多分大丈夫だと思います。 CSS のことよく解ってないのでこれでいいのか解りませんが ^^)
(defun get-elemement-init(regex)
(let(result tmp tag p1 p2 st)
(save-excursion
(goto-char(point-min))
(scan-buffer "<body.*>" :regexp t :case-fold t :tail t)
(while
(scan-buffer (concat "<\\("
regex
"[^<>]*?\\)>" )
:regexp t :no-dup t)
(when
(not(member
(car(split-string (match-string 1) #\SPC))
; exclusion
'("head" "title" "area" "hr" "br" "frame" "frameset"
"map" "noframes" "noscript" "optgroup" "option" "param"
"script" "style" "tbody" "tfoot" "thead")
:test #'(lambda(a b)(string= b a))))
(setq tag (car(split-string(match-string 1) #\SPC)))
(message "Study Tag Name: <~A>."(string-upcase tag))
(setq tmp nil)
(push (match-string 0) tmp)
(setq p1 (point))
(scan-buffer (concat "<\\(/" tag "\\)>")
:regexp t :no-dup t :tail t)
(setq p2 (point))
(goto-char p1)
;この処理が重い
(while(forward-char 1)
(and(<= p2 (point))(return))
(if(looking-at "<\\([^\/!<>]+?\\)>")
(push (match-string 0) tmp)))
(push (remove-duplicates (nreverse tmp) :test 'string-equal) result)
(goto-char p1))))
(nreverse result)))
(defun css-generator()
(interactive)
(let*((l (get-elemement-init "[^\/!<>]+") ))
(with-output-to-temp-buffer("CSS")
(format t "/*-*- mode:css -*-*/~%~{/* */~%~{~A~^ ~}{~%}~2%~}"
(mapcar
#'(lambda(b)
(mapcar
#'(lambda(a)
(concat
(substitute-string a "^<\\([^ ]+\\).*>" "\\1")
(if (string-matchp "class" a)
(substitute-string
a "^<.+class *= *\"\\([^ ]+\\)\".*>" ".\\1"))
(if (string-matchp "id" a)
(substitute-string
a "^<.+id *= *\"\\([^ ]+\\)\".*>" "#\\1"))))
b)
)
(remove-duplicates
(append (mapcar #'(lambda(x)(list(car x))) l) l)
:test 'equal)
)))))