开发者

Basic HTML operations in Emacs

I am working with HTML in Emacs and I am looking for ways to make basics operations as:

  • convert list of string to HTML-list

    one
    two
    three
    

    to

    <ul>
     <li>one</li>
     <l开发者_StackOverflowi>two</li>
     <li>three</li>
    </ul>
    
  • add class to list of elements

    <a></a>
    <a></a>
    <a></a>
    

    to

    <a class="one"></a>
    <a class="one"></a>
    <a class="one"></a>
    

Is there any extensions which can helps me?


I would do this with a macro:

  • Move to the first line, and type C-x (
  • Type the <li>, move to the end </li>, and move to the next line
  • End and repeat the macro on the remaining lines with C-x e e e e e...

This can easily be generalized to add classes to your <a> tags, and many other things.


You should take a look at zencoding , it's pretty useful. Here's a youtube video showing it with yasnippet, showing some functionality like what you want.


You can add class to list of elements using command M-x replace-string.


Here is an Emacs Lisp function which performs the first task (operates on selected text):

(defun my-make-list (start end)
  (interactive "r")
  (insert "<ul>\n")
  (mapcar '(lambda (line) (insert (concat " <li>" line "</li>\n")))
          (split-string (buffer-substring start end) "\n"))
  (insert "</ul>")
  (delete-region start end))

In the second case I would just use search/replace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