-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
46 lines (39 loc) · 1.16 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Snippet } from '@sharingan/database';
import { generateNoSnippetHtmlContent, generateSnippetHtmlContent } from './content/html-generator';
import { generateHTMLPreview } from './content/preview-template';
import { Shiki } from './types';
type Args = {
options: {
scriptUrl: string;
styleUrl: string;
webAppUrl: string;
};
shiki: Shiki;
snippet: Snippet | null;
};
export const renderSnippetToHtml = async ({ options, shiki, snippet }: Args): Promise<string> => {
const STYLE_URL = options.styleUrl;
const SCRIPT_URL = options.scriptUrl;
const WEBAPP_URL = options.webAppUrl;
if (!snippet) {
const code = generateNoSnippetHtmlContent(WEBAPP_URL);
return generateHTMLPreview({
code,
rawCode: '',
scriptUrl: SCRIPT_URL,
styleUrl: STYLE_URL,
title: 'Not found',
webAppUrl: WEBAPP_URL,
});
}
const { backgroundColor, html } = await generateSnippetHtmlContent({ shiki, snippet });
return generateHTMLPreview({
code: html,
color: backgroundColor,
rawCode: snippet.content,
scriptUrl: SCRIPT_URL,
styleUrl: STYLE_URL,
title: snippet.name,
webAppUrl: WEBAPP_URL,
});
};