Xah Talk Show 2022-09-22 Emacs Lisp Coding. Write Command to Add HTML Section Tags

vidthumb Zm  S8zQ40E
(defun xah-html-add-section-tags ()
  "Add HTML section tags to enclose all h3 headers.
Version 2022-09-22"
  (interactive)
  (let (xp1 xp2)
    (setq xp1 (region-beginning))
    (setq xp2 (region-end))
    (save-restriction
      (narrow-to-region xp1 xp2)

      (goto-char (point-min))
      (while (search-forward "<h3>" nil t)
        (replace-match "</section>

<section>

<h3>" t t))

      (goto-char (point-min))
      (search-forward "</section>" nil t)
      (replace-match "")

      (goto-char (point-max))
      (insert "</section>"))))