21 lines
624 B
TypeScript
21 lines
624 B
TypeScript
import { onMounted, ref } from "vue";
|
|
import { useTheme } from "@/composables/useTheme";
|
|
import { type SqlHighlighter, createShikiSqlHighlighter, escapeHtml } from "@/lib/sql/sqlHighlighter";
|
|
|
|
export function useSqlHighlighter() {
|
|
const { isDark } = useTheme();
|
|
const sqlHighlighter = ref<SqlHighlighter>();
|
|
|
|
onMounted(async () => {
|
|
sqlHighlighter.value = await createShikiSqlHighlighter({
|
|
appearance: () => (isDark.value ? "dark" : "light"),
|
|
});
|
|
});
|
|
|
|
function highlight(sql: string): string {
|
|
return sqlHighlighter.value?.(sql) ?? escapeHtml(sql);
|
|
}
|
|
|
|
return { highlight, sqlHighlighter };
|
|
}
|