Implement Edit Feature #28

Merged
kfickel merged 12 commits from 8-edit-feature into main 2026-02-01 10:34:32 +01:00
Showing only changes of commit 84843aea12 - Show all commits

View file

@ -1,22 +1,30 @@
from __future__ import annotations from __future__ import annotations
from pydantic import BaseModel
from streamer.parse.shard import Shard, StreamFile from streamer.parse.shard import Shard, StreamFile
class ShardWithMarkdown(Shard): class ShardWithMarkdown(BaseModel):
children: list[ShardWithMarkdown] markers: list[str] = []
tags: list[str] = []
start_line: int
end_line: int
children: list["ShardWithMarkdown"] = []
markdown_content: str markdown_content: str
class StreamFileWithMarkdown(StreamFile): class StreamFileWithMarkdown(BaseModel):
file_name: str
shard: ShardWithMarkdown | None = None shard: ShardWithMarkdown | None = None
def attach_markdown_shard(shard: Shard, markdown_text: str) -> ShardWithMarkdown: def attach_markdown_shard(shard: Shard, markdown_text: str) -> ShardWithMarkdown:
lines = markdown_text.splitlines() lines = markdown_text.splitlines()
markdown_content = "\n".join(lines[shard.start_line - 1 : shard.end_line]) markdown_content = "\n".join(lines[shard.start_line - 1 : shard.end_line])
return ShardWithMarkdown( return ShardWithMarkdown(
**shard.model_dump(exclude=["children"]), **shard.model_dump(exclude={"children"}),
children=[ children=[
attach_markdown_shard(child, markdown_text) for child in shard.children attach_markdown_shard(child, markdown_text) for child in shard.children
], ],