feat: add all_files iterator to simplify searching

Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
Konstantin Fickel 2026-01-30 18:05:26 +01:00
parent 1ce0790c0c
commit ee91b2e8db
Signed by: kfickel
GPG key ID: A793722F9933C1A5
3 changed files with 62 additions and 23 deletions

View file

@ -0,0 +1,31 @@
from streamer.parse.shard import Shard, StreamFile
class ShardWithMarkdown(Shard):
children: list[ShardWithMarkdown]
markdown_content: str
class StreamFileWithMarkdown(StreamFile):
shard: ShardWithMarkdown | None = None # pyright: ignore[reportIncompatibleVariableOverride]
def attach_markdown_shard(shard: Shard, markdown_text: str) -> ShardWithMarkdown:
lines = markdown_text.splitlines()
markdown_content = "\n".join(lines[shard.start_line - 1 : shard.end_line])
return ShardWithMarkdown(
**shard.model_dump(exclude=["children"]),
children=map(lambda child: attach_markdown_shard(child, markdown_text), shard.children),
markdown_content=markdown_content,
)
def attach_markdown(file: StreamFile, markdown_text: str) -> StreamFileWithMarkdown:
if file.shard is None:
return StreamFileWithMarkdown(filename=file.filename, shard=None)
attached_shard = attach_markdown_shard(file.shard, markdown_text)
return StreamFileWithMarkdown(filename=file.filename, shard=attached_shard)
__all__ = ["attach_markdown"]