Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_parser
提交
2f84db1a
S
skill_tree_parser
项目概览
CSDN 技术社区
/
skill_tree_parser
通知
5
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_parser
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2f84db1a
编写于
2月 09, 2022
作者:
F
feilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
如果markdown文本为空则初始化模版,修正新创建文件还没加入git管理时的username获取问题
上级
ae799754
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
7 deletion
+87
-7
.gitignore
.gitignore
+3
-0
src/skill_tree/exercises/init_exercises.py
src/skill_tree/exercises/init_exercises.py
+52
-0
src/skill_tree/tree.py
src/skill_tree/tree.py
+32
-7
未找到文件。
.gitignore
浏览文件 @
2f84db1a
...
...
@@ -59,3 +59,6 @@ target/
.settings/**
.project
.pydevproject
.DS_Store
\ No newline at end of file
src/skill_tree/exercises/init_exercises.py
0 → 100644
浏览文件 @
2f84db1a
def
simple_list_md_load
(
p
):
with
open
(
p
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
lines
=
f
.
readlines
()
result
=
[]
for
line
in
lines
:
item
=
line
.
strip
(
'
\n
'
)
result
.
append
(
item
)
return
result
def
simple_list_md_dump
(
p
,
lines
):
with
open
(
p
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
'
\n
'
.
join
(
lines
))
def
emit_head
(
md
):
title
=
'{在此填写标题}'
contents
=
[
'{在此填写题目描述}'
]
md
.
append
(
f
'#
{
title
}
'
)
md
.
append
(
''
)
for
content
in
contents
:
md
.
append
(
content
)
md
.
append
(
''
)
def
emit_answer
(
md
,
language
):
md
.
append
(
f
'## 答案'
)
md
.
append
(
''
)
if
language
:
md
.
append
(
f
'```
{
language
}
'
)
md
.
append
(
''
)
md
.
append
(
'```'
)
else
:
md
.
append
(
'{在此填写答案}'
)
md
.
append
(
''
)
def
emit_options
(
md
,
language
):
md
.
append
(
f
'## 选项'
)
md
.
append
(
''
)
for
tag
in
[
'A'
,
'B'
,
'C'
]:
md
.
append
(
f
'###
{
tag
}
'
)
md
.
append
(
''
)
if
language
:
md
.
append
(
f
'```
{
language
}
'
)
md
.
append
(
''
)
md
.
append
(
'```'
)
else
:
md
.
append
(
'{在此填写选项'
+
f
'
{
tag
}
'
+
'}'
)
md
.
append
(
''
)
src/skill_tree/tree.py
浏览文件 @
2f84db1a
...
...
@@ -9,6 +9,7 @@ import re
from
parsec
import
BasicState
,
ParsecError
from
.exercises.markdown
import
parse
from
.exercises.init_exercises
import
emit_head
,
emit_answer
,
emit_options
,
simple_list_md_dump
id_set
=
set
()
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -36,6 +37,8 @@ def user_name(md_file, author_dict):
for
line
in
lines
:
if
line
.
startswith
(
'Author'
):
author_lines
.
append
(
line
.
split
(
' '
)[
1
])
if
len
(
author_lines
)
==
0
:
return
None
author_nick_name
=
author_lines
[
-
1
]
return
search_author
(
author_dict
,
author_nick_name
)
...
...
@@ -45,7 +48,8 @@ def load_json(p):
try
:
return
json
.
loads
(
f
.
read
())
except
UnicodeDecodeError
:
logger
.
info
(
"json 文件 [{p}] 编码错误,请确保其内容保存为 utf-8 或 base64 后的 ascii 格式。"
)
logger
.
info
(
"json 文件 [{p}] 编码错误,请确保其内容保存为 utf-8 或 base64 后的 ascii 格式。"
)
def
dump_json
(
p
,
j
,
exist_ok
=
False
,
override
=
False
):
...
...
@@ -374,19 +378,38 @@ class TreeWalker:
export
.
append
(
mfile
)
flag
=
True
config
[
"export"
]
=
export
data
=
None
with
open
(
md_file
,
"r"
,
encoding
=
"utf-8"
)
as
efile
:
try
:
data
=
efile
.
read
()
except
UnicodeDecodeError
:
logger
.
error
(
f
"习题 [
{
md_file
}
] 编码错误,请确保其保存为 utf-8 编码"
)
sys
.
exit
(
1
)
state
=
BasicState
(
data
)
if
data
.
strip
()
==
''
:
md
=
[]
emit_head
(
md
)
emit_answer
(
md
,
None
)
emit_options
(
md
,
None
)
simple_list_md_dump
(
md_file
,
md
)
data
=
None
with
open
(
md_file
,
"r"
,
encoding
=
"utf-8"
)
as
efile
:
try
:
doc
=
parse
(
state
)
except
ParsecError
as
err
:
index
=
state
.
index
context
=
state
.
data
[
index
-
15
:
index
+
15
]
logger
.
error
(
f
"习题 [
{
md_file
}
] 解析失败,在位置
{
index
}
[
{
context
}
] 附近有格式: [
{
err
}
]"
)
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
]
logger
.
error
(
f
"习题 [
{
md_file
}
] 解析失败,在位置
{
index
}
[
{
context
}
] 附近有格式: [
{
err
}
]"
)
if
flag
:
dump_json
(
os
.
path
.
join
(
section_path
,
"config.json"
),
...
...
@@ -418,6 +441,8 @@ class TreeWalker:
meta
[
"source"
]
=
source
if
"author"
not
in
meta
:
meta
[
"author"
]
=
user_name
(
md_file
,
self
.
authors
)
elif
meta
[
'author'
]
is
None
:
meta
[
"author"
]
=
user_name
(
md_file
,
self
.
authors
)
if
"type"
not
in
meta
:
meta
[
"type"
]
=
"code_options"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录