Skip to content

Commit

Permalink
build: Fix basic gallery build issues for Markdown (OSGeo#5247)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
wenzeslaus authored Mar 3, 2025
1 parent e802e90 commit 30aa63d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions man/build_manual_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def img_in_file(filename: str | os.PathLike[str], imagename: str, ext: str) -> b
pattern = re.compile("<img .*src=.{0}.*>".format(imagename))
else:
# expecting markdown
pattern = re.compile(r"!\[(.*?)\]\({0}\)".format(imagename))
pattern = re.compile(r"\]\({0}\)".format(imagename))
return bool(re.search(pattern, Path(filename).read_text()))


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

with open(Path(man_dir, output_name), "w") as output:
output.write(
header1_tmpl.substitute(
title="GRASS GIS %s Reference Manual: Manual gallery" % grass_version
)
)
if ext == "html":
title = "GRASS GIS %s Reference Manual: Manual gallery" % grass_version
else:
title = "Manual gallery"
output.write(header1_tmpl.substitute(title=title))
if ext == "html":
output.write(header_graphical_index_tmpl)
output.write('<ul class="img-list">\n')
Expand All @@ -197,7 +198,7 @@ def main(ext):
output.write(f'[![{name}]({image} "{title}")]({filename})\n')
if ext == "html":
output.write("</ul>")
write_footer(output, f"index.{ext}", year)
write_footer(output, f"index.{ext}", year, template=ext)

return img_files

Expand Down

0 comments on commit 30aa63d

Please sign in to comment.