From 9ccf0e8fd4ca27583eb01a7facec36b45d5880bd Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Fri, 11 Oct 2024 16:43:11 -0400 Subject: [PATCH] chore(weave): Fix image docgen #2678 --- docs/scripts/generate_notebooks.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/scripts/generate_notebooks.py b/docs/scripts/generate_notebooks.py index af4bed31d36..b28fe8a9984 100644 --- a/docs/scripts/generate_notebooks.py +++ b/docs/scripts/generate_notebooks.py @@ -1,4 +1,5 @@ import os +import re import tempfile import nbformat @@ -63,6 +64,23 @@ def export_notebook(notebook_path, output_path): output = extract_meta + make_header(notebook_path) + output + # Fixes image paths by replacing markdown links containing '../docs/' with '/docs/' + pattern = re.compile( + r""" + \( + ( + \.\./docs/ + .*? + ) + \) + """, + re.VERBOSE, + ) + + replacement = r"(/\1)" + + output = pattern.sub(replacement, output) + with open(output_path, "w") as f: f.write(output)