gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-w3m display html patch


From: Henrik S. Hansen
Subject: emacs-w3m display html patch
Date: Sun, 17 Oct 2004 12:21:45 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

This is a patch for emacs-w3m to properly display some otherwise
non-displayable HTML character entities on the console (and in X with no
matching fonts) -- by default they are displayed as ~ (tilde).

The patch works for both version 1.4.3 and newest CVS (v. 1.1070).
Comments on the patch are very welcome.

Author: Henrik S. Hansen <address@hidden>
License: GNU General Public License, ver. 2 or newer

diff -Naur emacs-w3m.orig/w3m.el emacs-w3m/w3m.el
--- emacs-w3m.orig/w3m.el       2004-10-16 14:59:07.000000000 +0200
+++ emacs-w3m/w3m.el    2004-10-16 16:33:31.000000000 +0200
@@ -2745,14 +2745,43 @@
         (cdr elem))))
 
 (eval-and-compile
-  (unless (fboundp 'w3m-ucs-to-char)
-    (defun w3m-ucs-to-char (codepoint)
-      "A dummy function defined since nothing provided the regular function.
-This function simply returns the arg if it is between 0x20 and 0x7e,
-otherwise returns the tilde character."
+  (unless (fboundp 'w3m-ucs-to-string)
+    (defun w3m-ucs-to-string (codepoint)
+      "A dummy function defined since nothing provided the regular
+function.  This function returns the string representation of
+CODEPOINT, if it is between 0x20 and 0x7e.  Otherwise, we try to map
+CODEPOINT to a string resembling the HTML character entity, and return
+this.  If this is not possible, a string with only the tilde character
+is returned."
       (if (or (< codepoint 32) (< 127 codepoint))
-         ?~ ;; unsupported character
-       codepoint))))
+          (cond 
+           ((= codepoint 8211) "-") ;; en dash
+           ((= codepoint 8212) "--") ;; em dash
+           ((= codepoint 8216) "`") ;; left single quote
+           ((= codepoint 8217) "'") ;; right single quote
+           ((= codepoint 8218) "'") ;; single low quote
+           ((= codepoint 8220) "\"") ;; left double quote
+           ((= codepoint 8221) "\"") ;; right double quote
+           ((= codepoint 8222) "\"") ;; double low quote
+           ((= codepoint 8224) "^") ;; dagger
+           ((= codepoint 8225) "^") ;; double dagger
+           ((= codepoint 8226) "*") ;; bullet
+           ((= codepoint 8230) "...") ;; ellipses
+           ((= codepoint 8240) "%.") ;; per mille (thousand)
+           ((= codepoint 8242) "'") ;; prime, minutes, feet
+           ((= codepoint 8243) "\"") ;; double prime, seconds, inches
+           ((= codepoint 8260) "/") ;; fraction slash
+           ((= codepoint 8482) "(tm)") ;; trademark
+           ((= codepoint 8592) "<-") ;; left arrow
+           ((= codepoint 8593) "^") ;; up arrow
+           ((= codepoint 8594) "->") ;; right arrow
+           ((= codepoint 8595) "v") ;; down arrow
+           ((= codepoint 8596) "<->") ;; left-right arrow
+           ((= codepoint 8656) "<=") ;; left double arrow
+           ((= codepoint 8658) "=>") ;; right double arrow
+           ((= codepoint 8660) "<=>") ;; left-right double arrow
+           (t (char-to-string ?~)))
+        (char-to-string codepoint)))))
 
 (defun w3m-entity-value (name strict)
   "Get a char corresponding to NAME from the html char entities database.
@@ -2773,7 +2802,7 @@
        (let ((codepoint (if (char-equal (string-to-char name) ?x)
                             (string-to-number (substring name 1) 16)
                           (string-to-number name))))
-         (char-to-string (w3m-ucs-to-char codepoint))))
+         (w3m-ucs-to-string codepoint)))
     (let ((val (intern-soft name w3m-entity-db))
          (pre name)
          (post ""))

-- 
Henrik S. Hansen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]