Better use of Python regex facilities.

This commit is contained in:
Chris Palmer 2020-12-30 09:48:46 +00:00
parent 8f2532d61b
commit 46937e403e
3 changed files with 3 additions and 7 deletions

View File

@ -51,7 +51,7 @@ def split_blurb(lines):
""" Split blurb on horizontal rules.""" """ Split blurb on horizontal rules."""
blurbs = [""] blurbs = [""]
for line in lines.split('\n')[:-1]: for line in lines.split('\n')[:-1]:
if re.match(r'\*\*\*\**',line): if re.match(r'\*{3,}',line):
blurbs.append("") blurbs.append("")
else: else:
blurbs[-1] += line + '\n' blurbs[-1] += line + '\n'

View File

@ -52,7 +52,7 @@ def gallery(force):
if os.path.isfile(document): if os.path.isfile(document):
with open(document, 'rt') as readme: with open(document, 'rt') as readme:
for line in readme.readlines(): for line in readme.readlines():
match = re.match(r"^.*!(\[.*\]\(.*\)).*$", line) match = re.search(r"!(\[.*\]\(.*\))", line)
if match: if match:
image = match.group(0) image = match.group(0)
if image.startswith('![Main Assembly](assemblies/'): if image.startswith('![Main Assembly](assemblies/'):

View File

@ -227,11 +227,7 @@ def views(target, do_assemblies = None):
# #
# Only add the image if the first blurb section doesn't contain one. # Only add the image if the first blurb section doesn't contain one.
# #
got_image = False if not re.search(r'\!\[.*\]\(.*\)', blurbs[0], re.MULTILINE):
for line in blurbs[0].split('\n'):
if re.match(r'.*\!\[.*\]\(.*\).*', line):
got_image = True
if not got_image:
print('![Main Assembly](assemblies/%s.png)\n' % flat_bom[-1]["name"].replace('_assembly', '_assembled'), file = doc_file) print('![Main Assembly](assemblies/%s.png)\n' % flat_bom[-1]["name"].replace('_assembly', '_assembled'), file = doc_file)
eop(print_mode, doc_file, first = True) eop(print_mode, doc_file, first = True)
# #