Coverage for lintro / utils / output / helpers.py: 100%
9 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Helper functions for output formatting.
3This module contains escape and sanitization helpers used by
4output writing classes and functions.
5"""
7import html
10def markdown_escape(text: str) -> str:
11 """Escape text for Markdown formatting.
13 Args:
14 text: str: Text to escape.
16 Returns:
17 str: Escaped text safe for Markdown.
18 """
19 return text.replace("|", r"\|").replace("\n", " ")
22def html_escape(text: str) -> str:
23 """Escape text for HTML formatting.
25 Args:
26 text: str: Text to escape.
28 Returns:
29 str: Escaped text safe for HTML.
30 """
31 return html.escape(text)
34def sanitize_csv_value(value: str) -> str:
35 """Sanitize CSV cell value to prevent formula injection.
37 Prefixes values starting with '=', '+', '-', or '@' with a single quote
38 to prevent spreadsheet applications from interpreting them as formulas.
40 Args:
41 value: str: The value to sanitize.
43 Returns:
44 str: Sanitized value with leading quote if needed.
45 """
46 if value and value.startswith(("=", "+", "-", "@")):
47 return "'" + value
48 return value