Render a TOML command file from description and body. Uses multiline basic strings (``\"\"\"``) with backslashes escaped, matching the output of the release script. Falls back to multiline literal strings (``'''``) if the body contains ``\"\"\"``, then to an escaped
(description: str, body: str)
| 975 | |
| 976 | @staticmethod |
| 977 | def _render_toml(description: str, body: str) -> str: |
| 978 | """Render a TOML command file from description and body. |
| 979 | |
| 980 | Uses multiline basic strings (``\"\"\"``) with backslashes |
| 981 | escaped, matching the output of the release script. Falls back |
| 982 | to multiline literal strings (``'''``) if the body contains |
| 983 | ``\"\"\"``, then to an escaped basic string as a last resort. |
| 984 | |
| 985 | The body is ``rstrip("\\n")``'d before rendering, so the TOML |
| 986 | value preserves content without forcing a trailing newline. As a |
| 987 | result, multiline delimiters appear on their own line only when |
| 988 | the rendered value itself ends with a newline. |
| 989 | """ |
| 990 | toml_lines: list[str] = [] |
| 991 | |
| 992 | if description: |
| 993 | toml_lines.append( |
| 994 | f"description = {TomlIntegration._render_toml_string(description)}" |
| 995 | ) |
| 996 | toml_lines.append("") |
| 997 | |
| 998 | body = body.rstrip("\n") |
| 999 | toml_lines.append(f"prompt = {TomlIntegration._render_toml_string(body)}") |
| 1000 | |
| 1001 | return "\n".join(toml_lines) + "\n" |
| 1002 | |
| 1003 | def setup( |
| 1004 | self, |
no test coverage detected