From 649b816853ef018b0b1da293711fa9b7e580838e Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 19 Jul 2025 15:19:20 -0500 Subject: [PATCH 1/3] Show raw profiles as markdown code block --- Cogs/Profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cogs/Profile.py b/Cogs/Profile.py index f5473cf7..3602eb7d 100644 --- a/Cogs/Profile.py +++ b/Cogs/Profile.py @@ -116,7 +116,7 @@ async def _get_profile_reply(self,ctx,name=None,raw=False): DisplayName.name(member), "Raw " if raw else "", Nullify.escape_all(item['Name']), - discord.utils.escape_markdown(item['URL']) if raw else item['URL'] + "```markdown\n{}\n```".format(item['URL']) if raw else item['URL'] ) return await ctx.send(Utils.suppressed(ctx,msg)) From c20b912836c040afcd8cfad05647862eff6d9def Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 19 Jul 2025 15:56:23 -0500 Subject: [PATCH 2/3] Replace multiline codeblock quotes in the raw profile content before formatting in $rawprofile --- Cogs/Profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cogs/Profile.py b/Cogs/Profile.py index 3602eb7d..0a36e11c 100644 --- a/Cogs/Profile.py +++ b/Cogs/Profile.py @@ -116,7 +116,7 @@ async def _get_profile_reply(self,ctx,name=None,raw=False): DisplayName.name(member), "Raw " if raw else "", Nullify.escape_all(item['Name']), - "```markdown\n{}\n```".format(item['URL']) if raw else item['URL'] + "```markdown\n{}\n```".format(item['URL'].replace("```", "`\u200b``")) if raw else item['URL'] ) return await ctx.send(Utils.suppressed(ctx,msg)) From 66fabbf33fff38d4cf06c9f769a8b3810d94da96 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 19 Jul 2025 21:17:12 -0500 Subject: [PATCH 3/3] Format via escaping instead of using a markdown code block for $rawprofile --- Cogs/Profile.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Cogs/Profile.py b/Cogs/Profile.py index 0a36e11c..134aa8aa 100644 --- a/Cogs/Profile.py +++ b/Cogs/Profile.py @@ -1,4 +1,5 @@ import asyncio, discord, time, shutil, os, tempfile, json +import re from operator import itemgetter from discord.ext import commands from Cogs import Utils, Settings, ReadableTime, DisplayName, Message, Nullify, PickList, DL @@ -112,11 +113,28 @@ async def _get_profile_reply(self,ctx,name=None,raw=False): if item is None: # Just got a member - list their profiles return await self._list_profiles(ctx,member.id) + def _format_codeblock(contents=""): + return "```markdown\n{}\n```".format(contents.replace("```", "`\uFEFF`\uFEFF`")) + def _format_raw(contents=""): # Format the contents to properly display all characters without letting Discord format it. + contents = discord.utils.escape_markdown(item['URL']) + pattern = re.compile(r"(#{1,3}|-#|-\s*|>(>>)?) ") + number_prefix_pattern = re.compile(r"\d+\. [^\n]+") + lines = [] + for line in contents.splitlines(): + if number_prefix_pattern.search(line): + i = line.find(".") + if i != -1: + line = line[:i] + "\\" + line[i:] # Escape number lists manually + elif pattern.search(line): + line = "\\" + line + lines.append(line) + contents = "\n".join(lines) + return contents msg = '*{}\'s {}{} Profile:*\n\n{}'.format( DisplayName.name(member), "Raw " if raw else "", Nullify.escape_all(item['Name']), - "```markdown\n{}\n```".format(item['URL'].replace("```", "`\u200b``")) if raw else item['URL'] + _format_raw(item['URL']) if raw else item['URL'] ) return await ctx.send(Utils.suppressed(ctx,msg))