From 17f56ef2429539aa9aa5eb4be0496199eef94483 Mon Sep 17 00:00:00 2001 From: xunbu Date: Thu, 3 Jul 2025 17:52:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8md5=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E5=9B=BE=E7=89=87id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docutranslate/utils/markdown_utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docutranslate/utils/markdown_utils.py b/docutranslate/utils/markdown_utils.py index c85ef6d..1d7d4cc 100644 --- a/docutranslate/utils/markdown_utils.py +++ b/docutranslate/utils/markdown_utils.py @@ -1,4 +1,5 @@ import base64 +import hashlib import io import mimetypes import os @@ -187,7 +188,7 @@ def unembed_base64_images_to_zip(markdown:str,markdown_name:str,image_folder_nam def unembed_base64_images(match:re.Match)->str: b64data = match.group(3) extension=mimetypes.guess_extension(match.group(2)) - image_id=uuid.uuid1().hex[:8] + image_id=hashlib.md5(b64data.encode()).hexdigest()[:8] image_name=f"{image_id}{extension}" url=f"./{image_folder_name}/{image_name}" #创建对应的image文件 @@ -217,7 +218,5 @@ def clean_markdown_math_block(markdown): if __name__ == '__main__': - with open(r"C:\Users\jxgm\Desktop\translate\docutranslate\tests\files\test7.md",'r') as f: - markdown=f.read() - print(unembed_base64_images_to_zip(markdown,"markdown.md")) + pass