添加一些 tag 解析
This commit is contained in:
parent
14dd7b1cfa
commit
4be5301af1
@ -1,21 +1,5 @@
|
||||
---
|
||||
```toml
|
||||
tags = [
|
||||
"小型模块",
|
||||
"算术运算模块",
|
||||
"加/减法器",
|
||||
"二级模块",
|
||||
"静音",
|
||||
"传统红石",
|
||||
"无容器",
|
||||
"Java版"
|
||||
]
|
||||
authors = ["Fredbill"]
|
||||
title = "CCA-vertial-20gt-32bit"
|
||||
description = "竖式 32位 20gt 加法器"
|
||||
[version]
|
||||
java = "1.16+"
|
||||
```
|
||||
module
|
||||
---
|
||||
|
||||
# 32位封闭进位加法器
|
||||
|
@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
import mistune
|
||||
|
||||
@ -9,6 +10,7 @@ from lib_not_dr.types.options import Options
|
||||
|
||||
|
||||
ast_markdown = mistune.create_markdown(renderer='ast')
|
||||
ast_type = list[dict[str, str | dict]]
|
||||
|
||||
|
||||
class TagParser(Options):
|
||||
@ -59,7 +61,48 @@ class TagParser(Options):
|
||||
def init(self, **kwargs) -> bool:
|
||||
self.logger = loggers.get_logger()
|
||||
self.logger.global_level = 0
|
||||
return True
|
||||
self.load_tags()
|
||||
return False
|
||||
|
||||
def load_tags(self):
|
||||
tag_list_path = Path("./tags/readme.md")
|
||||
if not tag_list_path.exists():
|
||||
self.logger.error("未找到 tags/readme.md")
|
||||
return False
|
||||
|
||||
with open(tag_list_path, 'r', encoding='utf-8') as f:
|
||||
file = f.read()
|
||||
|
||||
tag_ast: ast_type = ast_markdown(file)
|
||||
start_tag = -1
|
||||
for i, node in enumerate(tag_ast):
|
||||
if node['type'] != 'heading':
|
||||
continue
|
||||
if node['attrs']['level'] != 2:
|
||||
continue
|
||||
# 说明是二级标题
|
||||
start_tag = i
|
||||
break
|
||||
if start_tag == -1:
|
||||
self.logger.error("未找到二级标题")
|
||||
return False
|
||||
# 获取 tag
|
||||
tag_ast: ast_type = tag_ast[start_tag + 1:]
|
||||
|
||||
start_tag = -1
|
||||
for i, node in enumerate(tag_ast):
|
||||
if node['type'] != 'list':
|
||||
continue
|
||||
start_tag = i
|
||||
break
|
||||
if start_tag == -1:
|
||||
self.logger.error("未找到 tag 列表")
|
||||
return False
|
||||
tag_ast: ast_type = [item['children'] for item in tag_ast[start_tag]['children'] if item.get('type') == 'list_item']
|
||||
# 顺手过滤一下
|
||||
pprint(tag_ast)
|
||||
self.logger.info(tag_ast)
|
||||
# 获取 tag 列表
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -4,7 +4,10 @@
|
||||
|
||||
## 所有可用标签
|
||||
|
||||
- [小型模块](./tags/small_module.md) : 方块数量小于10000的模块
|
||||
- [小型模块](./tags/small_module.md)
|
||||
- 方块数量小于10000的模块
|
||||
- 别名
|
||||
- 小模块
|
||||
- [中型模块](./tags/middle_size_module.md) : 方块数量在10001-100000之间的模块。
|
||||
- [大型模块](./tags/large_module.md) : 方块数量>100000的模块。
|
||||
- [算术单元](./tags/au.md) : 具有运算功能的模块。
|
||||
|
Loading…
Reference in New Issue
Block a user