ELisp: HTML Link to Dead Link

By Xah Lee. Date: .

Here's a command that turn a link in html into a dead link with strik-thru.

<a href="http://example.com/">http://example.com/</a>


<s data-accessed="" data-defunct-date="2019-04-02">http://example.com/</s>

with today's date added to the “data-defunct-date” part.

the HTML s tag means strike thru. [see HTML: s strike del Tags]

Here's the Code.

(defun xah-html-make-link-defunct ()
  "Make the HTML link under cursor to a defunct form.
If cursor is inside this tag
 <a href=\"‹url›\">…</a>
 <a href=\"‹url›\" data-accessed=\"‹access_date›\">…</a>
where ‹access_date› is of this format 2019-04-02

It becomes:
 <s data-accessed=\"‹access_date›\" data-defunct-date=\"‹now_date›\">‹url›</s>

URL `http://xahlee.info/emacs/emacs/elisp_html-linkify.html'
Version 2019-04-02"
  (let ($p1 $p2 $wholeLinkStr $newLinkStr $url $accessedDate)
      ;; get the boundary of opening tag
      (forward-char 3)
      (search-backward "<a " ) (setq $p1 (point))
      (search-forward "</a>") (setq $p2 (point))
      (setq $wholeLinkStr (buffer-substring-no-properties $p1 $p2))
        ;; generate replacement text
        (insert $wholeLinkStr)
        (goto-char (point-min))
        (re-search-forward  "href=\"\\([^\"]+?\\)\"")
        (setq $url (match-string 1))
        (setq $accessedDate
              (if (re-search-forward
                   "data-accessed=\"\\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\\)\"" $p2 t)
                  (match-string 1)
        (setq $newLinkStr
              (format "<s data-accessed=\"%s\" data-defunct-date=\"%s\">%s</s>" $accessedDate (format-time-string "%Y-%m-%d") $url ))))
    (delete-region $p1 $p2)
    (insert $newLinkStr)))