miracleyoo / Markdown4Zhihu

一键解决知乎导入Markdown文件时图片和公式等问题。
85 stars 186 forks source link

运行出现错误 #1

Open q1anzhen opened 4 years ago

q1anzhen commented 4 years ago

你好,十分感谢你贡献的工具,我认为这是一个非常好的工具。 我使用电脑尝试转化我自己的一个markdown文件时,出现了这样的问题,不知道如何debug,如果有时间,可以看看,非常感谢! python3 zhihu-publisher.py --input="./Data/droplet.md" {'encoding': None, 'confidence': 0.0, 'language': None} Traceback (most recent call last): File "zhihu-publisher.py", line 123, in <module> process_for_zhihu() File "zhihu-publisher.py", line 35, in process_for_zhihu lines = image_ops(lines) File "zhihu-publisher.py", line 73, in image_ops _lines = re.sub(r'<img src="(.*?)"',functools.partial(rename_image_ref, original=False), _lines) File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count) File "zhihu-publisher.py", line 50, in rename_image_ref if os.path.getsize(image_folder_path.parent/m.group(1+int(original)))>COMPRESS_THRESHOLD: File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/genericpath.py", line 50, in getsize return os.stat(filename).st_size FileNotFoundError: [Errno 2] No such file or directory: 'Data/https:/www.zhihu.com/equation?tex=G'

miracleyoo commented 4 years ago

请问您方便把您在转换的droplet.md文件邮箱传一份吗?根据错误信息来看应该是某个公式被错误解析了,具体需要看文件内容而定。若有隐私顾虑,您可以将文件文字内容全部换成随机字符。谢谢!

q1anzhen commented 4 years ago

你好,我觉得不是我自己markdown的问题,因为我测试你Data里的测试文档,也是有同样的问题。 $ python3 zhihu-publisher.py --input="./Data/一个测试文档.md" {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''} Traceback (most recent call last): File "zhihu-publisher.py", line 123, in <module> process_for_zhihu() File "zhihu-publisher.py", line 35, in process_for_zhihu lines = image_ops(lines) File "zhihu-publisher.py", line 73, in image_ops _lines = re.sub(r'<img src="(.*?)"',functools.partial(rename_image_ref, original=False), _lines) File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count) File "zhihu-publisher.py", line 50, in rename_image_ref if os.path.getsize(image_folder_path.parent/m.group(1+int(original)))>COMPRESS_THRESHOLD: File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/genericpath.py", line 50, in getsize return os.stat(filename).st_size FileNotFoundError: [Errno 2] No such file or directory: 'Data/https:/www.zhihu.com/equation?tex=Sum=\\sum_{i=0}^{n}{\\sqrt{x_i^2+y_i^2}}' 不知道是不是我python版本的问题。

miracleyoo commented 4 years ago

是我这边的问题。之前更新了一个模块功能但是会对链接式图片不兼容。刚才修复了这个问题,您可以再试试看。

q1anzhen commented 4 years ago

感谢你的更新,现在可以成功执行了。 我还是有一个问题和建议:

  1. 现在成功执行了后,也自动把相应的图片上传至Github/Data,但是在知乎编辑器里,它不能访问,显示是上传失败,也没有重新上传的按钮,我试了你的测试文档也有这样的问题。(不过图片重新上传一下倒是不累....)

  2. 我觉得现在产生知乎公式的格式可能有点问题,在md中行内公式和行间公式是有明显区分的($$与$),但我到知乎编辑器中发现生成的公式全部都是行间公式(知乎中似乎没有区分这两个),或者说我手动给几个换行符变成 ”行正确“ 的公式后,也存在着 ”行正确“ 公式没有居中的问题。 如果要居中它也是可以,需要我再编辑一下,给公式结尾加上 ' \\' 换行,这一点往往是在md单行公式中没有加的。 我认为这一点可以修改一下,把产生知乎公式格式调整一下,行间公式后面都补上 ' \\',使其在知乎编辑器中可以居中。

https://zhuanlan.zhihu.com/p/31188118

谢谢:)

Magica-Chen commented 4 years ago

