summaryrefslogtreecommitdiffstats
path: root/src/server/template/syntax.ts
blob: 82b37e8ae6276de9d6378a728bce4eee0268e138 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import hljs from "highlight.js"
import { data, Attribute, code as Code } from "./html.js"
import { c } from "./vdom.js"

interface Syntax extends Attribute {
	lang: string
}

export default function code({ lang, ...attr }: Syntax, content: string) {
	return c(
		Code,
		{
			class: attr.class ?? "hljs",
			...attr
		},
		data(hljs.highlight(content,{ language: lang }).value)
	)
}