(defunxah-html-show-duplicate-links ()
"highlight and print any duplicate links in current html file.
Created: 2024-07-22
Version: 2024-07-22"
(interactive)
(let (xp1xp2xlink
(xlinksTable (make-hash-table:test 'equal)))
(seq-setq (xp1xp2)
(if (region-active-p)
(vector (region-beginning) (region-end))
(vector (point-min) (point-max))))
(save-restriction
(narrow-to-regionxp1xp2)
;; algorithm. Find each link, then for each, extract the link, if it ;; is local, then expand to file absolute path. check if the path is ;; in hashtable. If so, highlight the link Else, add to hashtable. ;; Repeat to next link.
(goto-char (point-min))
(while (search-forward"href=\""nilt)
(let (xboundaryxbegxendxhrefval)
(setqxboundary (bounds-of-thing-at-point 'filename))
(setqxbeg (carxboundary) xend (cdrxboundary))
(setqxhrefval (buffer-substring-no-propertiesxbegxend))
(setqxlink
(if (string-match"^http"xhrefval)
xhrefval
(expand-file-namexhrefvaldefault-directory)))
(if (gethashxlinkxlinksTable)
(progn
(overlay-put (make-overlayxbegxend) 'face 'font-lock-warning-face)
(message"DUPLICATE: %s"xlink))
(progn
(puthashxlink 1 xlinksTable))))))))