-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_scite_api_files_1.py
190 lines (135 loc) · 5.95 KB
/
make_scite_api_files_1.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!python3
'''Make sciteproperties.api and scitevariables.api files from SciTEDoc.html.'''
import os, re, sys
import common
settings = common.settings
# Set OS specific. True=All properties except for other OSes. False=All.
settings['os_specific'] = True
def get_absent_property_items(content):
'''Get property items absent of an id attribute.'''
properties = []
# Items expected to have a id attribute.
exclude = ['style.lexer.34', 'style.lexer.35']
# Brief property doc string.
doc = {
'style.lexer.32': 'Default style...',
'style.lexer.33': 'Line numbers in the margin...',
'style.lexer.36': 'Control characters...',
'style.lexer.37': 'Indentation guides...',
'style.lexer.38': 'Calltips...',
'command.name.number.filepattern': 'Tools menu text item...',
'command.number.filepattern': 'Command string...',
'command.is.filter.number.filepattern': 'Optional...',
'command.subsystem.number.filepattern': 'Subsytem default is 0...',
'command.save.before.number.filepattern': '1 auto save 2 no save else ask...',
'command.input.number.filepattern': 'Windows only. Optional...',
'command.replace.selection.number.filepattern': 'Optional...',
'command.quiet.number.filepattern': '1 no echo...',
'command.mode.number.filepattern': 'Comma-separated list of settings...',
'command.shortcut.number.filepattern': 'Keyboard shortcut for the command...'}
for item in doc:
if doc[item] and not doc[item].startswith('\\n '):
doc[item] = '\\n ' + doc[item]
# Get command... property section and style... property section.
alt = r'command\.name\.<i>number</i>\.<i>filepattern|style\.<i>lexer</i>\.\d'
matches = re.findall(r'<tr>\s*<td>\s*((?:' + alt + r').*?)\s*</td>',
content, re.S|re.I)
if matches:
for item in matches:
# Split into items.
items = re.split(r'<br />\s*', item, flags=re.S|re.I)
if items:
for item in items:
# Remove tags.
item = re.sub('<.+?>', '', item)
# Add to list if not in the exclude list.
if item and item not in exclude:
properties.append(item + ' (-) [property]' + doc.get(item, ''))
return properties
if __name__ == '__main__':
# Set output path.
output = settings['output']
if not os.path.isdir(output):
os.makedirs(output)
# Read SciTEDoc.html.
file = os.path.join('scite', 'doc', 'SciTEDoc.html')
if not os.path.isfile(file):
exit('"' + file + '" not found')
with open(file) as r:
content = r.read()
# Remove leading classes to ensure matches in the next re pattern.
if settings['os_specific']:
classes = ['windowsonly', 'gtkonly', 'osxonly',
'windows-osx', 'windows-gtk']
platforms = [['win32', 'windows'],
['darwin', 'osx'],
['linux', 'gtk']]
for os_name, class_name in platforms:
if sys.platform.startswith(os_name):
print('specific to', class_name)
for item in classes:
if class_name in item:
content = re.sub(r'<tr\s+class="' + item + '"',
'<tr', content)
break
else:
print('specific to all')
content = re.sub(r'<tr\s+class=".+?"', '<tr', content)
else:
content = re.sub(r'<tr\s+class=".+?"', '<tr', content)
# Get the properties and the doc strings.
scitevariables = []
sciteproperties = []
current = {'tag': 'variable', 'list': scitevariables}
matches = re.findall(r'<tr\s+id=[\'"]property-.+?[\'"].*?>\s*'
r'<td>(.+?)</td>\s*<td>(.+?)</td>',
content, re.S|re.I)
if matches:
for item in matches:
# Properties can be multiple.
prop = item[0].split('<br />')
# Remove html tags.
prop = [re.sub('<.+?>', '', item).strip() for item in prop]
# Remove any empty items.
prop = [item for item in prop if item]
# Trim the doc string.
doc = item[1].strip()
# Replace html breaks with \\n.
doc = doc.replace('<br />', '\\n')
# Remove html tags.
doc = re.sub('<.+?>', '', doc)
# Replace tabs with spaces.
doc = re.sub('^\t+', ' ', doc, flags=re.M)
# Reduce spaces.
doc = re.sub('^ {2,}', ' ', doc, flags=re.M)
# Reduce lines.
doc = re.sub(r'^((?:.+?\n){10}).*', r'\1 ...', doc, flags=re.S)
# Replace \n with \\n.
doc = re.sub(r'(?<!\\n)\n', r'\\n', doc)
# Replace \n with ' '.
doc = doc.replace('\n', ' ')
# Change current tag and list once this property is found.
if prop[0].startswith('position.left'):
current = {'tag': 'property', 'list': sciteproperties}
for item in prop:
current['list'].append('{} (-) [{}]\\n {}'.format(item, current['tag'], doc))
# Get property items absent of an id attribute.
items = get_absent_property_items(content)
if items:
sciteproperties.extend(items)
sciteproperties.sort()
scitevariables.sort()
print('output:')
# Write to sciteproperties.api.
if sciteproperties:
print(' sciteproperties.api')
with open(os.path.join(output, 'sciteproperties.api'), 'w') as w:
for item in sciteproperties:
w.write(item + '\n')
# Write to scitevariables.api.
if scitevariables:
print(' scitevariables.api')
with open(os.path.join(output, 'scitevariables.api'), 'w') as w:
for item in scitevariables:
w.write(item + '\n')
print('done')