Coverage for pydantic_ai_jupyter / markdown.py: 92%

12 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-01-26 11:36 -0800

1"""Live-updating Markdown display for Jupyter notebooks.""" 

2 

3from __future__ import annotations 

4 

5from pydantic import Field 

6 

7from .decorators import markdown 

8from .models import View 

9 

10 

11@markdown 

12class Markdown(View): 

13 """A live-updating Markdown display for Jupyter notebooks. 

14 

15 This class manages its own display_id internally and provides 

16 methods to append content and update the display in place. 

17 

18 Example: 

19 md = Markdown("# Hello") 

20 md.display() 

21 md.append(" World!") # Updates in place 

22 """ 

23 

24 content: str = Field(default="", description="The content of the Markdown display.") 

25 

26 def render(self) -> str: 

27 return self.content 

28 

29 def append(self, text: str) -> None: 

30 """Append text and update the display.""" 

31 self.content += text 

32 self.update()