Emacs: HTML, Wrap Paragraph Tags

By Xah Lee. Date: . Last updated: .

Here's a command to wrap a ā€œpā€ tag around current text block or selection.

(defun xah-html-wrap-p-tag ()
  "Add <p>ā€¦</p> tag to current block or text selection.
If there's a text selection, wrap p around each text block.
A text block is separated by blank lines.

URL `http://ergoemacs.org/emacs/emacs_html_wrap_tags.html'

Version 2019-06-21"
  (interactive)
  (let* (
         ($bds (xah-get-bounds-of-thing-or-region 'block))
         ($p1 (car $bds))
         ($p2 (cdr $bds))
         ($inputText (buffer-substring-no-properties $p1 $p2)))
    (delete-region $p1 $p2 )
    (insert
     "<p>\n"
     (replace-regexp-in-string "\n\n+" "</p>\n\n<p>" (string-trim $inputText))
     "\n</p>")
    (skip-chars-forward "\n" )))

You need (require 'subr-x) and Emacs: xah-get-thing.el

HTML

Tags

Links

CSS

Misc

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial