mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Add auto linking in Markdown components
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
@@ -2,6 +2,7 @@ import type { marked } from "marked";
|
||||
|
||||
import dompurify from "dompurify";
|
||||
import katexMarkedExtension from "marked-katex-extension";
|
||||
import markedLinkifyIt from "marked-linkify-it";
|
||||
import { Marked, Renderer as BaseRenderer } from "marked";
|
||||
|
||||
import emojis from "@app/lib/emojis";
|
||||
@@ -142,6 +143,7 @@ export class Renderer extends BaseRenderer {
|
||||
|
||||
const markedInstance = new Marked(
|
||||
katexMarkedExtension({ throwOnError: false }),
|
||||
markedLinkifyIt(),
|
||||
{
|
||||
extensions: [
|
||||
emojisMarkedExtension,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl } from "@httpd-client";
|
||||
|
||||
import Clipboard from "@app/components/Clipboard.svelte";
|
||||
import dompurify from "dompurify";
|
||||
|
||||
import Clipboard from "@app/components/Clipboard.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import markdown from "@app/lib/markdown";
|
||||
import { formatNodeId, twemoji } from "@app/lib/utils";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
@@ -11,10 +13,6 @@
|
||||
export let projectDescription: string;
|
||||
export let projectId: string;
|
||||
export let projectName: string;
|
||||
|
||||
const linkifyDescription = (text: string) => {
|
||||
return text.replaceAll(/(https?:\/\/[^\s]+)/g, `<a href="$1">$1</a>`);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -111,6 +109,6 @@
|
||||
<Clipboard small text={projectId} />
|
||||
</div>
|
||||
<div class="description" use:twemoji>
|
||||
{@html dompurify.sanitize(linkifyDescription(projectDescription))}
|
||||
{@html dompurify.sanitize(markdown.parse(projectDescription))}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user