diff --git a/src/zona/markdown.py b/src/zona/markdown.py index c5a83d4..1132f22 100644 --- a/src/zona/markdown.py +++ b/src/zona/markdown.py @@ -118,16 +118,26 @@ class ZonaLinkTreeprocessor(Treeprocessor): else: # treat as relative link and try to resolve resolved = (self.source.parent / cur).resolve() + # check if the link is internal + internal = same_file + if not same_file: + for suffix in {".md", ".html"}: + if resolved.with_suffix(suffix).exists(): + internal = True + resolved = resolved.with_suffix(suffix) + break # only substitute if link points to an actual file # that isn't the self file - if not same_file and resolved.exists(): + if not same_file and internal: item = self.item_map.get(resolved) if item: href = util.normalize_url(item.url) - element.set("href", href) - self.logger.debug( - f"Link in file {self.source}: {_href} resolved to {href}" - ) + # don't sub if it's already correct lol + if _href != href: + element.set("href", href) + self.logger.debug( + f"Link in file {self.source}: {_href} resolved to {href}" + ) else: self.logger.debug( f"Warning: resolved path {resolved} not found in item map"