Convert Microsoft "smart quotes" to standard quotes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from django.utils.encoding import smart_unicode

# translation mapping table that converts
# single smart quote characters to standard
# single quotes
SINGLE_QUOTE_MAP = {
	0x2018: 39, 
	0x2019: 39,
	0x201A: 39,
	0x201B: 39,
	0x2039: 39,
	0x203A: 39,
}

# translation mapping table that converts
# double smart quote characters to standard
# double quotes
DOUBLE_QUOTE_MAP = {
	0x00AB: 34,
	0x00BB: 34,
	0x201C: 34,
	0x201D: 34,
	0x201E: 34,
	0x201F: 34,
}

def convert_smart_quotes(str):
	"""
	Convert "smart quotes" from Microsoft products
	to standard quotes.
	"""
	return smart_unicode(str).translate(DOUBLE_QUOTE_MAP).translate(SINGLE_QUOTE_MAP)

More like this

  1. split_contents2 for template tags by bl4th3rsk1t3 3 years, 11 months ago
  2. Remove quotes from bits in a custom tag by mwdiers 4 years, 8 months ago
  3. Inline truncate by character number by esanchez 4 years, 10 months ago
  4. Convert Unicode to ASCII by coordt 5 years, 3 months ago
  5. run "silent" dev server by justinlilly 5 years, 11 months ago

Comments

(Forgotten your password?)