(Go to my E2 tool index)

E2 doesn't allow external links to be used, but ocassionally people have HTML document at hand with just a couple of links that they'd like to node (for example, a +5, Insightful Slashdot comment or 4.91 / 12 Kuro5hin comment, or something of slightly less rated by others but of equal worthiness in metaphysical sense).

This program takes a HTML document and "unlinks" it (adding footnote numbers), adding all links it found to the end of the document.


;;; This "Unlinks" a HTML document - it removes all hypertext anchors
;;; from the text, inserts superscript numbers, and creates a
;;; list of those links to the end of the document.
;;; Be sure to remove all those links from the document that you don't
;;; want to list in the end, because otherwise clearing the list up
;;; makes numbers go out of synch And That Isn't Fun.
;;; Not tested with links that go to multiple lines...
;;; Distributed under the Artistic Lisence.
;;; Written by Urpo Lankinen / Weyfour WWWWolf
;;; <wwwwolf@iki.fi> <http://www.iki.fi/wwwwolf/>
;;; $Id: html-unlink.el,v 1.0 2001/04/26 17:40:06 wwwwolf Exp $

(defun html-links-to-footnotes-buffer (buffer)
  "Remove all HTML links from buffer and insert them to the end of the
   document as a list."
  (interactive "bBuffer: ")

      ((linklist '())
       (foundlinks 0))

    (switch-to-buffer buffer)
    (goto-char (point-min))

    ;; Replace all occurences of <a href="...">...</a>
	 "<a href=\"\\([^\"]*\\)\">\\([^<]*\\)</a>"
	 nil t)

      ;; Increment match counter
      (setq foundlinks (+ foundlinks 1)) 
      ;; Append the URL to the link list
      (setq linklist
	    (append linklist
		    (list (match-string 1))))

      ;; Replace the string with stuph...
       (format "\\2 <sup><small><small>%d</small></small></sup>" foundlinks)
       nil nil))

    (if (> foundlinks 0)
	(let ()

	  (goto-char (point-max))
	  (insert "\n\n<ol>\n")

	  ;; I know, using bare side effects is Naughty...
	  ;; I wanted to use (insert (concat... )) but that didn't
	  ;; work at all (said just that my string wasn't characterp. Silly.)
	   '(lambda (string)
	      (insert (format "<li>%s\n" string)))

	  (insert "</ol>\n")

	  (message "Found %d links." foundlinks))
      (let ()
	(error "No links found!")))))

Log in or registerto write something here or to contact authors.