Skip to content

Commit 8cfa34c

Browse files
authored
Merge branch 'main' into main
2 parents d076905 + a598bfd commit 8cfa34c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tux/cogs/utility/tldr.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,26 @@ def get_tldr_page(self, command: str) -> str:
121121
if command.startswith("-"):
122122
return "Invalid command: Command can't start with a dash (-)."
123123

124-
return self._run_subprocess(["tldr", "-r", command], "No TLDR page found.")
124+
output = self._run_subprocess(["tldr", "-r", command], "No TLDR page found.")
125+
# Process output: escape leading dashes and inline code
126+
lines = output.splitlines()
127+
formatted_lines: list[str] = []
128+
for i, raw in enumerate(lines):
129+
# remove blank between dash and backtick
130+
if (
131+
not raw.strip()
132+
and i > 0
133+
and i < len(lines) - 1
134+
and lines[i - 1].startswith("-")
135+
and lines[i + 1].startswith("`")
136+
):
137+
continue
138+
line = raw
139+
# escape leading dash
140+
if line.startswith("-"):
141+
line = "\\" + line
142+
formatted_lines.append(line)
143+
return "\n".join(formatted_lines)
125144

126145
def get_tldrs(self) -> list[str]:
127146
"""

0 commit comments

Comments
 (0)