author | Gregory Szorc <gregory.szorc@gmail.com> |
Sat, 27 Feb 2016 21:11:24 -0800 | |
changeset 28398 | 712298942c82 |
parent 28049 | c00f67c15c5a |
child 28810 | 9934362978e1 |
permissions | -rwxr-xr-x |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
2 |
# |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
3 |
# docchecker - look for problematic markup |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
4 |
# |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
5 |
# Copyright 2016 timeless <timeless@mozdev.org> and others |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
6 |
# |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
8 |
# GNU General Public License version 2 or any later version. |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
9 |
import sys |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
10 |
import re |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
11 |
|
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
12 |
leadingline = re.compile(r'(^\s*)(\S.*)$') |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
13 |
hg_backtick = re.compile(r""":hg:`[^`]*'[^`]*`""") |
27733
3d1baa702d1a
docchecker: scan for missing space before :hg:
timeless <timeless@mozdev.org>
parents:
27730
diff
changeset
|
14 |
hg_cramped = re.compile(r'\w:hg:`') |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
15 |
|
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
16 |
def check(line): |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
17 |
if hg_backtick.search(line): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
18 |
print(line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
19 |
print("""warning: please avoid nesting ' in :hg:`...`""") |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
20 |
if hg_cramped.search(line): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
21 |
print(line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
22 |
print('warning: please have a space before :hg:') |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
23 |
|
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
24 |
def work(file): |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
25 |
(llead, lline) = ('', '') |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
26 |
|
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
27 |
for line in file: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
28 |
# this section unwraps lines |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
29 |
match = leadingline.match(line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
30 |
if not match: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
31 |
check(lline) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
32 |
(llead, lline) = ('', '') |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
33 |
continue |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
34 |
|
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
35 |
lead, line = match.group(1), match.group(2) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
36 |
if (lead == llead): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
37 |
if (lline != ''): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
38 |
lline += ' ' + line |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
39 |
else: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
40 |
lline = line |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
41 |
else: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
42 |
check(lline) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
43 |
(llead, lline) = (lead, line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
44 |
check(lline) |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
45 |
|
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
46 |
def main(): |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
47 |
for f in sys.argv[1:]: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
48 |
try: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
49 |
with open(f) as file: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
50 |
work(file) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
51 |
except BaseException as e: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
52 |
print("failed to process %s: %s" % (f, e)) |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
53 |
|
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
54 |
main() |