Skip to content

Commit 2a2533e

Browse files
committed
feat: refine editor layout and paste styling
1 parent 7272847 commit 2a2533e

8 files changed

Lines changed: 379 additions & 129 deletions

File tree

src/app.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
:root {
22
color-scheme: dark;
33
font-family:
4-
Inter,
4+
Pretendard,
5+
"Noto Sans KR",
6+
"Noto Sans CJK KR",
7+
SUIT,
58
ui-sans-serif,
69
system-ui,
710
-apple-system,
811
BlinkMacSystemFont,
912
"Segoe UI",
13+
"Malgun Gothic",
1014
sans-serif;
1115
background: oklch(19.13% 0 0);
1216
color: oklch(96.01% 0.018 89.72);

src/lib/dc/font-stacks.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,13 @@ const codeSignals = new Set([
3636
]);
3737

3838
export const proseFallbackFonts = [
39-
"Malgun Gothic",
40-
"맑은 고딕",
41-
"Apple SD Gothic Neo",
42-
"AppleGothic",
4339
"Pretendard",
40+
"Noto Sans KR",
41+
"Noto Sans CJK KR",
4442
"SUIT",
4543
"Wanted Sans",
4644
"Spoqa Han Sans Neo",
4745
"Spoqa Han Sans",
48-
"Noto Sans CJK KR",
49-
"Noto Sans KR",
50-
"Noto Sans",
5146
"Source Han Sans K",
5247
"Source Han Sans KR",
5348
"본고딕",
@@ -62,7 +57,12 @@ export const proseFallbackFonts = [
6257
"IBM Plex Sans KR",
6358
"Gmarket Sans",
6459
"Arial Unicode MS",
60+
"Apple SD Gothic Neo",
61+
"AppleGothic",
6562
"Segoe UI",
63+
"Malgun Gothic",
64+
"맑은 고딕",
65+
"Noto Sans",
6666
"Arial",
6767
"Helvetica Neue",
6868
"Helvetica",
@@ -88,7 +88,10 @@ export const serifFallbackFonts = [
8888
] as const;
8989

9090
export const codeFallbackFonts = [
91-
"Consolas",
91+
"Cascadia Mono",
92+
"Cascadia Code",
93+
"Cascadia Mono PL",
94+
"Cascadia Code PL",
9295
"D2Coding",
9396
"D2Coding ligature",
9497
"D2CodingLigature",
@@ -102,10 +105,6 @@ export const codeFallbackFonts = [
102105
"Source Han Mono KR",
103106
"Sarasa Mono K",
104107
"Sarasa Gothic K",
105-
"Cascadia Mono",
106-
"Cascadia Code",
107-
"Cascadia Mono PL",
108-
"Cascadia Code PL",
109108
"JetBrains Mono",
110109
"Fira Code",
111110
"Fira Mono",
@@ -121,6 +120,7 @@ export const codeFallbackFonts = [
121120
"Liberation Mono",
122121
"Ubuntu Mono",
123122
"Bitstream Vera Sans Mono",
123+
"Consolas",
124124
"SFMono-Regular",
125125
"Menlo",
126126
"Monaco",
@@ -199,23 +199,21 @@ export function buildFontStack(
199199
primaryFonts: readonly string[],
200200
mode: "prose" | "code" = "prose",
201201
): string {
202+
const normalizedPrimaryFonts = primaryFonts.map(normalizeFontName).filter(Boolean);
203+
202204
return appendFallbackFonts(
203-
primaryFonts.map(normalizeFontName).filter(Boolean),
204-
fallbackFontsFor(primaryFonts, mode),
205+
mode === "code" ? [] : normalizedPrimaryFonts,
206+
fallbackFontsFor(normalizedPrimaryFonts, mode),
205207
);
206208
}
207209

208-
export function safeProseFontFamily(value: string): string {
210+
export function safeProseFontFamily(value = ""): string {
209211
return buildFontStack(parseFontFamily(value), "prose");
210212
}
211213

212214
export function safeCodeFontFamily(value = ""): string {
213215
return buildFontStack(parseFontFamily(value), "code");
214216
}
215217

216-
export const fontFamilyOptions = [
217-
{ label: "맑은 고딕", value: buildFontStack(["Malgun Gothic"]) },
218-
{ label: "고운 본문", value: buildFontStack(["Georgia", "Times New Roman"]) },
219-
{ label: "둥근 산스", value: buildFontStack(["Pretendard", "Inter"]) },
220-
{ label: "코드", value: buildFontStack(["Consolas"], "code") },
221-
] as const;
218+
export const defaultProseFontFamily = safeProseFontFamily();
219+
export const defaultCodeFontFamily = safeCodeFontFamily();

src/lib/dc/render-dc-html.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ export function renderDcHtml(input: DcRenderInput): string {
7676
const foreground = sanitizeColor(input.foreground, fallbackForeground);
7777
const filename = input.filename?.trim();
7878
const hasDecorations = input.lineDecorations?.some(Boolean) ?? false;
79+
const codeFontFamily = safeCodeFontFamily();
7980
const preStyle = joinStyle({
8081
"background-color": input.showBackground ? background : undefined,
8182
color: foreground,
82-
"font-family": safeCodeFontFamily(),
83+
"font-family": codeFontFamily,
8384
"font-size": input.fontSize ?? "14px",
8485
"line-height": "1.58",
8586
margin: filename ? 0 : "0 0 16px",
@@ -89,6 +90,17 @@ export function renderDcHtml(input: DcRenderInput): string {
8990
"overflow-wrap": "anywhere",
9091
"tab-size": 4,
9192
});
93+
const codeStyle = joinStyle({
94+
background: "none",
95+
color: "inherit",
96+
"font-family": codeFontFamily,
97+
"font-size": "inherit",
98+
"line-height": "inherit",
99+
"white-space": "inherit",
100+
"word-break": "inherit",
101+
"overflow-wrap": "inherit",
102+
"tab-size": 4,
103+
});
92104

93105
const lineNumberWidth = `${Math.max(2, String(input.lines.length).length)}ch`;
94106
const renderedLines = input.lines.map((line, index) => {
@@ -128,7 +140,7 @@ export function renderDcHtml(input: DcRenderInput): string {
128140
return `<span style="${lineStyle}">${content}</span>`;
129141
});
130142

131-
const code = `<pre style="${preStyle}"><code>${renderedLines.join("\n")}</code></pre>`;
143+
const code = `<pre style="${preStyle}"><code style="${codeStyle}">${renderedLines.join("\n")}</code></pre>`;
132144

133145
if (!filename) {
134146
return code;
@@ -144,7 +156,7 @@ export function renderDcHtml(input: DcRenderInput): string {
144156
display: "block",
145157
"background-color": "oklch(20.16% 0.018 257.49)",
146158
color: "oklch(89.72% 0.019 247.91)",
147-
"font-family": safeCodeFontFamily(),
159+
"font-family": codeFontFamily,
148160
"font-size": "12px",
149161
"font-weight": 800,
150162
"line-height": 1.2,

0 commit comments

Comments
 (0)