网天下信息技术有限公司网站成都网站seo收费标准
web/
2025/10/1 21:20:26/
文章来源:
网天下信息技术有限公司网站,成都网站seo收费标准,大型门户网站建设需要哪些技术,龙华区民治街道城市更新一、背景 当我们使用Joplin时#xff0c;上传图片时会自动上传到Joplin服务器并替换链接 但是Joplin的编辑器不好用#xff0c;我更习惯用Typora来编辑#xff0c; 然而Typora中上传的图片只能在本地#xff0c;无法上传到Joplin服务器#xff0c;在其他客户端也看不到图片…一、背景 当我们使用Joplin时上传图片时会自动上传到Joplin服务器并替换链接 但是Joplin的编辑器不好用我更习惯用Typora来编辑 然而Typora中上传的图片只能在本地无法上传到Joplin服务器在其他客户端也看不到图片 本文编写了一个脚本通过Typora的上传服务器功能自动上传图片并替换为Joplin链接 二、准备脚本
2.1 第一个脚本修改token
token可以在网页剪藏器中获取 import requests
import sys
import json
import subprocess# 修改为你的token
token 请修改我
# WARNING: replace 41184 with your joplin web clipper port
port 41184
# 修改为你的python路径
python_exe_path rC:\Users\realw\AppData\Local\Microsoft\WindowsApps\python.exe
# 修改为你的第二个脚本路径
second_script_path rD:\app\Typora\job\typora-windows-2.py# collect args for typora-windows-2.py
args []
for arg in sys.argv:# the first arg is .py file, ignore itif(.py in arg):continue# the second arg is the current editing file passed by Typoraif(.md in arg):args.append(arg)continue# other arg is the local Typora-Image path passed by Typoraurl http://127.0.0.1: str(port) /resources/?token tokenpayload {props: {}}files [(data, (typora.png, open(arg, rb), image/png))]headers {}# upload your images to joplin resources using joplin web clipper APIresponse requests.request(POST, url, headersheaders, datapayload, filesfiles)newFilePath http://127.0.0.1: str(port) /resources/ json.loads(response.text)[id] /file?token token# print newFilePath, so Typora can replace the local-typora-image path with the joplin web clipper url.# We cannot directly use resources/ json.loads(response.text)[id] .png since Typora thinks it is an illegal URL,# and a warning will show up.print(newFilePath)args.append(newFilePath)args.append(resources/ json.loads(response.text)[id] .png)# first arg is .py file, second arg is .md file, then newFilePath and resources/ json.loads(response.text)[id] .png appear in order
# We use subprocess because Typora will wait for the result of the first script and then replace the Typora_local_path with newFilePath.
# If we dont use subprocess, our replacement will be ahead of Typoras, and covered by Typora, which makes newFilePath as the final result link.
# This is not what we want, we want resources/ json.loads(response.text)[id] .png as the result.
subprocess.Popen([python_exe_path, second_script_path] args, creationflagssubprocess.DETACHED_PROCESS, shellFalse)sys.exit()
2.1 准备第二个脚本按需修改delay时间
import sys
import time# We need to wait Typoras replacement happens first
delay_time 5# Typora 将 typora-local-image-link 替换为 web-clipper-link 后
# 而您没有按“ctrl s”保存您的内容不会“提交”到当前文件
# 这使得 python 无法检测到 web-clipper-link 并将其替换为 joplin-resources-link。
# 因此我们至少重试该函数 10 次以等待您的保存。如果您在 50 秒内没有按“ctrl s”保存则替换将失败
retry_times 10
time.sleep(delay_time)for i in range(retry_times):try:with open(sys.argv[1], r, encodingutf-8) as file:file_content file.read()file_content_copy file_contentfor index, arg in enumerate(sys.argv):if ((.png in arg) or (.md in arg) or (.py in arg)):continue# replace newFilePath with resources/{id}.pngfile_content file_content.replace(sys.argv[index], sys.argv[index 1])file.seek(0)file.write(file_content)file.truncate()time.sleep(delay_time)except Exception as e:print(fAn error occurred: {e})time.sleep(delay_time)
sys.exit()
3. 修改Typora配置 选择图象上传服务命令确保你的python环境和模块正确
python D:\app\Typora\job\typora-windows.py ${filepath}点击验证图片上传
4 在编辑器内测试
用法 在编辑器内粘贴图片按下ctrls 保存等待几秒后自动替换为内部连接大公告成 如果遇到问题可以手动点击上传图片检查顶部报错
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/85258.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!