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

upgrade to 0.0.5

上级 1d664a0a
......@@ -9,4 +9,8 @@ CSDN 技能树结构(章节、元信息、习题)解释器,支持技能树
## what's new
### 0.0.4
- 支持在习题中内嵌 markdown 源码
\ No newline at end of file
- 支持在习题中内嵌 markdown 源码
### 0.0.5
- 捕获习题编码错误
- 捕获 json 文件编码错误
\ No newline at end of file
......@@ -7,7 +7,7 @@ this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
setup(name="skill-tree-parser",
version="0.0.4",
version="0.0.5",
description="CSDN Skill Tree Parser",
long_description=long_description,
long_description_content_type='text/markdown',
......
......@@ -42,7 +42,10 @@ def user_name(md_file, author_dict):
def load_json(p):
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):
......@@ -368,13 +371,17 @@ class TreeWalker:
flag = True
config["export"] = export
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)
try:
doc = parse(state)
except ParsecError as err:
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}]")
if flag:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册