html-charref package for converting string from/to HTML charref.
--- a/.emacs-my Tue Jun 21 12:07:04 2011 +0300
+++ b/.emacs-my Tue Jun 21 16:18:54 2011 +0300
@@ -1497,7 +1497,7 @@
;;; ----------------------------------------------------------------
(message "html")
-(defun text2html (start end)
+(defun html-charref-escape-region (start end)
(interactive "r")
(save-excursion
(save-restriction
@@ -1510,6 +1510,45 @@
(replace-string ">" ">")
)))
+(defun html-charref-from-char (char)
+ (format "&#%d;" char)
+ )
+
+(defun html-charref-from-string (string)
+ (let ((res ""))
+ (mapc
+ (lambda (char) (setq res (concat res (html-charref-from-char char))))
+ string)
+ res
+ ) )
+
+(defun html-charref-escape-region2 (begin end &optional prefix)
+ (interactive "r\nP")
+ (if prefix
+ (save-excursion
+ (goto-char begin)
+ (insert (html-charref-from-string (delete-and-extract-region begin end))))
+ (html-charref-from-string (buffer-substring begin end))
+ ))
+
+(defun html-charref-to-string (html)
+ (let ((res "") (pos 0))
+ (while (string-match "&#\\([[:digit:]]+\\);" html pos)
+ (setq res (concat res (string (string-to-int (substring html (match-beginning 1) (match-end 1)) 10))))
+ (setq pos (match-end 0))
+ )
+ res
+ ) )
+
+(defun html-charref-unescape-region (begin end &optional prefix)
+ (interactive "r\nP")
+ (if prefix
+ (save-excursion
+ (goto-char begin)
+ (insert (html-charref-to-string (delete-and-extract-region begin end))))
+ (html-charref-to-string (buffer-substring begin end))
+ ))
+
;;; ----------------------------------------------------------------
(message "nxml")