Lets start with conversion one line with this function
(defun wrap-line (before after)
"Convert line at the point adding BEFORE and AFTER."
(save-excursion
(progn
(goto-char (line-beginning-position))
(insert before)
(goto-char (line-end-position))
(insert after))))
You could wrap line into <li>
and </li>
with function
(defun wrap-into-li ()
(interactive)
(wrap-line "<li>" "</li>"))
This function do the same that @Jules macros in another answer. And you could set key for this with, for example
(global-set-key (kbd "C-c w l") 'wrap-into-li)
You could convert block from start
till end
with markers of block and each line with function:
(defun wrap-block (start end before-block after-block before-line after-line)
"Wrap each line and whole block.
Wrap block from START till END with BEFORE-BLOCK and AFTER-BLOCK
and wrap each line inside with BEFORE-LINE and AFTER-LINE."
(save-excursion
(goto-char start)
(goto-char (line-beginning-position))
(insert before-block) (newline)
(while (<= (point) end)
(wrap-line before-line after-line)
(forward-line 1))
(insert after-block) (newline)))
And you could use this function on region and make block <ul>
(marked) with:
(defun make-region-ul (start end)
(interactive "r")
(wrap-block start end "<ul>" "</ul>" "<li>" "</li>"))
or make block <ol>
(numbered) with:
(defun make-region-ol (start end)
(interactive "r")
(wrap-block start end "<ol>" "</ol>" "<li>" "</li>"))
and bound this functions to keys:
(global-set-key (kbd "C-c w u") 'make-region-ul)
(global-set-key (kbd "C-c w o") 'make-region-ol)