diff --git a/package.json b/package.json
index 2ca7ee04..b2c0e583 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
- "version": "1.0.1",
+ "version": "1.0.2",
"private": true,
"scripts": {
"dev": "vite dev",
diff --git a/src/lib/components/markdown/Markdown.svelte b/src/lib/components/markdown/Markdown.svelte
index 75095b61..0852821c 100644
--- a/src/lib/components/markdown/Markdown.svelte
+++ b/src/lib/components/markdown/Markdown.svelte
@@ -3,9 +3,27 @@
export let source: string = ''
export let inline: boolean = false
+
+ function replaceURLs(node: HTMLElement) {
+ const postRegex = /^https:\/\/([a-zA-Z0-9.-]+)\/post\/(\d+)$/
+
+ const links = node.querySelectorAll('a')
+
+ links.forEach((l) => {
+ if (!postRegex.test(l.href)) return
+
+ const match = l.href.match(postRegex)
+ if (!match) return
+
+ l.href = `/post/${match?.[1]}/${match?.[2]}`
+ })
+ }
-
+
{#if inline}
{@html mdInline.render(source)}
{:else}
diff --git a/src/lib/components/markdown/markdown.ts b/src/lib/components/markdown/markdown.ts
index fc7030b1..fc0a14c5 100644
--- a/src/lib/components/markdown/markdown.ts
+++ b/src/lib/components/markdown/markdown.ts
@@ -51,8 +51,8 @@ export const mdInline: MarkdownIt = new MarkdownIt('zero')
.use(markdown_it_sub)
.use(markdown_it_sup)
-md.linkify.add('!', {
- validate: function (text, pos, self) {
+const communityLinks = {
+ validate: function (text: any, pos: any, self: any) {
var tail = text.slice(pos)
if (!self.re.community) {
@@ -70,9 +70,22 @@ md.linkify.add('!', {
}
return 0
},
- normalize: function (match) {
- match.url = `/c/${match.url.slice(1)}`
+ normalize: function (match: any) {
+ let prefix = `${match.url}`
+ prefix = prefix.startsWith('c/') ? prefix.slice(2) : prefix.slice(1)
+
+ match.url = `/c/${prefix}`
},
+}
+
+md.linkify.add('!', {
+ validate: communityLinks.validate,
+ normalize: communityLinks.normalize,
+})
+
+md.linkify.add('c/', {
+ validate: communityLinks.validate,
+ normalize: communityLinks.normalize,
})
md.linkify.add('@', {
@@ -96,4 +109,3 @@ md.linkify.add('@', {
match.url = `/u/${match.url.slice(1)}`
},
})
-