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://ergoemacs.org/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 1)
        (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)))

Elisp HTML Commands

  1. wrap-url
  2. URL to Link
  3. Link to Dead Link
  4. Make Image Links
  5. Extract URL
  6. Word to Wikipedia Linkify
  7. Wikipedia URL Linkify
  8. URL Percent Decode/Encode
  9. Lines to HTML Table
  10. Markup Function Names
  11. Color Source Code
  12. Transform Text Under Cursor
  13. Chinese Char Reference Linkify
  14. HTML make-citation
  15. update-title
  16. Google Map Linkify 🌐
  17. CSS Compressor
  18. Make Ruby Annotation
  19. Move Image File

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp