Skip to content

Commit 30aa63d

Browse files
authored
build: Fix basic gallery build issues for Markdown (#5247)
This fixes build of header and footer by avoiding YAML syntax issue in title (colon) and writing of HTML footer. It also does multiline matching for the image capture which results in capturing (presumably) all images in the Markdown docs. Less complete, but much faster expression. We are not capturing the alt, only testing the image presence, so we take the assumption that closing square bracket and image name in parentheses is a link. This avoids costly multiline matching with dot (from 1.5min back to original 30sec), while still capturing the multiline images (by ignoring their multiline alts).
1 parent e802e90 commit 30aa63d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

man/build_manual_gallery.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def img_in_file(filename: str | os.PathLike[str], imagename: str, ext: str) -> b
100100
pattern = re.compile("<img .*src=.{0}.*>".format(imagename))
101101
else:
102102
# expecting markdown
103-
pattern = re.compile(r"!\[(.*?)\]\({0}\)".format(imagename))
103+
pattern = re.compile(r"\]\({0}\)".format(imagename))
104104
return bool(re.search(pattern, Path(filename).read_text()))
105105

106106

@@ -171,13 +171,14 @@ def main(ext):
171171
if img_in_file(Path(man_dir, man_filename), filename, ext):
172172
img_files[filename] = man_filename
173173
# for now suppose one image per manual filename
174+
continue
174175

175176
with open(Path(man_dir, output_name), "w") as output:
176-
output.write(
177-
header1_tmpl.substitute(
178-
title="GRASS GIS %s Reference Manual: Manual gallery" % grass_version
179-
)
180-
)
177+
if ext == "html":
178+
title = "GRASS GIS %s Reference Manual: Manual gallery" % grass_version
179+
else:
180+
title = "Manual gallery"
181+
output.write(header1_tmpl.substitute(title=title))
181182
if ext == "html":
182183
output.write(header_graphical_index_tmpl)
183184
output.write('<ul class="img-list">\n')
@@ -197,7 +198,7 @@ def main(ext):
197198
output.write(f'[![{name}]({image} "{title}")]({filename})\n')
198199
if ext == "html":
199200
output.write("</ul>")
200-
write_footer(output, f"index.{ext}", year)
201+
write_footer(output, f"index.{ext}", year, template=ext)
201202

202203
return img_files
203204

0 commit comments

Comments
 (0)