Coverage for lintro / formatters / styles / markdown.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Markdown output style implementation.""" 

2 

3from typing import Any 

4 

5from lintro.formatters.core.format_registry import OutputStyle 

6 

7 

8class MarkdownStyle(OutputStyle): 

9 """Output format that renders data as markdown table.""" 

10 

11 def format( 

12 self, 

13 columns: list[str], 

14 rows: list[list[Any]], 

15 tool_name: str | None = None, 

16 **kwargs: Any, 

17 ) -> str: 

18 """Format a table given columns and rows as markdown. 

19 

20 Args: 

21 columns: List of column header names. 

22 rows: List of row values (each row is a list of cell values). 

23 tool_name: Optional tool name to include in context. 

24 **kwargs: Extra options ignored by this formatter. 

25 

26 Returns: 

27 Formatted data as markdown table string. 

28 """ 

29 if not rows: 

30 return "No issues found." 

31 

32 # Build the header 

33 header = "| " + " | ".join(columns) + " |" 

34 separator = "| " + " | ".join("---" for _ in columns) + " |" 

35 

36 # Build the rows 

37 formatted_rows = [] 

38 for row in rows: 

39 # Ensure row has same number of elements as columns 

40 padded_row = row + [""] * (len(columns) - len(row)) 

41 # Escape pipe characters in cell values 

42 escaped_cells = [str(cell).replace("|", "\\|") for cell in padded_row] 

43 formatted_rows.append("| " + " | ".join(escaped_cells) + " |") 

44 

45 # Combine all parts 

46 result = [header, separator] + formatted_rows 

47 return "\n".join(result)