Skip to content

Commit 2c5cd8e

Browse files
committed
update version to 0.2.0
1 parent 1340f6f commit 2c5cd8e

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"name": "Python: 当前文件",
99
"type": "python",
1010
"request": "launch",
11-
"program": "${file}",
11+
// "program": "${file}",
12+
"program": "${workspaceFolder}\\tests\\test.py",
13+
"cwd": "${workspaceFolder}\\tests",
1214
"console": "integratedTerminal"
1315
}
1416
]

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- pypi:<https://pypi.org/project/markdown-img-icexmoon/>
66
- github:<https://github.com/icexmoon/markdown-img>
7-
- 个人博客:<https://blog.icexmoon.xyz/>
7+
- 个人博客:<https://blog.icexmoon.xyz/?p=99>
88

99
## 用途
1010

@@ -30,7 +30,7 @@
3030
3131
- `sm.ms`国内访问不算友好,生成的markdown拷贝立即在网络上发布可能会显示防盗链等图片挂掉的情况,那是因为国内CDN比较慢,等一段时间就好了。
3232

33-
- 本程序使用Python编写,需要安装Python运行环境,如果不知道如何安装的,可以阅读[**windows下的python环境安装**](https://blog.icexmoon.xyz/?p=101)
33+
- 本程序使用Python编写,需要安装Python运行环境,如果不知道如何安装,可以阅读[**windows下的python环境安装**](https://blog.icexmoon.xyz/?p=101)
3434

3535
## 安装
3636

@@ -169,4 +169,12 @@ python -m markdown_img -m refresh
169169

170170
加入遇见图床支持。
171171

172-
阿里图床的API调用替换为遇见图床。
172+
阿里图床的API调用替换为遇见图床。
173+
174+
### 0.1.9
175+
176+
修复了只能处理png,不能识别并处理其他格式的图片的问题。
177+
178+
### 0.2.0
179+
180+
修复了不能识别html`<img/>`标签的问题,现在对img标签中的图片也可以正常处理了。

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
# replace with your username:
33
name = markdown-img-icexmoon
4-
version = 0.1.8
4+
version = 0.2.0
55
author = icexmoon
66
author_email = [email protected]
77
description = A program for find and upload images in markdown file and will replace them.

src/markdown_img/main.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .user_exception import UserException
55
from .download_help import DownloadHelp
66
from .time_helper import TimeHelper
7+
import re
78

89

910
class Main():
@@ -42,27 +43,53 @@ def getCopyFilePath(self, fileName: str):
4243
SysConfig = Config()
4344
return SysConfig.getMarkdownImgDirPath()+'\\'+copyFileName
4445

46+
def isImgFileName(self, file):
47+
imgExts = ('.png', '.gif', '.jpg', '.jpeg', '.svg', '.bmp')
48+
for imgExt in imgExts:
49+
if file.endswith(imgExt):
50+
return True
51+
return False
52+
53+
def findHtmlImg(self, line, onlyLocal) -> list:
54+
'''从字符串中查找html标签中的本地图片'''
55+
findImgs = []
56+
pattern = re.compile(r"<img src=\"(.+?)\"(.*)/>")
57+
for matched in pattern.finditer(line):
58+
imgFile = matched.group(1)
59+
if self.isImgFileName(imgFile):
60+
if not onlyLocal:
61+
findImgs.append(imgFile)
62+
elif os.path.exists(imgFile):
63+
findImgs.append(imgFile)
64+
else:
65+
pass
66+
return findImgs
67+
4568
def findLocalImageFile(self, line: str, localImages: set):
4669
'''递归查找某段字符串中中括号包裹的内容是否为本地图片'''
70+
htmlImgs = self.findHtmlImg(line,True)
71+
if htmlImgs:
72+
localImages.update(htmlImgs)
4773
linePart = line.partition('(')
4874
if len(linePart[2]) > 0:
4975
secondPart = linePart[2].partition(')')
5076
content = secondPart[0]
5177
if len(content) > 0:
52-
# print(content)
53-
if content.endswith('.png') and os.path.exists(content):
78+
if self.isImgFileName(content) and os.path.exists(content):
5479
localImages.add(content)
5580
self.findLocalImageFile(content, localImages)
5681

5782
def findImagesInStr(self, line: str, localImages: list):
5883
'''递归查找某段字符串中中括号包裹的内容是否为本地图片'''
84+
htmlImgs = self.findHtmlImg(line,False)
85+
if htmlImgs:
86+
localImages.update(htmlImgs)
5987
linePart = line.partition('(')
6088
if len(linePart[2]) > 0:
6189
secondPart = linePart[2].partition(')')
6290
content = secondPart[0]
6391
if len(content) > 0:
64-
# print(content)
65-
if content.endswith('.png'):
92+
if self.isImgFileName(content):
6693
localImages.append(content)
6794
self.findImagesInStr(content, localImages)
6895

0 commit comments

Comments
 (0)