From 99cd13ccf114179f4a188018223cd57435330a76 Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Tue, 28 May 2024 20:35:25 -0400 Subject: [PATCH] feat(seautils): add correct formatting for masked links --- seautils/seautils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/seautils/seautils.py b/seautils/seautils.py index a32d02c..9200927 100644 --- a/seautils/seautils.py +++ b/seautils/seautils.py @@ -8,6 +8,7 @@ import asyncio import inspect import operator +import re from asyncio.subprocess import Process from functools import partial, partialmethod from typing import Any @@ -28,6 +29,9 @@ from redbot.core.utils.views import SimpleMenu def md(soup: BeautifulSoup, **options) -> Any | str: return MarkdownConverter(**options).convert_soup(soup) +def convert_rfc_references(text: str): + return re.sub(r"\(RFC\s(\d+)\)", r"(https://www.rfc-editor.org/rfc/rfc\1.html)", text) + class SeaUtils(commands.Cog): """A collection of random utilities.""" @@ -204,15 +208,16 @@ class SeaUtils(commands.Cog): pre_tags = soup.find_all('pre') content = [] for pre_tag in pre_tags: + text = convert_rfc_references(md(pre_tag)) if await ctx.embed_requested(): embed = Embed( title="RFC Document", - description=md(pre_tag), + description=text, color=await ctx.embed_color() ) content.append(embed) else: - content.append(md(pre_tag)) + content.append(text) await SimpleMenu(pages=content, disable_after_timeout=True, timeout=300).start(ctx) else: await ctx.maybe_send_embed(content=cf.error(f"An error occurred while fetching RFC {number}. Status code: {response.status}."))