This repository was archived by the owner on Jan 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautocorrect.coffee
More file actions
61 lines (59 loc) · 3.41 KB
/
autocorrect.coffee
File metadata and controls
61 lines (59 loc) · 3.41 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This function does all the changes to the code in a series of replace steps.
Toolbar.add_button
name: 'Autocorrect'
pos: 80
callback: ->
Toolbar.actOnSelection (txt, isSelection) ->
Toolbar.clean txt.replace(/\t/g, " "), (line) ->
# words to capitalize
words = ["AMD", "AppleScript", "ASUS", "ATI", "Bluetooth", "DivX", "DVD", "Eee PC", "FireWire",
"GarageBand", "GHz", "iBookstore", "iCal", "iChat", "iLife", "iMac", "iMovie", "iOS", "iPad",
"iPhone", "iPhoto", "iPod", "iTunes", "iWeb", "iWork", "JavaScript", "jQuery", "Lenovo",
"MacBook", "MacPorts", "MHz", "MobileMe", "MySQL", "Nvidia", "OS X", "PowerBook", "PowerPoint",
"QuickTime", "SSD", "TextEdit", "TextMate", "ThinkPad", "USB", "VMware", "WebKit", "Wi-Fi",
"Windows XP", "WordPress", "Xcode", "XMLHttpRequest", "Xserve"]
line
# convert pronouns from monkeglish/lolcatz
.replace(/\bi( |')/g, "I$1" )
.replace(/\bi ?m\b/ig, "I'm" )
.replace(/\bu\b/g, "you" )
.replace(/\bur\b/g, "your")
.replace(/\bcud\b/ig, "could")
.replace(/\bb4\b/ig, "before")
.replace(/\bpl[sz]\b/i, "please")
# these '' are a fricking effort to type, eh?
.replace(/\b(can|doesn|won|hasn|isn|didn)t\b/ig, "$1't")
# determiners are often a problem, special cased HTML.
.replace(/\b(a)n(?= +(?![aeiou]|HTML|user))/gi,"$1")
.replace(/\b(a)(?= +[aeiou](?!ser))/gi, "$1n" )
.replace(/\b(a)lot\b/gi, "$1 lot" )
# get rid of greetings and gratitude (would be nice to get rid of signature as well
# but I have no clue how)
# as per http://meta.stackoverflow.com/questions/2950
.replace(/// ^( H(i|[eaiy][yiea]|ell?o) | greet(ings|z) ) # hi hello greetings
(\s to )? \s? # to
( every(one|body) | expert | geek | all | friend | there | guy | people | folk )?s?
\s*[\!\.\,\:]*\s*///ig, "")
.replace(/^(thx|thanks?|cheers|thanx|tia)\s?((in advance)|you)?[\.\!\,]*/gi, "")
# basic typography
.replace(/[ ]*([\:\,]) */g, "$1 ")
# uses a negative lookahead to skip common filenames (that can't be beginnings of words)
.replace(/([\.\?\!] *|^)(?!rb|txt|hs|x?h?t?ml|htaccess|dll|wav|mp3|exe|ini|htpasswd)(.)/g, -> #(?![\s\.])
if arguments[1].length == 0
arguments[2].toUpperCase();
else
arguments[1].trim() + " " + arguments[2].toUpperCase();
).replace(/[ ]*\.( ?\.)+ */g, "... " )
.replace(/[ ]*([\?\!] ?)+ */g, "$1" )
#correct stuff messed up by this script
.replace(/\. (\d)/g, ".$1") # digits tend to be version numbers or numerals
# use of comma is the most common, see http://english.stackexchange.com/questions/16172
.replace(/\be\.? *G\.?\,? +(.)/gi, (_, l) -> "e.g., " + l.toLowerCase()
#too bad it's also short for Internet Explorer (it can screw up your js just by it's mere existence)
).replace(/\bi\. *e\. (.)/gi, (_, l) -> "i.e. " + l.toLowerCase()
# Use the words defined at the top
).replace RegExp('\\b(?:(' + words.join(')|(') + '))\\b', 'ig'), (m) ->
a = arguments.length - 2
while a--
return words[a-1] || m if arguments[a]
, true # = Will do stuff on the title as well