Debian Codegraph @

proselint/checks/typography/symbols.py

raw
1 """Use the right symbols.
2
3 source: Butterick's Practical Typography
4 source_url: http://practicaltypography.com/
5 """
6
7 from proselint.tools import existence_check, max_errors, memoize
8
9
10 @max_errors(3)
11 @memoize
12 def check_ellipsis(text):
13 """Use an ellipsis instead of three dots."""
14 err = "typography.symbols.ellipsis"
15 msg = "'...' is an approximation, use the ellipsis symbol '…'."
16 regex = r"\.\.\."
17
18 return existence_check(text, [regex], err, msg, require_padding=False,
19 offset=0)
20
21
22 @max_errors(1)
23 @memoize
24 def check_copyright_symbol(text):
25 """Use the copyright symbol instead of (c)."""
26 err = "typography.symbols.copyright"
27 msg = "(c) is a goofy alphabetic approximation, use the symbol ©."
28 regex = r"\([cC]\)"
29
30 return existence_check(text, [regex], err, msg, require_padding=False)
31
32
33 @max_errors(3)
34 @memoize
35 def check_trademark_symbol(text):
36 """Use the trademark symbol instead of (TM)."""
37 err = "typography.symbols.trademark"
38 msg = "(TM) is a goofy alphabetic approximation, use the symbol ™."
39 regex = r"\(TM\)"
40
41 return existence_check(text, [regex], err, msg, require_padding=False)
42
43
44 @max_errors(3)
45 @memoize
46 def check_registered_trademark_symbol(text):
47 """Use the registered trademark symbol instead of (R)."""
48 err = "typography.symbols.trademark"
49 msg = "(R) is a goofy alphabetic approximation, use the symbol ®."
50 regex = r"\([rR]\)"
51
52 return existence_check(text, [regex], err, msg, require_padding=False)
53
54
55 @max_errors(3)
56 @memoize
57 def check_sentence_spacing(text):
58 """Use no more than two spaces after a period."""
59 err = "typography.symbols.sentence_spacing"
60 msg = "More than two spaces after the period; use 1 or 2."
61 regex = r"\. {3}"
62
63 return existence_check(text, [regex], err, msg, require_padding=False)
64
65
66 @max_errors(3)
67 @memoize
68 def check_multiplication_symbol(text):
69 """Use the multiplication symbol ×, not the lowercase letter x."""
70 err = "typography.symbols.multiplication_symbol"
71 msg = "Use the multiplication symbol ×, not the letter x."
72 regex = r"[0-9]+ ?x ?[0-9]+"
73
74 return existence_check(text, [regex], err, msg, require_padding=False)
75
76
77 @max_errors(3)
78 @memoize
79 def check_curly_quotes(text):
80 """Use curly quotes, not straight quotes."""
81 err = "typography.symbols.curly_quotes"
82 msg = 'Use curly quotes “”, not straight quotes "".'
83 regex = r"\"[\w\s\d]+\""
84
85 return existence_check(text, [regex], err, msg, require_padding=False)
86
87 # @memoize
88 # def check_en_dash_separated_names(text):
89 # """Use an en-dash to separate names."""
90 # # [u"[A-Z][a-z]{1,10}[-\u2014][A-Z][a-z]{1,10}",
91 # # u"Use an en dash (–) to separate names."],