Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support funky Microsoft Word XHTML unicode escapes #60

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from html2text import config

from html2text.utils import (
wide_unichr,
name2cp,
unifiable_n,
google_text_emphasis,
Expand Down Expand Up @@ -703,7 +704,7 @@ def charref(self, name):
return unifiable_n[c]
else:
try:
return unichr(c)
return wide_unichr(c)
except NameError: # Python3
return chr(c)

Expand All @@ -720,7 +721,7 @@ def entityref(self, c):
return config.UNIFIABLE[c]
else:
try:
return unichr(name2cp(c))
return wide_unichr(name2cp(c))
except NameError: # Python3
return chr(name2cp(c))

Expand Down
9 changes: 9 additions & 0 deletions html2text/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import sys
from html2text import config
import struct

from html2text.compat import htmlentitydefs

# Based on http://stackoverflow.com/questions/7105874/valueerror-unichr-arg-not-in-range0x10000-narrow-python-build-please-hel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to the share link for this question instead: http://stackoverflow.com/q/7105874/173630

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

def wide_unichr(i):
try:
return unichr(i)
except ValueError:
return struct.pack('i', i).decode('utf-32')



def name2cp(k):
if k == 'apos':
Expand Down