2 ;;; richtext.el -- read and save files in text/richtext format
4 ;;; $Id: richtext.el,v 1.4 1995/07/15 17:58:36 morioka Exp $
9 (if (or (< emacs-major-version 19)
10 (and (= emacs-major-version 19)
11 (< emacs-minor-version 29))
18 ;;; @ text/richtext <-> text/enriched converter
21 (defun richtext-to-enriched-region (beg end)
22 "Convert the region of text/richtext style to text/enriched style."
25 (narrow-to-region beg end)
26 (goto-char (point-min))
28 (while (re-search-forward "[ \t]*<comment>" nil t)
29 (setq b (match-beginning 0))
31 (if (re-search-forward "</comment>[ \t]*" nil t)
36 (goto-char (point-min))
37 (while (re-search-forward "\n\n+" nil t)
40 (goto-char (point-min))
41 (while (re-search-forward "[ \t\n]*<nl>[ \t\n]*" nil t)
42 (setq b (match-beginning 0))
43 (setq e (match-end 0))
45 (while (looking-at "[ \t\n]*<nl>[ \t\n]*")
46 (setq e (match-end 0))
55 (goto-char (point-min))
56 (while (search-forward "<lt>" nil t)
61 (defun enriched-to-richtext-region (beg end)
62 "Convert the region of text/enriched style to text/richtext style."
66 (and (search-forward "text/enriched")
67 (replace-match "text/richtext"))
68 (search-forward "\n\n")
69 (narrow-to-region (match-end 0) end)
71 (goto-char (point-min))
72 (while (re-search-forward "\n\n+" nil t)
73 (setq str (buffer-substring (match-beginning 0)
75 (setq n (1- (length str)))
78 (setq str (concat str "<nl>\n"))
83 (goto-char (point-min))
84 (while (search-forward "<<" nil t)
85 (replace-match "<lt>")
90 ;;; @ encoder and decoder
93 (defun richtext-decode (beg end)
95 (narrow-to-region beg end)
96 (richtext-to-enriched-region beg (point-max))
97 (enriched-decode beg (point-max))
100 (defun richtext-encode (beg end)
102 (narrow-to-region beg end)
103 (enriched-encode beg (point-max))
104 (enriched-to-richtext-region beg (point-max))
111 (set-alist 'format-alist
113 '("Extended MIME text/richtext format."
114 "Content-[Tt]ype:[ \t]*text/richtext"
115 richtext-decode richtext-encode t enriched-mode))