changeset 153:207f0b4af9df dev

Unescape URL strings from buffer(yahtml-unescape-string).
author yuuji@gentei.org
date Sat, 06 Nov 2010 19:24:34 +0900
parents 095a5c97ecac
children d3bcc4e2166a
files yahtml.el
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/yahtml.el	Wed Oct 20 12:36:36 2010 +0900
+++ b/yahtml.el	Sat Nov 06 19:24:34 2010 +0900
@@ -1,6 +1,6 @@
 ;;; -*- Emacs-Lisp -*-
 ;;; (c) 1994-2010 by HIROSE Yuuji [yuuji(@)yatex.org]
-;;; Last modified Mon Sep 13 08:09:46 2010 on firestorm
+;;; Last modified Sat Nov  6 19:22:54 2010 on firestorm
 ;;; $Id$
 
 (defconst yahtml-revision-number "1.74.2"
@@ -1051,6 +1051,21 @@
 	(setq str (substring str (1+ p))))
       (concat target str)))))
 
+(defun yahtml-unescape-string (str)
+  "Untranslate reserved URL-encoded string."
+  (let ((p 0) c (target "") (md (match-data)) (case-fold-search nil))
+    (unwind-protect
+	(progn
+	  (while (string-match "%\\([0-9a-f][0-9a-f]\\)" str p)
+	    (setq target (concat target
+				 (substring str p (1- (match-beginning 1))))
+		  p (match-end 0)
+		  c (YaTeX-hex (substring
+				str (match-beginning 1) (match-end 1)))
+		  target (concat target (format "%c" c))))
+	  (concat target (substring str p)))
+      (store-match-data md))))
+
 (defun yahtml-escape-chars-region (beg end)
   "Translate reserved chars to encoded string in the region."
   (interactive "r")
@@ -1711,7 +1726,7 @@
 	     (skip-chars-forward " \t\n")
 	     (looking-at "\"?\\([^\"> \t\n]+\\)\"?"))
 	   (< p (match-end 0))
-	   (YaTeX-match-string 1)))))
+	   (yahtml-unescape-string (YaTeX-match-string 1))))))
 
 (defun yahtml-netscape-sentinel (proc mes)
   (cond
@@ -1889,7 +1904,8 @@
   (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t))
     (if (and tag
 	     (string-match "img" tag)
-	     (setq image (yahtml-get-attrvalue "src")))
+	     (setq image
+		   (yahtml-unescape-string (yahtml-get-attrvalue "src"))))
 	(progn
 	  (message "Invoking %s %s..." yahtml-image-viewer image)
 	  (start-process
@@ -1903,7 +1919,7 @@
   (let ((env (yahtml-current-tag)) s (p (point)))
     (cond
      ((string-match "applet" env)
-      (if (setq s (yahtml-get-attrvalue "code"))
+      (if (setq s (yahtml-unescape-string (yahtml-get-attrvalue "code")))
 	  (progn
 	    (setq s (YaTeX-match-string 1)
 		  s (concat

yatex.org