* eww.el (eww-detect-charset): Detect charset from the <meta> tag.
authorKatsumi Yamaoka <yamaoka@jpl.org>
Thu, 13 Jun 2013 05:38:23 +0000 (07:38 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Thu, 13 Jun 2013 05:38:23 +0000 (07:38 +0200)
lisp/ChangeLog
lisp/eww.el

index 1072910..f41d86d 100644 (file)
@@ -1,3 +1,7 @@
+2013-06-13  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+       * eww.el (eww-detect-charset): Detect charset from the <meta> tag.
+
 2013-06-12  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * shr.el (shr-tag-svg): Ignore SVG elements, because we don't know how
index 3e79973..8f8dbec 100644 (file)
   (interactive "sUrl: ")
   (url-retrieve url 'eww-render (list url)))
 
+(defun eww-detect-charset (html-p)
+  (let ((case-fold-search t)
+       (pt (point)))
+    (or (and html-p
+            (re-search-forward
+             "<meta[\t\n\r ]+[^>]*charset=\\([^\t\n\r \"/>]+\\)" nil t)
+            (goto-char pt)
+            (match-string 1))
+       (and (looking-at
+             "[\t\n\r ]*<\\?xml[\t\n\r ]+[^>]*encoding=\"\\([^\"]+\\)")
+            (match-string 1)))))
+
 (defun eww-render (status url &optional point)
   (let* ((headers (eww-parse-headers))
         (content-type
@@ -47,6 +59,8 @@
         (charset (intern
                   (downcase
                    (or (cdr (assq 'charset (cdr content-type)))
+                       (eww-detect-charset (equal (car content-type)
+                                                  "text/html"))
                        "utf8"))))
         (data-buffer (current-buffer)))
     (unwind-protect