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]

HTML Topic

  1. Emacs HTML Tips
  2. Insert HTML Tag
  3. URL to Link Command
  4. Lines to HTML Table
  5. Replace HTML Entities
  6. CSS Compressor
  7. Color CSS Color Values
  8. View Image Thumbnails
  9. HTML Image Path to Img Tag
  10. Convert Image Files in Dired
  11. Xah HTML Mode

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp