Convert URLs in project descriptions to anchor tags

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-01-06 15:51:27 +01:00
parent 972b5ccf20
commit c7cb461586
+12 -1
View File
@@ -3,12 +3,17 @@
import Avatar from "@app/components/Avatar.svelte";
import Clipboard from "@app/components/Clipboard.svelte";
import DOMPurify from "dompurify";
import Link from "@app/components/Link.svelte";
import ProjectLink from "@app/components/ProjectLink.svelte";
import { formatSeedId } from "@app/lib/utils";
export let project: Project;
export let peer: PeerId | null = null;
const linkifyDescription = (text: string) => {
return text.replaceAll(/(https?:\/\/[^\s]+)/g, `<a href="$1">$1</a>`);
};
</script>
<style>
@@ -52,6 +57,10 @@
margin: 1rem 0 1.5rem 0;
}
.description :global(a) {
border-bottom: 1px solid var(--color-foreground-6);
}
.content {
padding: 0 2rem 0 8rem;
}
@@ -112,5 +121,7 @@
<span class="truncate">{project.id}</span>
<Clipboard small text={project.id} />
</div>
<div class="description">{project.description}</div>
<div class="description">
{@html DOMPurify.sanitize(linkifyDescription(project.description))}
</div>
</header>