aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shakya Majumdar <[email protected]>2022-01-10 17:21:15 +0530
committerGravatar Shakya Majumdar <[email protected]>2022-01-10 17:21:15 +0530
commit8c849136a1bbcdaf367851fac2bf5d4716717325 (patch)
tree729f2d7de4ff3df3d428edb106d6337612801133
parentrun isort and flake8 (diff)
format error messages in codeblocks
-rw-r--r--bot/exts/fun/latex/_latex_cog.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/bot/exts/fun/latex/_latex_cog.py b/bot/exts/fun/latex/_latex_cog.py
index 9ab85238..0cd4c981 100644
--- a/bot/exts/fun/latex/_latex_cog.py
+++ b/bot/exts/fun/latex/_latex_cog.py
@@ -3,6 +3,7 @@ import hashlib
import re
import sys
from pathlib import Path
+from textwrap import dedent
import discord
from discord.ext import commands
@@ -31,6 +32,18 @@ def _prepare_input(text: str) -> str:
return text
+def _format_err(text: str) -> str:
+ # prevent escaping the codeblock by inserting a zero-width-joiner
+ text = text.replace("`", "`\u200d")
+ return dedent(
+ f"""
+ ```
+ {text}
+ ```
+ """
+ ).strip()
+
+
class Latex(commands.Cog):
"""Renders latex."""
@@ -55,6 +68,6 @@ class Latex(commands.Cog):
if return_code != 0:
image_path.unlink()
err = (await proc.stderr.read()).decode()
- raise commands.BadArgument(err)
+ raise commands.BadArgument(_format_err(err))
await ctx.send(file=discord.File(image_path, "latex.png"))