mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[Dev] Friendlier code-block strip for [p]eval(#2017)
not relying on newlines where they aren't required by discord, retaining py highlight support. Resolves #1928.
This commit is contained in:
parent
6082eb21e3
commit
7acea29cdb
@ -3,6 +3,7 @@ import inspect
|
||||
import io
|
||||
import textwrap
|
||||
import traceback
|
||||
import re
|
||||
from contextlib import redirect_stdout
|
||||
from copy import copy
|
||||
|
||||
@ -21,6 +22,8 @@ https://github.com/Rapptz/RoboDanny/blob/master/cogs/repl.py
|
||||
|
||||
_ = Translator("Dev", __file__)
|
||||
|
||||
START_CODE_BLOCK_RE = re.compile(r"^((```py)(?=\s)|(```))")
|
||||
|
||||
|
||||
class Dev:
|
||||
"""Various development focused utilities."""
|
||||
@ -34,7 +37,7 @@ class Dev:
|
||||
"""Automatically removes code blocks from the code."""
|
||||
# remove ```py\n```
|
||||
if content.startswith("```") and content.endswith("```"):
|
||||
return "\n".join(content.split("\n")[1:-1])
|
||||
return START_CODE_BLOCK_RE.sub("", content)[:-3]
|
||||
|
||||
# remove `foo`
|
||||
return content.strip("` \n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user