doc/docchecker
changeset 27730 ed86fb2a4187
child 27733 3d1baa702d1a
equal deleted inserted replaced
27729:58f8b29c37ff 27730:ed86fb2a4187
       
     1 #!/usr/bin/env python
       
     2 #
       
     3 # docchecker - look for problematic markup
       
     4 #
       
     5 # Copyright 2016 timeless <timeless@mozdev.org> and others
       
     6 #
       
     7 # This software may be used and distributed according to the terms of the
       
     8 # GNU General Public License version 2 or any later version.
       
     9 import sys
       
    10 import re
       
    11 
       
    12 leadingline = re.compile(r'(^\s*)(\S.*)$')
       
    13 hg_backtick = re.compile(r""":hg:`[^`]*'[^`]*`""")
       
    14 
       
    15 def check(line):
       
    16   if hg_backtick.search(line):
       
    17     print(line)
       
    18     print("""warning: please avoid nesting ' in :hg:`...`""")
       
    19 
       
    20 def work(file):
       
    21   (llead, lline) = ('', '')
       
    22 
       
    23   for line in file:
       
    24     # this section unwraps lines
       
    25     match = leadingline.match(line)
       
    26     if not match:
       
    27       check(lline)
       
    28       (llead, lline) = ('', '')
       
    29       continue
       
    30 
       
    31     lead, line = match.group(1), match.group(2)
       
    32     if (lead == llead):
       
    33       if (lline != ''):
       
    34         lline += ' ' + line
       
    35       else:
       
    36         lline = line
       
    37     else:
       
    38       check(lline)
       
    39       (llead, lline) = (lead, line)
       
    40   check(lline)
       
    41 
       
    42 def main():
       
    43   for f in sys.argv[1:]:
       
    44     try:
       
    45       with open(f) as file:
       
    46         work(file)
       
    47     except:
       
    48       print("failed to process %s" % f)
       
    49 
       
    50 main()