syntax highlighting for everyone!

This commit is contained in:
Mark Pilgrim
2009-06-08 12:44:13 -04:00
parent 672132a1d3
commit ae146df0d9
27 changed files with 2621 additions and 1151 deletions
+10 -2
View File
@@ -4,12 +4,20 @@ from pyquery import PyQuery as pq
import glob
import sys
# These selectors are kept regardless of whether this script thinks they are used.
# Most of these match nodes that are dynamically inserted or manipulated by script
# after the page has loaded, which is why a static analysis thinks they're unused.
SELECTOR_EXCEPTIONS = ('.w', '.b', '.str', '.kwd', '.com', '.typ', '.lit', '.pun', '.tag', '.atn', '.atv', '.dec', 'pre span.u', 'pre span.u span')
filename = sys.argv[1]
pqd = pq(filename=filename)
raw_data = open(filename, 'rb').read()
if raw_data.count('<pre><code>') or raw_data.count('<pre class=screen>'):
if raw_data.count('<pre><code') or raw_data.count('<pre class=screen>'):
def keep(s):
return s == '.w' or s.startswith('.w ') or s == '.b' or s.startswith('.b ')
for selector in SELECTOR_EXCEPTIONS:
if s == selector: return True
if s.startswith(selector + ' '): return True
return False
else:
def keep(s):
return False