Emacs: HTML, Lines to List

By Xah Lee. Date: .

Here's a command that turn lines into HTML list.

(defun xah-html-lines-to-list ()
  "Make the current block of lines into a HTML list.

If `universal-argument' is called first, use ordered list <ol> instead of <ul>.

Example:
If your cursor is in the following block of text:

cat
dog

becomes:

<ul>
<li>cat</li>
<li>dog</li>
</ul>

Version 2019-03-15"
  (interactive)
  (let ($bds $p1 $p2 $input-str $resultStr )
    (setq $bds (xah-get-bounds-of-thing 'block))
    (setq $p1 (car $bds))
    (setq $p2 (cdr $bds))
    (setq $input-str (buffer-substring-no-properties $p1  $p2))
    (save-excursion
      (setq $resultStr
            (with-temp-buffer
              (insert $input-str)
              (goto-char (point-max))
              (insert "\n")
              (progn
                (goto-char (point-min))
                (while
                    (re-search-forward  "\.html$" nil t)
                  (backward-char 1)
                  (xah-html-any-linkify)))
              (goto-char (point-min))
              (while
                  (not (equal (line-end-position) (point-max)))
                (beginning-of-line)
                (when (looking-at "• ")
                  (delete-char 2))
                (when (looking-at "* ")
                  (delete-char 2))
                (when (looking-at "- ")
                  (delete-char 2))
                (when (looking-at "⓪①②③④⑤⑥⑦⑧⑨⑩")
                  (delete-char 2))
                (insert "<li>")
                (end-of-line) (insert "</li>")
                (forward-line 1 ))
              (if current-prefix-arg
                  (progn
                    (goto-char (point-min))
                    (insert "<ol>\n")
                    (goto-char (point-max))
                    (insert "</ol>"))
                (progn
                  (goto-char (point-min))
                  (insert "<ul>\n")
                  (goto-char (point-max))
                  (insert "</ul>")))
              (buffer-string))))
    (delete-region $p1 $p2)
    (insert $resultStr)))

You need Emacs: xah-get-thing.el

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy JavaScript in Depth

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Tutorial

Quick Start

Manage Windows

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Doc

Working with Brackets

Power Editing

Org Mode

HTML

Emacs Efficiency

Misc