SiteMap / AllPages / Out

HtmlQuote

While writing HTML with TheOneAndOnly editor, I sometimes want to cite HTML code on my page. In order to do that, I need to quote the `<', `&', and `>' characters. This is what I use when I don't use WikiMode:

    (defun html-quote (start end &optional arg)
      "Quote html code in region for inclusion into other HTML.
    With optional argument ARG reverse operation.
    This applies to the region between START and END."
      (interactive "r\nP")
      (let ((commands (if arg
                          '(("&amp;amp;" . "&amp;")
                            ("&amp;lt;" . "&lt;")
                            ("&amp;gt;" . "&gt;"))
                        '(("&amp;" . "&amp;amp;")
                          ("&lt;" . "&amp;lt;")
                          ("&gt;" . "&amp;gt;"))))
            (text (buffer-substring start end)))
        (with-temp-buffer
          (insert text)
          (while commands
            (let ((from-str (caar commands))
                  (to-str (cdar commands)))
              (goto-char (point-min))
              (while (search-forward from-str nil t)
                (replace-match to-str nil t)))
            (setq commands (cdr commands)))
          (setq text (buffer-substring (point-min) (point-max))))
        (kill-region start end)
        (goto-char start)
        (insert text)))

SiteMap / AllPages / Out / kensanata@yahoo.com / Last change: 2001-03-02