提交 4fb530f3 编写于 作者: M Mars Liu

upgrade to 0.0.5

上级 1d664a0a
...@@ -9,4 +9,8 @@ CSDN 技能树结构(章节、元信息、习题)解释器,支持技能树 ...@@ -9,4 +9,8 @@ CSDN 技能树结构(章节、元信息、习题)解释器,支持技能树
## what's new ## what's new
### 0.0.4 ### 0.0.4
- 支持在习题中内嵌 markdown 源码 - 支持在习题中内嵌 markdown 源码
\ No newline at end of file
### 0.0.5
- 捕获习题编码错误
- 捕获 json 文件编码错误
\ No newline at end of file
...@@ -7,7 +7,7 @@ this_directory = Path(__file__).parent ...@@ -7,7 +7,7 @@ this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text() long_description = (this_directory / "README.md").read_text()
setup(name="skill-tree-parser", setup(name="skill-tree-parser",
version="0.0.4", version="0.0.5",
description="CSDN Skill Tree Parser", description="CSDN Skill Tree Parser",
long_description=long_description, long_description=long_description,
long_description_content_type='text/markdown', long_description_content_type='text/markdown',
......
...@@ -42,7 +42,10 @@ def user_name(md_file, author_dict): ...@@ -42,7 +42,10 @@ def user_name(md_file, author_dict):
def load_json(p): def load_json(p):
with open(p, 'r', encoding="utf-8") as f: with open(p, 'r', encoding="utf-8") as f:
return json.loads(f.read()) try:
return json.loads(f.read())
except UnicodeDecodeError:
logger.info("json 文件 [{p}] 编码错误,请确保其内容保存为 utf-8 或 base64 后的 ascii 格式。")
def dump_json(p, j, exist_ok=False, override=False): def dump_json(p, j, exist_ok=False, override=False):
...@@ -368,13 +371,17 @@ class TreeWalker: ...@@ -368,13 +371,17 @@ class TreeWalker:
flag = True flag = True
config["export"] = export config["export"] = export
with open(md_file, "r", encoding="utf-8") as efile: with open(md_file, "r", encoding="utf-8") as efile:
data = efile.read() try:
data = efile.read()
except UnicodeDecodeError:
logger.error(f"习题 [{md_file}] 编码错误,请确保其保存为 utf-8 编码")
sys.exit(1)
state = BasicState(data) state = BasicState(data)
try: try:
doc = parse(state) doc = parse(state)
except ParsecError as err: except ParsecError as err:
index = state.index index = state.index
context = state.data[index-15:index+15] context = state.data[index - 15:index + 15]
logger.error(f"习题 [{md_file}] 解析失败,在位置 {index} [{context}] 附近有格式: [{err}]") logger.error(f"习题 [{md_file}] 解析失败,在位置 {index} [{context}] 附近有格式: [{err}]")
if flag: if flag:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册