 
 ;; Selector computation
 
-(defun skewer-html--cleanup (name)
-  "Cleanup tag names provided by sgml-mode."
-  (replace-regexp-in-string "/$" "" name))
+(defun skewer-html--cleanup (tag)
+  "Cleanup TAG name from sgml-mode."
+  (replace-regexp-in-string "/$" "" (sgml-tag-name tag)))
 
 (defun skewer-html--tag-after-point ()
   "Return the tag struct for the tag immediately following point."

    (forward-char 1)
    (sgml-parse-tag-backward)))

(defun skewer-html-compute-tag-nth ()
  "Compute the position of this tag within its parent."
  (save-excursion
    (let ((tag (car (last (sgml-get-context)))))
      (if (null tag)
          1
        (cl-loop with start = (sgml-tag-name tag)
                 with stop = (save-excursion (sgml-get-context) (point))
                 with n = 1
                 do (sgml-skip-tag-backward 1)
                 while (> (point) stop)
                 when (equal start (sgml-tag-name
                                    (skewer-html--tag-after-point)))
                 do (cl-incf n)
                 finally (return n))))))

(defun skewer-html-compute-tag-ancestry ()
  "Compute the ancestry chain at point."
  (save-excursion
    (nreverse
     (cl-loop for nth = (skewer-html-compute-tag-nth)
              for tag = (car (last (sgml-get-context)))
              while tag
              for name = (skewer-html--cleanup (sgml-tag-name tag))
              for type = (sgml-tag-type tag)
              when (not (or (string= name "html")
                            (eq type 'close)))
              collect (list name nth)))))

(defun skewer-html-compute-selector ()
  "Compute the selector for exactly the tag around point."

  (let ((ancestry (skewer-html-compute-tag-ancestry)))
    (save-excursion
      ;; Move to beginning of opening tag
      (let* ((beg (progn (sgml-skip-tag-forward 1) (point)))
             (end (progn (sgml-skip-tag-backward 1) (point)))
             (region (buffer-substring-no-properties beg end)))
        (skewer-flash-region beg end)
        (if (= (length ancestry) 1)
