Emacs: Wrap HTML Tags

By Xah Lee. Date: .

Here's a command to wrap a “p” tag around current text block or selection.

You need Emacs: xah-get-thing.el

(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 2018-03-22"
  (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>" (replace-regexp-in-string "\n\n+" "</p>\n\n<p>" (xah-html--trim-string $inputText)) "</p>")))

[see Emacs: How to Define Keys]

Emacs HTML Topic

  1. Emacs HTML Tips
  2. Emacs: Xah HTML Mode
  3. Emacs: Insert HTML Tag
  4. Emacs: URL to Link Command
  5. Elisp: Replace HTML Entities
  6. Emacs: CSS Compressor
  7. Emacs: Working with CSS Color Values
  8. Emacs: View Image Thumbnails
  9. Emacs: HTML Image Path to Img Tag
  10. Emacs: Convert Image Files in Dired
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.