feat: add some highlighting to markdown renderer

This commit is contained in:
2023-08-02 17:21:03 +02:00
parent 21871a72e6
commit 70d16913f3
10 changed files with 485 additions and 15 deletions

View File

@ -16,6 +16,7 @@ export default function App({ Component }: AppProps) {
rel="stylesheet"
/>
<link href="/global.css" rel="stylesheet" />
<link href="/prism-material-dark.css" rel="stylesheet" />
</Head>
<Component />
</>

View File

@ -73,6 +73,12 @@ async function processCreateArticle(
return `![${alt}](${url.origin}${src.replace(/$\//, "")})`;
}
if (!src.startsWith("https://") && !src.startsWith("http://")) {
return `![${alt}](${url.origin.replace(/\/$/, "")}/${
src.replace(/^\//, "")
})`;
}
return `![${alt}](${src})`;
},
});
@ -87,9 +93,16 @@ async function processCreateArticle(
}
if (href.startsWith("#")) {
if (content.length < 2) return "";
return `[${content}](${url.href}#${href})`.replace("##", "#");
}
if (!href.startsWith("https://") && !href.startsWith("http://")) {
return `[${content}](${url.origin.replace(/\/$/, "")}/${
href.replace(/^\//, "")
})`;
}
return `[${content}](${href})`;
},
});

View File

@ -42,7 +42,9 @@ export default function Greet(props: PageProps<Article>) {
<YoutubePlayer link={article.meta.link} />
)}
<pre
class="whitespace-break-spaces"
class="whitespace-break-spaces markdown-body"
data-color-mode="dark"
data-dark-theme="dark"
dangerouslySetInnerHTML={{ __html: article.content || "" }}
>
{article.content||""}