diff --git a/sphinxcontrib/jupyter/writers/translate_all.py b/sphinxcontrib/jupyter/writers/translate_all.py index 0ab9e34a..bd2a7b9f 100644 --- a/sphinxcontrib/jupyter/writers/translate_all.py +++ b/sphinxcontrib/jupyter/writers/translate_all.py @@ -177,9 +177,17 @@ def visit_image(self, node): self.images.append(uri) #TODO: list of image files if self.jupyter_download_nb_image_urlpath: for file_path in self.jupyter_static_file_path: - if file_path in uri: - uri = uri.replace(file_path +"/", self.jupyter_download_nb_image_urlpath) - break #don't need to check other matches + #Adjust Relative References + if "../" in uri: + uri = uri.replace("../","") + #If the root path "/" is specified in RST URI then only the name of the source directory will be needed for substitution + if "/" in file_path and uri.split("/")[0] == file_path.split("/")[-1]: + uri = uri.replace(file_path.split("/")[-1]+"/", self.jupyter_download_nb_image_urlpath) + break + #Otherwise full file_path needs to be replaced + else: + uri = uri.replace(file_path+"/", self.jupyter_download_nb_image_urlpath) + break attrs = node.attributes if self.jupyter_images_markdown: #-Construct MD image diff --git a/sphinxcontrib/jupyter/writers/translate_code.py b/sphinxcontrib/jupyter/writers/translate_code.py index 259fc28a..a31fe438 100644 --- a/sphinxcontrib/jupyter/writers/translate_code.py +++ b/sphinxcontrib/jupyter/writers/translate_code.py @@ -44,10 +44,12 @@ def __init__(self, builder, document): self.jupyter_ignore_skip_test = builder.config["jupyter_ignore_skip_test"] self.jupyter_lang_synonyms = builder.config["jupyter_lang_synonyms"] self.jupyter_target_html = builder.config["jupyter_target_html"] - self.jupyter_download_nb_image_urlpath = builder.jupyter_download_nb_image_urlpath self.jupyter_images_markdown = builder.config["jupyter_images_markdown"] self.jupyter_target_pdf = builder.config["jupyter_target_pdf"] + # Non global variables set in builder + self.jupyter_download_nb_image_urlpath = builder.jupyter_download_nb_image_urlpath + # set the value of the cell metadata["slideshow"] to slide as the default option self.slide = "slide" self.metadata_slide = False #value by default for all the notebooks, we change it for those we want