Compare commits

..

2 Commits

Author SHA1 Message Date
1127dff969
ignore .idea
Some checks failed
自动生成 label / Generate-label (push) Failing after 53s
2023-12-15 06:52:50 +08:00
4be5301af1
添加一些 tag 解析 2023-12-15 06:51:32 +08:00
4 changed files with 58 additions and 19 deletions

9
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,9 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
*

View File

@ -1,21 +1,5 @@
--- ---
```toml module
tags = [
"小型模块",
"算术运算模块",
"加/减法器",
"二级模块",
"静音",
"传统红石",
"无容器",
"Java版"
]
authors = ["Fredbill"]
title = "CCA-vertial-20gt-32bit"
description = "竖式 32位 20gt 加法器"
[version]
java = "1.16+"
```
--- ---
# 32位封闭进位加法器 # 32位封闭进位加法器

View File

@ -1,4 +1,5 @@
from pathlib import Path from pathlib import Path
from pprint import pprint
import mistune import mistune
@ -9,6 +10,7 @@ from lib_not_dr.types.options import Options
ast_markdown = mistune.create_markdown(renderer='ast') ast_markdown = mistune.create_markdown(renderer='ast')
ast_type = list[dict[str, str | dict]]
class TagParser(Options): class TagParser(Options):
@ -59,7 +61,48 @@ class TagParser(Options):
def init(self, **kwargs) -> bool: def init(self, **kwargs) -> bool:
self.logger = loggers.get_logger() self.logger = loggers.get_logger()
self.logger.global_level = 0 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__': if __name__ == '__main__':

View File

@ -4,7 +4,10 @@
## 所有可用标签 ## 所有可用标签
- [小型模块](./tags/small_module.md) : 方块数量小于10000的模块 - [小型模块](./tags/small_module.md)
- 方块数量小于10000的模块
- 别名
- 小模块
- [中型模块](./tags/middle_size_module.md) : 方块数量在10001-100000之间的模块。 - [中型模块](./tags/middle_size_module.md) : 方块数量在10001-100000之间的模块。
- [大型模块](./tags/large_module.md) : 方块数量>100000的模块。 - [大型模块](./tags/large_module.md) : 方块数量>100000的模块。
- [算术单元](./tags/au.md) : 具有运算功能的模块。 - [算术单元](./tags/au.md) : 具有运算功能的模块。