Skip to content

Commit 6c4c254

Browse files
Merge pull request #8 from LangChain-OpenTutorial/soo-dev
⚡️ Add a function to create a file in the docs folder.
2 parents ba2294c + ec67a58 commit 6c4c254

8 files changed

+728
-6
lines changed

markdown_generator/mdconverter_class.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import re
33
import shutil
4-
from mdconverter.mdconverter import get_default_css
4+
from .mdconverter import get_default_css
55
from nbconvert import MarkdownExporter
66
from nbconvert.preprocessors import Preprocessor
77
import nbformat
@@ -66,7 +66,9 @@ def _add_prefix_css(self) -> str:
6666

6767
def _save_script(self) -> None:
6868
"""Save the converted script"""
69-
output_filename = self.filename.replace(".ipynb", f"{self.post_fix}.md")
69+
output_filename = os.path.join(
70+
"./docs", self.filename.replace(".ipynb", f"{self.post_fix}.md")
71+
)
7072
print(f"Saving file : {output_filename}")
7173
with open(output_filename, "w", encoding="utf-8") as f:
7274
f.write(self.ndconverter_script)
@@ -107,20 +109,21 @@ def _setup_image_processing(self) -> None:
107109
self._extracting_img_path()
108110
if self.resources.get("outputs"):
109111
self._process_output_images()
112+
self._process_markdown_images_pattern()
110113

111114
def _extracting_img_path(self) -> None:
112115
"""Set image directory path"""
113116
folder_name = os.path.dirname(self.filename)
114-
self.img_dir = os.path.join(folder_name, "img")
117+
self.img_dir = os.path.join("./docs", folder_name, "img")
115118
os.makedirs(self.img_dir, exist_ok=True)
116-
print(f"Setting image dir : {self.img_dir}")
119+
print(f"Making image dir : {self.img_dir}")
117120

118121
def _process_output_images(self) -> None:
119122
"""Save image files and update paths"""
120123
for img_filename, image_data in self.resources["outputs"].items():
121124
img_path = os.path.join(self.img_dir, img_filename)
122125
self._save_image(img_path, image_data)
123-
self._update_image_path(img_filename, img_path)
126+
self._update_image_path(img_filename, f"./img/{img_filename}")
124127

125128
def _save_image(self, img_path: str, image_data: bytes) -> None:
126129
"""Save image file"""
@@ -161,7 +164,7 @@ def _process_markdown_image(self, desc: str, old_path: str) -> None:
161164

162165
if os.path.exists(abs_old_path):
163166
shutil.copy2(abs_old_path, new_path)
164-
self._update_markdown_image_path(desc, old_path, new_path)
167+
self._update_markdown_image_path(desc, old_path, f"./img/{filename}")
165168

166169
def _get_absolute_path(self, old_path: str) -> str:
167170
"""Convert relative path to absolute path"""

0 commit comments

Comments
 (0)