@@ -4525,23 +4525,33 @@ def save_as_html(
45254525
45264526 with open (filename , "w" , encoding = "utf-8" ) as fw :
45274527 fw .write (html_out )
4528-
4528+
45294529 def _get_output_paths (
45304530 self , filename : Union [str , Path ], artifacts_dir : Optional [Path ] = None
45314531 ) -> Tuple [Path , Optional [Path ]]:
4532+ """
4533+ Determines the output directory for artifacts and the reference path for URIs.
4534+
4535+ This function correctly handles absolute and relative paths for `filename`
4536+ and `artifacts_dir` without path duplication.
4537+ """
45324538 if isinstance (filename , str ):
45334539 filename = Path (filename )
45344540 if artifacts_dir is None :
4535- # Remove the extension and add '_pictures'
4536- artifacts_dir = filename .with_suffix ("" )
4537- artifacts_dir = artifacts_dir .with_name (artifacts_dir .name + "_artifacts" )
4538- if artifacts_dir .is_absolute ():
4541+ # Default case: create an '_artifacts' directory alongside the file.
4542+ final_artifacts_dir = filename .with_name (filename .stem + "_artifacts" )
4543+ else :
4544+ if isinstance (artifacts_dir , str ):
4545+ artifacts_dir = Path (artifacts_dir )
4546+ if artifacts_dir .is_absolute ():
4547+ final_artifacts_dir = artifacts_dir
4548+ else :
4549+ final_artifacts_dir = filename .parent / artifacts_dir
4550+ if final_artifacts_dir .is_absolute ():
45394551 reference_path = None
45404552 else :
45414553 reference_path = filename .parent
4542- artifacts_dir = reference_path / artifacts_dir
4543-
4544- return artifacts_dir , reference_path
4554+ return final_artifacts_dir , reference_path
45454555
45464556 def _make_copy_with_refmode (
45474557 self ,
0 commit comments