(value: Any, fallback: str)
| 37 | |
| 38 | |
| 39 | def _text(value: Any, fallback: str) -> str: |
| 40 | candidate = value if isinstance(value, str) and value.strip() else fallback |
| 41 | normalized = " ".join(candidate.split()) |
| 42 | if not normalized: |
| 43 | return "" |
| 44 | if re.match(r"^(?:#{1,6}\s|[-*+]\s|>\s|```|\d+\.\s|\|)", normalized): |
| 45 | normalized = f"Text: {normalized}" |
| 46 | rendered: list[str] = [] |
| 47 | cursor = 0 |
| 48 | for match in re.finditer(r"(?<!`)`([^`\n]+)`(?!`)", normalized): |
| 49 | rendered.append(_escape_markdown_text(normalized[cursor : match.start()])) |
| 50 | rendered.append(f"`{match.group(1)}`") |
| 51 | cursor = match.end() |
| 52 | rendered.append(_escape_markdown_text(normalized[cursor:])) |
| 53 | return "".join(rendered) |
| 54 | |
| 55 | |
| 56 | def _escape_markdown_text(value: str) -> str: |
no test coverage detected