Better use of Python regex facilities.
This commit is contained in:
parent
8f2532d61b
commit
46937e403e
|
@ -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'
|
||||||
|
|
|
@ -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/'):
|
||||||
|
|
|
@ -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)
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue