Re: html-mode.el update

Dan Connolly (connolly@pixel.convex.com)
Wed, 18 Nov 92 22:54:10 CST


Message-Id: <9211190454.AA08886@pixel.convex.com>
To: marca@ncsa.uiuc.edu (Marc Andreessen)
Cc: www-talk@nxoc01.cern.ch
Subject: Re: html-mode.el update 
In-Reply-To: Your message of "Wed, 18 Nov 92 21:42:37 PST."
             <9211190542.AA09366@wintermute.ncsa.uiuc.edu> 
Date: Wed, 18 Nov 92 22:54:10 CST
From: Dan Connolly <connolly@pixel.convex.com>


Here's a patch to add a function to fix all the existing
HREFs in an HTML file so they'll have quotes around them.

Dan

*** /mnt/connolly/foo	Wed Nov 18 22:51:50 1992
--- html-mode.el	Wed Nov 18 22:50:32 1992
***************
*** 517,522 ****
--- 517,543 ----
                 (setq html-link-counter (1+ html-link-counter))
                 (replace-string-in-buffer start (1- end)
                  (format "%d" html-link-counter))))))))
+ 
+ (defun html-quote-hrefs ()
+   "Insert quotes around all HREF attribute value literals.
+ 
+ This remedies the problem with old html files that can't be
+ processed by SGML parsers. That is, changes
+ <A HREF=foo> to <A HREF="foo">.
+ 
+ By Dan Connolly, so don't yell at Mark if it breaks."
+   (interactive)
+   (save-excursion
+     (goto-char (point-min))
+     (setq html-link-counter 0)
+     (while (re-search-forward "<[aA][ \t\n]+\\([nN][aA][mM][eE]=[a-zA-Z0-9]+[ \t\n]+\\)?[hH][rR][eE][fF]=" (point-max) t)
+       (cond ((null (looking-at "\""))
+ 	     (insert "\"")
+ 	     (re-search-forward "[ \t\n>]" (point-max) t)
+ 	     (forward-char -1)
+ 	     (insert "\"")
+ 	     ))
+       ) ) )
  
  ;;; ------------------------------- html-mode --------------------------------