Skip to content

Commit

Permalink
修复正则替换Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Polaris-F committed Aug 29, 2024
1 parent 232f6c2 commit a9da15e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CopyReplace/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

[Settings]

#replace_url = "https://polaris-f.github.io/Link2Zotero/#zotero://"
replace_url = "https://flaribbit.github.io/zotero-link/#zotero://"
replace_url = "https://polaris-f.github.io/Link2Zotero/#zotero://"
#replace_url = "https://flaribbit.github.io/zotero-link/#zotero://"
icon_path = "D:/Github/Tools/Link2Zotero/dist/Link2Zotero_2.ico"
7 changes: 4 additions & 3 deletions CopyReplace/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# 使用 RawConfigParser 读取配置文件,保留原始字符串格式
config = configparser.RawConfigParser()
config.read(r'config.ini')
replace_url = config.get('Settings', 'replace_url').strip('"')
# 将 replace_url 设置为你的目标前缀
replace_url = "https://polaris-f.github.io/Link2Zotero/#"
icon_path = Path(config.get('Settings', 'icon_path').strip('"'))

# 检查系统类型并导入相应的通知库
Expand Down Expand Up @@ -49,8 +50,8 @@ def process(clip_text: str) -> (str, int): # type: ignore
pattern = r'(?<!#)(zotero://[^\s]+)'
# 统计匹配到的链接数量
link_count = len(re.findall(pattern, clip_text))
# 替换匹配到的链接
new_text = re.sub(pattern, replace_url, clip_text)
# 替换匹配到的链接,加上指定的前缀
new_text = re.sub(pattern, lambda m: f"{replace_url}{m.group(0)}", clip_text)
return new_text, link_count

# 剪贴板监控主函数
Expand Down
4 changes: 2 additions & 2 deletions dist/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

[Settings]

#replace_url = "https://polaris-f.github.io/Link2Zotero/#zotero://"
replace_url = "https://flaribbit.github.io/zotero-link/#zotero://"
replace_url = "https://polaris-f.github.io/Link2Zotero/#zotero://"
#replace_url = "https://flaribbit.github.io/zotero-link/#zotero://"
icon_path = "D:/Github/Tools/Link2Zotero/dist/Link2Zotero_2.ico"

0 comments on commit a9da15e

Please sign in to comment.