feat: add Fandom -> Phantom replacement support
This commit is contained in:
@@ -15,6 +15,8 @@ let
|
|||||||
xLinkRegex = re"""<a href="https:\/\/x.com([^"]+)">x\.com(\S+)</a>"""
|
xLinkRegex = re"""<a href="https:\/\/x.com([^"]+)">x\.com(\S+)</a>"""
|
||||||
imgurRegex = re"(?<=(?<!\S)https:\/\/|(?<=\s))(i\.)?imgur\.com"
|
imgurRegex = re"(?<=(?<!\S)https:\/\/|(?<=\s))(i\.)?imgur\.com"
|
||||||
imgurLinkRegex = re"""<a href="https://(i\.)?imgur.com([^"]+)">(i\.)?imgur\.com(\S+)</a>"""
|
imgurLinkRegex = re"""<a href="https://(i\.)?imgur.com([^"]+)">(i\.)?imgur\.com(\S+)</a>"""
|
||||||
|
fandomRegex = re"(?<=(?<!\S)https:\/\/|(?<=\s))([a-z0-9-]+)\.fandom\.com"
|
||||||
|
fandomLinkRegex = re"""<a href="https://([a-z0-9-]+)\.fandom\.com([^"]+)">([a-z0-9-]+)\.fandom\.com(\S+)</a>"""
|
||||||
|
|
||||||
ytRegex = re(r"([A-z.]+\.)?youtu(be\.com|\.be)", {reStudy, reIgnoreCase})
|
ytRegex = re(r"([A-z.]+\.)?youtu(be\.com|\.be)", {reStudy, reIgnoreCase})
|
||||||
|
|
||||||
@@ -80,6 +82,11 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string =
|
|||||||
result = result.replacef(imgurLinkRegex, a(
|
result = result.replacef(imgurLinkRegex, a(
|
||||||
prefs.replaceImgur & "$4", href = https & prefs.replaceImgur & "$2"))
|
prefs.replaceImgur & "$4", href = https & prefs.replaceImgur & "$2"))
|
||||||
|
|
||||||
|
if prefs.replaceFandom.len > 0 and "fandom.com" in result:
|
||||||
|
result = result.replace(fandomRegex, prefs.replaceFandom & "/$1")
|
||||||
|
result = result.replacef(fandomLinkRegex, a(
|
||||||
|
prefs.replaceFandom & "/$1$2", href = https & prefs.replaceFandom & "/$1$2"))
|
||||||
|
|
||||||
if prefs.replaceReddit.len > 0 and ("reddit.com" in result or "redd.it" in result):
|
if prefs.replaceReddit.len > 0 and ("reddit.com" in result or "redd.it" in result):
|
||||||
result = result.replace(rdShortRegex, prefs.replaceReddit & "/comments/")
|
result = result.replace(rdShortRegex, prefs.replaceReddit & "/comments/")
|
||||||
result = result.replace(rdRegex, prefs.replaceReddit)
|
result = result.replace(rdRegex, prefs.replaceReddit)
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ genPrefs:
|
|||||||
"Imgur -> Rimgo"
|
"Imgur -> Rimgo"
|
||||||
placeholder: "Rimgo hostname"
|
placeholder: "Rimgo hostname"
|
||||||
|
|
||||||
|
replaceFandom(input, ""):
|
||||||
|
"Fandom -> Phantom"
|
||||||
|
placeholder: "Phantom hostname"
|
||||||
|
|
||||||
iterator allPrefs*(): Pref =
|
iterator allPrefs*(): Pref =
|
||||||
for k, v in prefList:
|
for k, v in prefList:
|
||||||
for pref in v:
|
for pref in v:
|
||||||
|
|||||||
Reference in New Issue
Block a user