Skip to content

Commit

Permalink
Add colorScheme to style
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Oct 16, 2024
1 parent 6901dce commit 3b31ad4
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/dist/browser.esm.mjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type LighterResult = {
style: {
color: string;
background: string;
colorScheme: string;
};
};
type AnnotatedLighterResult = {
Expand All @@ -111,6 +112,7 @@ type AnnotatedLighterResult = {
style: {
color: string;
background: string;
colorScheme: string;
};
};

Expand Down
2 changes: 1 addition & 1 deletion lib/dist/index.esm.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/dist/worker.esm.mjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const prefixes = {
bat: "REM",
shaderlab: "//",
sas: "*",
clarity: ";;",
};

function getAnnotationsFromLine(
Expand Down
4 changes: 4 additions & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
Token,
} from "./annotations";
import { getTerminalStyle, highlightTerminal } from "./terminal";
import { getColorScheme } from "./theme-colors";

type Config = { scopes?: boolean };
type AnnotatedConfig = { annotations: Annotation[] } & Config;
Expand All @@ -41,6 +42,7 @@ type LighterResult = {
style: {
color: string;
background: string;
colorScheme: string;
};
};
type AnnotatedLighterResult = {
Expand All @@ -49,6 +51,7 @@ type AnnotatedLighterResult = {
style: {
color: string;
background: string;
colorScheme: string;
};
};

Expand Down Expand Up @@ -157,6 +160,7 @@ export function highlightSync(
: {
color: theme.foreground,
background: theme.background,
colorScheme: getColorScheme(theme),
};

if (isAnnotatedConfig(config)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FinalTheme } from "./theme";
import { Token } from "./annotations";
import { Color, createAnsiSequenceParser } from "ansi-sequence-parser";
import { getColor } from "./theme-colors";
import { getColor, getColorScheme } from "./theme-colors";

export function highlightTerminal(code: string, theme: FinalTheme): Token[][] {
const parser = createAnsiSequenceParser();
Expand Down Expand Up @@ -76,5 +76,6 @@ export function getTerminalStyle(theme: FinalTheme) {
return {
color: getColor(theme, "terminal.foreground"),
background: getColor(theme, "terminal.background"),
colorScheme: getColorScheme(theme),
};
}
24 changes: 24 additions & 0 deletions lib/test/__snapshots__/browser.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ exports[`extract annotation with inline global regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -385,6 +386,7 @@ exports[`extract annotation with inline regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -701,6 +703,7 @@ exports[`extract annotation with multiline inline regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -810,6 +813,7 @@ exports[`extract annottations 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -932,6 +936,7 @@ exports[`extract annottations from jsx 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1021,6 +1026,7 @@ exports[`extract annottations from mdx 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1069,6 +1075,7 @@ exports[`extract annottations from text 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1143,6 +1150,7 @@ exports[`extract annottations from txt 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1277,6 +1285,7 @@ exports[`extract annottations with prefix 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1427,6 +1436,7 @@ exports[`extract empty annotation with inline regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1511,6 +1521,7 @@ exports[`extract empty line annotation with regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1704,6 +1715,7 @@ exports[`extract line annotation with global regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1843,6 +1855,7 @@ exports[`extract line annotation with regex 2`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1917,6 +1930,7 @@ exports[`highlight html with theme 1`] = `
"style": {
"background": "#0d1117",
"color": "#c9d1d9",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -1949,6 +1963,7 @@ exports[`highlight js 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand All @@ -1967,6 +1982,7 @@ exports[`highlight terminal 1`] = `
"style": {
"background": "#0d1117",
"color": "#c9d1d9",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -2027,6 +2043,7 @@ exports[`highlight terminal ansi codes 1`] = `
"style": {
"background": "#0d1117",
"color": "#c9d1d9",
"colorScheme": "dark",
},
}
`;
Expand All @@ -2045,6 +2062,7 @@ exports[`highlight text 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand All @@ -2065,6 +2083,7 @@ exports[`highlight with empty theme 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#bbbbbb",
"colorScheme": "dark",
},
}
`;
Expand All @@ -2085,6 +2104,7 @@ exports[`highlight with frozen theme 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#bbbbbb",
"colorScheme": "dark",
},
}
`;
Expand All @@ -2105,6 +2125,7 @@ exports[`highlight with frozen theme with global setting 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#bbbbbb",
"colorScheme": "dark",
},
}
`;
Expand Down Expand Up @@ -2167,6 +2188,7 @@ exports[`highlight with scopes 1`] = `
"style": {
"background": "#0d1117",
"color": "#c9d1d9",
"colorScheme": "dark",
},
}
`;
Expand All @@ -2187,6 +2209,7 @@ exports[`null code 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Expand All @@ -2205,6 +2228,7 @@ exports[`null lang 1`] = `
"style": {
"background": "#1E1E1E",
"color": "#D4D4D4",
"colorScheme": "dark",
},
}
`;
Loading

0 comments on commit 3b31ad4

Please sign in to comment.