我这边直接运行这个例子也有些问题哈,不知道如何解决,能不能帮忙看看哈 (base) D:\Markdown4Zhihu>python zhihu-publisher.py --input="./Data/一个测试文档.md" {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''} Traceback (most recent call last): File "zhihu-publisher.py", line 126, in <module> process_for_zhihu() File "zhihu-publisher.py", line 35, in process_for_zhihu lines = image_ops(lines) File "zhihu-publisher.py", line 76, in image_ops _lines = re.sub(r'<img src="(.*?)"',functools.partial(rename_image_ref, original=False), _lines) File "C:\Users\user\anaconda3\lib\re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count) File "zhihu-publisher.py", line 51, in rename_image_ref if not (Path(image_folder_path.parent/m.group(1)).is_file() or Path(image_folder_path.parent/m.group(2)).is_file()): File "C:\Users\user\anaconda3\lib\site-packages\pathlib2\__init__.py", line 1663, in is_file return S_ISREG(self.stat().st_mode) File "C:\Users\user\anaconda3\lib\site-packages\pathlib2\__init__.py", line 1436, in stat return self._accessor.stat(self) File "C:\Users\user\anaconda3\lib\site-packages\pathlib2\__init__.py", line 585, in wrapped return strfunc(str(pathobj), *args) OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'Data\\https:\\www.zhihu.com\\equation?tex=Sum=\\sum_{i=0}^{n}{\\sqrt{x_i^2+y_i^2}}'

RshStone commented 3 years ago

我这边直接运行这个例子也有些问题哈,不知道如何解决,能不能帮忙看看哈 (base) D:\Markdown4Zhihu>python zhihu-publisher.py --input="./Data/一个测试文档.md" {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''} Traceback (most recent call last): File "zhihu-publisher.py", line 126, in <module> process_for_zhihu() File "zhihu-publisher.py", line 35, in process_for_zhihu lines = image_ops(lines) File "zhihu-publisher.py", line 76, in image_ops _lines = re.sub(r'<img src="(.*?)"',functools.partial(rename_image_ref, original=False), _lines) File "C:\Users\user\anaconda3\lib\re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count) File "zhihu-publisher.py", line 51, in rename_image_ref if not (Path(image_folder_path.parent/m.group(1)).is_file() or Path(image_folder_path.parent/m.group(2)).is_file()): File "C:\Users\user\anaconda3\lib\site-packages\pathlib2\__init__.py", line 1663, in is_file return S_ISREG(self.stat().st_mode) File "C:\Users\user\anaconda3\lib\site-packages\pathlib2\__init__.py", line 1436, in stat return self._accessor.stat(self) File "C:\Users\user\anaconda3\lib\site-packages\pathlib2\__init__.py", line 585, in wrapped return strfunc(str(pathobj), *args) OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'Data\\https:\\www.zhihu.com\\equation?tex=Sum=\\sum_{i=0}^{n}{\\sqrt{x_i^2+y_i^2}}'

请问你解决了吗

Pearlzju commented 3 years ago

你好,我这边遇到这个问题,不知道如何解决,能否帮忙看下,感谢

(python3) ➜ /Users/shanglin/pearl/tool/Markdown4Zhihu git:(master) ✗ python zhihu-publisher.py --input="./Data/一个测试文档.md" {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''} 1 ('这里是一个测试图片', '一个测试文档/image-01.png') 2 False 1 ('https://www.zhihu.com/equation?tex=Sum=\\sum_{i=0}^{n}{\\sqrt{x_i^2+y_i^2}}',) 2 False Traceback (most recent call last): File "/Users/shanglin/pearl/tool/Markdown4Zhihu/zhihu-publisher.py", line 129, in process_for_zhihu() File "/Users/shanglin/pearl/tool/Markdown4Zhihu/zhihu-publisher.py", line 35, in process_for_zhihu lines = image_ops(lines) File "/Users/shanglin/pearl/tool/Markdown4Zhihu/zhihu-publisher.py", line 79, in image_ops _lines = re.sub(r'<img src="(.*?)"',functools.partial(rename_image_ref, original=False), _lines) File "/usr/local/Cellar/python@3.9/3.9.1_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 210, in sub return _compile(pattern, flags).sub(repl, string, count) File "/Users/shanglin/pearl/tool/Markdown4Zhihu/zhihu-publisher.py", line 54, in rename_image_ref if not (Path(image_folder_path.parent/m.group(1)).is_file() or Path(image_folder_path.parent/m.group(2)).is_file()): IndexError: no such group

SUNRISEFLY commented 3 years ago

@Pearlzju 我也遇到了相同的问题