-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
69 lines (54 loc) · 2.06 KB
/
script.py
File metadata and controls
69 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# # fix_typora_link_real.py
# import sys
# import os
# import re
# from urllib.parse import unquote
# def fix_links(file_path):
# if not os.path.isfile(file_path):
# print("❗ 파일을 찾을 수 없습니다:", file_path)
# return
# with open(file_path, 'r', encoding='utf-8') as file:
# content = file.read()
# # 정규식으로 URL만 찾아서 디코딩
# # (전체 텍스트를 디코딩하면 안 돼, 링크만 디코딩해야 돼)
# def decode_url(match):
# url = match.group(0)
# return unquote(url)
# # Markdown 링크 형태에서 URL만 찾아서 디코딩
# fixed_content = re.sub(r'https?://[^\s\)\]]+', decode_url, content)
# with open(file_path, 'w', encoding='utf-8') as file:
# file.write(fixed_content)
# print(f"✅ 링크 수정 완료: {file_path}")
# if __name__ == "__main__":
# if len(sys.argv) != 2:
# print("사용법: python fix_typora_link_real.py [수정할 .md 파일 경로]")
# else:
# file_path = sys.argv[1]
# fix_links(file_path)
# fix_typora_link_real_fixed.py
import sys
import os
import re
from urllib.parse import unquote
def fix_links(file_path):
if not os.path.isfile(file_path):
print("❗ 파일을 찾을 수 없습니다:", file_path)
return
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# 마크다운 링크 형태 [텍스트](URL) 찾아서
def decode_url(match):
full_match = match.group(0)
url = match.group(1)
decoded_url = unquote(url)
return full_match.replace(url, decoded_url)
fixed_content = re.sub(r'\[[^\]]*\]\((https?://[^\)]+)\)', decode_url, content)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(fixed_content)
print(f"✅ 링크 수정 완료: {file_path}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("사용법: python fix_typora_link_real_fixed.py [수정할 .md 파일 경로]")
else:
file_path = sys.argv[1]
fix_links(file_path)