feat: switch to svelte-markdown
This commit is contained in:
1 parent
2b642b0926
commit
98a899c596
27 files changed
+510
-139
No files matched your search
@@ -86,3 +86,36 @@ export const linkify = markedLinkifyIt(
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
const regexes = {
|
||||
post: /^https:\/\/([a-zA-Z0-9.-]+)\/post\/(\d+)$/i,
|
||||
comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i,
|
||||
user: /^https:\/\/([a-zA-Z0-9.-]+)(\/u\/)([a-zA-Z0-9.-_]+)$/i,
|
||||
community: /^https:\/\/([a-zA-Z0-9.-]+)(\/c\/)([a-zA-Z0-9.-_]+)$/i,
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert links to photon links
|
||||
*/
|
||||
export const photonify = (link: string) => {
|
||||
if (regexes.post.test(link)) {
|
||||
const match = link.match(regexes.post)
|
||||
if (!match) return
|
||||
return `/post/${match?.[1]}/${match?.[2]}`
|
||||
}
|
||||
if (regexes.comment.test(link)) {
|
||||
const match = link.match(regexes.comment)
|
||||
if (!match) return
|
||||
return `/comment/${match?.[1]}/${match?.[2]}`
|
||||
}
|
||||
if (regexes.user.test(link)) {
|
||||
const match = link.match(regexes.user)
|
||||
if (!match) return
|
||||
return `/u/${match?.[3]}@${match?.[1]}`
|
||||
}
|
||||
if (regexes.community.test(link)) {
|
||||
const match = link.match(regexes.community)
|
||||
if (!match) return
|
||||
return `/c/${match?.[3]}@${match?.[1]}`
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user