@@ -4525,23 +4525,33 @@ def save_as_html(
4525
4525
4526
4526
with open (filename , "w" , encoding = "utf-8" ) as fw :
4527
4527
fw .write (html_out )
4528
-
4528
+
4529
4529
def _get_output_paths (
4530
4530
self , filename : Union [str , Path ], artifacts_dir : Optional [Path ] = None
4531
4531
) -> 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
+ """
4532
4538
if isinstance (filename , str ):
4533
4539
filename = Path (filename )
4534
4540
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 ():
4539
4551
reference_path = None
4540
4552
else :
4541
4553
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
4545
4555
4546
4556
def _make_copy_with_refmode (
4547
4557
self ,
0 commit comments