(defunxah-html-ul-to-dl (&optionalSepChar)
"Change html unordered list to definition list.
Cursor must be on the left of ▮<ul>
SepChar is a string that separates term and definition, in a <li> item.
KeepSep if true, keep the SepChar in result.
Warning, if you have nested list, remember that each li must have a SepChar in its inner text.
Created: 2020-09-05
Version: 2025-06-29"
(interactive (list (read-string"Seperator:"" -- ")))
(when (not (string-equal"<ul"
(buffer-substring-no-properties
(point)
(+ (point) (length"<ul")))))
(search-backward"<ul"nilt)
(user-error"%s: Cursor must be on the left of ▮<ul.
Cursor is moved to there now.
"this-command))
(when
(not (string-equal"<ul" (buffer-substring-no-properties (point) (+ (point) (length"<ul"))))) (user-error"%s: Cursor must be on the left of ▮<ul"this-command))
(let (xbegxend)
(seq-setq (xbegxend) (list (point) (progn (xah-html-skip-tag-forward) (point))))
(save-restriction
(narrow-to-regionxbegxend)
(progn
(goto-char (point-min))
(while (re-search-forward"<\\(/?\\)ul\\(?: [^>]+\\)?>"nilt)
(replace-match"<\\1dl\\2>"t)))
(progn
(goto-char (point-min))
(while (re-search-forward"<li\\(?: [^>]+\\)?>"nilt)
(replace-match"<dt\\2>"t)))
(progn
(goto-char (point-min))
(while (re-search-forward"</li>"nilt)
(replace-match"</dd>\n"t)))
(progn
(goto-char (point-min))
(while (re-search-forward (concat" *"SepChar" *") nilt)
(replace-match"</dt>\n<dd>"t))))))