2023-01-05 18:18:07 +09:00
|
|
|
import { marked } from "https://deno.land/x/marked@1.0.1/mod.ts";
|
|
|
|
|
|
|
|
export function MarkdownRenderer(props: { text: string | undefined }) {
|
2023-01-06 18:24:27 +09:00
|
|
|
let text = props.text;
|
|
|
|
if (text === undefined) {
|
|
|
|
text = "";
|
|
|
|
}
|
2023-01-06 22:17:45 +09:00
|
|
|
let c = text;
|
2023-01-07 02:37:35 +09:00
|
|
|
let meta = null;
|
2023-01-06 22:17:45 +09:00
|
|
|
if (text.startsWith("---")) {
|
|
|
|
const index = text.indexOf("\n---", 3);
|
2023-01-07 02:37:35 +09:00
|
|
|
meta = text.slice(4, index);
|
2023-01-06 22:17:45 +09:00
|
|
|
c = text.slice(index + 4, text.length);
|
|
|
|
}
|
2023-01-14 03:03:58 +09:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{meta
|
|
|
|
? (
|
|
|
|
<div>
|
|
|
|
<h2>Meta</h2>
|
|
|
|
<pre>{meta}</pre>
|
|
|
|
<hr class="mt-2 mb-2"></hr>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
: <div></div>}
|
|
|
|
<div
|
|
|
|
class="markdown-body"
|
|
|
|
dangerouslySetInnerHTML={{ __html: marked.parse(c) }}
|
2023-01-07 02:37:35 +09:00
|
|
|
>
|
2023-01-14 03:03:58 +09:00
|
|
|
</div>
|
|
|
|
</>
|
2023-01-06 18:24:27 +09:00
|
|
|
);
|
2023-01-05 18:18:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export default MarkdownRenderer;
|