diff --git a/content.py b/content.py
index a2587f0..79263ce 100644
--- a/content.py
+++ b/content.py
@@ -169,6 +169,59 @@ def extract_forums(id, course_folder, item_id_to_index, verbose=0, discussion_li
#
# Download everything interesting in a course to a local folder
# Build a master file with the entire class content
+# Adjust image paths in aggregated snippets so they work from the course root.
+def adjust_fullcourse_image_sources(html_fragment):
+ if not html_fragment:
+ return html_fragment
+
+ def _prefix_images(match):
+ prefix = match.group(1)
+ path = match.group(2)
+ normalized = path.lstrip('./')
+ if normalized.lower().startswith('pages/'):
+ return f"{prefix}{normalized}"
+ return f"{prefix}pages/{normalized}"
+
+ src_pattern = re.compile(r'(]+?\bsrc\s*=\s*[\'"])(?:\./)?(images/[^\'"]*)', re.IGNORECASE)
+ html_fragment = src_pattern.sub(_prefix_images, html_fragment)
+
+ canvas_pattern = re.compile(r'(
]+?\bdata-canvas-src\s*=\s*[\'"])(?:\./)?(images/[^\'"]*)', re.IGNORECASE)
+ html_fragment = canvas_pattern.sub(_prefix_images, html_fragment)
+
+ srcset_pattern = re.compile(r'(
]+?\bsrcset\s*=\s*[\'"])([^\'"]*)([\'"])', re.IGNORECASE | re.DOTALL)
+
+ def _prefix_srcset(match):
+ prefix = match.group(1)
+ value = match.group(2)
+ suffix = match.group(3)
+ entries = []
+ changed = False
+ for chunk in value.split(','):
+ chunk = chunk.strip()
+ if not chunk:
+ continue
+ parts = chunk.split()
+ url = parts[0]
+ descriptors = parts[1:]
+ normalized = url.lstrip('./')
+ if normalized.lower().startswith('pages/'):
+ new_url = url
+ elif normalized.lower().startswith('images/'):
+ new_url = f"pages/{normalized}"
+ changed = True
+ else:
+ new_url = url
+ descriptor_text = ' '.join(descriptors)
+ entry = f"{new_url} {descriptor_text}".strip()
+ entries.append(entry)
+ if not changed:
+ return match.group(0)
+ return f"{prefix}{', '.join(entries)}{suffix}"
+
+ html_fragment = srcset_pattern.sub(_prefix_srcset, html_fragment)
+
+ return html_fragment
+
def course_download(id=""):
global items
@@ -203,6 +256,7 @@ def course_download(id=""):
file_local_map = {}
discussion_local_map = {}
module_details = []
+ canvas_host = urlparse(url).hostname if url else None
for m in modules:
items[running_index] = '