chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""Wire form of source blocks (see docreader.parser.source_locator).
|
||||
|
||||
Kept apart from docreader.main so it can be imported without the parser
|
||||
registry.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
from docreader.proto.docreader_pb2 import SourceBlock
|
||||
|
||||
|
||||
def source_blocks_to_proto(document) -> list:
|
||||
"""Convert a document's source blocks to their wire form.
|
||||
|
||||
Malformed entries are skipped: positions are an optional extra and must
|
||||
never fail a parse.
|
||||
"""
|
||||
out = []
|
||||
for block in getattr(document, "source_blocks", None) or []:
|
||||
try:
|
||||
start, end = int(block["start"]), int(block["end"])
|
||||
locator = block["locator"]
|
||||
if end <= start or start < 0 or not locator.get("type"):
|
||||
continue
|
||||
out.append(
|
||||
SourceBlock(
|
||||
start=start,
|
||||
end=end,
|
||||
locator_json=json.dumps(locator, ensure_ascii=False),
|
||||
)
|
||||
)
|
||||
except (KeyError, TypeError, ValueError, AttributeError):
|
||||
continue
|
||||
return out
|
||||
Reference in new issue
Block a user