/
plugin.py
73 lines (63 loc) · 1.84 KB
/
plugin.py
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
62
63
64
65
66
67
68
69
70
71
72
from bs4 import BeautifulSoup
import urllib2
def appearance():
import Foundation
dark_mode = Foundation.NSUserDefaults.standardUserDefaults().persistentDomainForName_(Foundation.NSGlobalDomain).objectForKey_("AppleInterfaceStyle") == "Dark"
return "dark" if dark_mode else "light"
def generate_html(query):
url = "http://www.dfcd.net/projects/latex/latex.php?q=" + query
webpage = urllib2.urlopen(url)
soup = BeautifulSoup(webpage)
table = soup.findAll('table')[-1]
table = str(table).replace("./", "http://www.dfcd.net/projects/latex/")
html = """
<html>
<head>
<style>
* {
font-family: 'Helvetica Neue';
font-size: 16px;
font-weight: 200;
text-align: center;
}
table {
border: none;
background-color: #fff;
padding: 5px;
width: 100%;
}
td {
border: none;
padding: 5px;
-webkit-user-select: all;
}
.dark {
color: #fff;
padding: 10px 20px;
}
.light {
color: #000;
padding: 10px 20px;
}
</style>
</head>
<body>
<div class={{appearance}}>
<h4>Click a command, then ⌘ + C to copy</h4>
{{table}}
</div>
</body>
"""
html = html.replace("{{appearance}}", appearance())
html = html.replace("{{table}}", table)
return html
def results(fields, original_query):
query = fields['~message']
return {
"title" : "LaTeX Symbol Finder",
"html" : generate_html(query),
"webview_transparent_background" : True
}
def run( output):
import os
os.system('printf "' + output + '" | pbcopy')