Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions edgar/company_reports/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,26 @@ def view(self, item_or_part: str):
if item_text:
print(item_text)

def _focused_context(self, focus, detail: str = 'standard') -> str:
def _focused_context(self, focus, detail: str = 'standard', output_format: str = 'text') -> str:
"""Generate cross-cutting context for specific topic(s).

Pulls statement line items, note content, and policies together.

Args:
focus: Topic or list of topics
detail: 'minimal', 'standard', or 'full'
output_format: 'text' (default) or 'markdown' for GFM pipe tables
"""
if isinstance(focus, str):
focus = [focus]

notes = self.notes

# Markdown mode: delegate to Notes.to_markdown with focus filtering
if output_format == 'markdown' and notes:
return notes.to_markdown(detail=detail, focus=focus, optimize_for_llm=True)

# Text mode (original behavior)
form_label = self.form or 'Filing'
lines = []
topic_str = ', '.join(focus)
Expand All @@ -220,7 +232,6 @@ def _focused_context(self, focus, detail: str = 'standard') -> str:
pass
lines.append("")

notes = self.notes
if not notes:
lines.append("(No notes available)")
return "\n".join(lines)
Expand Down
6 changes: 4 additions & 2 deletions edgar/company_reports/ten_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def id_parse_document(self, markdown:bool=False):
def __str__(self):
return f"""TenK('{self.company}')"""

def to_context(self, detail: str = 'standard', focus: 'str | list[str] | None' = None) -> str:
def to_context(self, detail: str = 'standard', focus: 'str | list[str] | None' = None,
output_format: str = 'text') -> str:
"""
AI-optimized context string.

Expand All @@ -358,10 +359,11 @@ def to_context(self, detail: str = 'standard', focus: 'str | list[str] | None' =
focus: Optional topic or list of topics for cross-cutting context.
When set, returns statement lines + note + policy for that topic.
Example: focus='debt' or focus=['debt', 'revenue']
output_format: 'text' (default) or 'markdown' for GFM with pipe tables
"""
# Handle focus mode — cross-cutting topic context
if focus:
return self._focused_context(focus, detail)
return self._focused_context(focus, detail, output_format=output_format)

from edgar.display.formatting import format_currency_short

Expand Down
6 changes: 4 additions & 2 deletions edgar/company_reports/ten_q.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def __init__(self, filing):
def __str__(self):
return f"""TenQ('{self.company}')"""

def to_context(self, detail: str = 'standard', focus: 'str | list[str] | None' = None) -> str:
def to_context(self, detail: str = 'standard', focus: 'str | list[str] | None' = None,
output_format: str = 'text') -> str:
"""
AI-optimized context string.

Expand All @@ -88,10 +89,11 @@ def to_context(self, detail: str = 'standard', focus: 'str | list[str] | None' =
focus: Optional topic or list of topics for cross-cutting context.
When set, returns statement lines + note + policy for that topic.
Example: focus='debt' or focus=['debt', 'revenue']
output_format: 'text' (default) or 'markdown' for GFM with pipe tables
"""
# Handle focus mode — cross-cutting topic context
if focus:
return self._focused_context(focus, detail)
return self._focused_context(focus, detail, output_format=output_format)

from edgar.display.formatting import format_currency_short

Expand Down
Loading
Loading