Show More
@@ -1,54 +1,61 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # |
|
3 | 3 | # docchecker - look for problematic markup |
|
4 | 4 | # |
|
5 | 5 | # Copyright 2016 timeless <timeless@mozdev.org> and others |
|
6 | 6 | # |
|
7 | 7 | # This software may be used and distributed according to the terms of the |
|
8 | 8 | # GNU General Public License version 2 or any later version. |
|
9 | 9 | import sys |
|
10 | 10 | import re |
|
11 | 11 | |
|
12 | 12 | leadingline = re.compile(r'(^\s*)(\S.*)$') |
|
13 | hg_backtick = re.compile(r""":hg:`[^`]*'[^`]*`""") | |
|
14 | hg_cramped = re.compile(r'\w:hg:`') | |
|
13 | ||
|
14 | checks = [ | |
|
15 | (r""":hg:`[^`]*'[^`]*`""", | |
|
16 | """warning: please avoid nesting ' in :hg:`...`"""), | |
|
17 | (r'\w:hg:`', | |
|
18 | 'warning: please have a space before :hg:'), | |
|
19 | ] | |
|
15 | 20 | |
|
16 | 21 | def check(line): |
|
17 | if hg_backtick.search(line): | |
|
22 | messages = [] | |
|
23 | for match, msg in checks: | |
|
24 | if re.search(match, line): | |
|
25 | messages.append(msg) | |
|
26 | if messages: | |
|
18 | 27 | print(line) |
|
19 | print("""warning: please avoid nesting ' in :hg:`...`""") | |
|
20 | if hg_cramped.search(line): | |
|
21 | print(line) | |
|
22 | print('warning: please have a space before :hg:') | |
|
28 | for msg in messages: | |
|
29 | print(msg) | |
|
23 | 30 | |
|
24 | 31 | def work(file): |
|
25 | 32 | (llead, lline) = ('', '') |
|
26 | 33 | |
|
27 | 34 | for line in file: |
|
28 | 35 | # this section unwraps lines |
|
29 | 36 | match = leadingline.match(line) |
|
30 | 37 | if not match: |
|
31 | 38 | check(lline) |
|
32 | 39 | (llead, lline) = ('', '') |
|
33 | 40 | continue |
|
34 | 41 | |
|
35 | 42 | lead, line = match.group(1), match.group(2) |
|
36 | 43 | if (lead == llead): |
|
37 | 44 | if (lline != ''): |
|
38 | 45 | lline += ' ' + line |
|
39 | 46 | else: |
|
40 | 47 | lline = line |
|
41 | 48 | else: |
|
42 | 49 | check(lline) |
|
43 | 50 | (llead, lline) = (lead, line) |
|
44 | 51 | check(lline) |
|
45 | 52 | |
|
46 | 53 | def main(): |
|
47 | 54 | for f in sys.argv[1:]: |
|
48 | 55 | try: |
|
49 | 56 | with open(f) as file: |
|
50 | 57 | work(file) |
|
51 | 58 | except BaseException as e: |
|
52 | 59 | print("failed to process %s: %s" % (f, e)) |
|
53 | 60 | |
|
54 | 61 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now