Skip to content

Commit

Permalink
[Feat] Added support for custom highlight themes
Browse files Browse the repository at this point in the history
  • Loading branch information
marqmitk committed Feb 24, 2024
1 parent 3b8f8e4 commit 5c82d48
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ There is a default config:
preview_title = "CodeSnap.nvim", -- (Optional) preview page title
editor_font_family = "CaskaydiaCove Nerd Font", -- (Optional) preview code font family
watermark_font_family = "Pacifico", -- (Optional) watermark font family
highlight_theme = "atom-one-dark", -- (Optional) theme for code highlights
}
```

Expand Down
1 change: 1 addition & 0 deletions lua/codesnap/static.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ return {
preview_title = "CodeSnap.nvim",
editor_font_family = "CaskaydiaCove Nerd Font",
watermark_font_family = "Pacifico",
highlight_theme = "atom-one-dark",
auto_load = true,
},
cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))),
Expand Down
13 changes: 13 additions & 0 deletions snap-client/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getWebsocketHost } from "./utils";
const CODE_EMPTY_PLACEHOLDER = `print "Hello, CodeSnap.nvim!"`;
const WATER_MARK_PLACEHOLDER = "CodeSnap.nvim";
const PREVIEW_TITLE_PLACEHOLDER = "CodeSnap.nvim";
const DEFAULT_THEME = "atom-one-dark";

function App() {
const [socketUrl] = useState(`ws://${getWebsocketHost()}/ws`);
Expand Down Expand Up @@ -69,6 +70,18 @@ function App() {
document.title = config?.preview_title ?? PREVIEW_TITLE_PLACEHOLDER;
}, []);

useEffect(() => {
const theme = config?.highlight_theme ?? DEFAULT_THEME;
const cssLink = document.createElement("link");
cssLink.rel = "stylesheet";
cssLink.href = "https://cdn.jsdelivr.net/npm/highlight.js/styles/" + theme + ".css";
document.head.appendChild(cssLink);
return () => {
document.head.removeChild(cssLink);
};
}
, [config?.highlight_theme]);

return (
<div className="w-full h-full flex flex-col items-center bg-deep-gray">
<p className="rainbow-text text-4xl font-extrabold mt-20">
Expand Down
1 change: 1 addition & 0 deletions snap-client/src/hooks/use-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Config {
preview_title: string;
watermark_font_family: string;
editor_font_family: string;
highlight_theme: string;
}

const CONFIG_STORAGE_KEY = "CONFIG_STORAGE_KEY";
Expand Down
1 change: 0 additions & 1 deletion snap-client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import ReactDOM from "react-dom/client";
import "./output.css";
import "highlight.js/styles/atom-one-dark.css";
import App from "./app";
import reportWebVitals from "./reportWebVitals";

Expand Down
1 change: 1 addition & 0 deletions snap-server/src/event_handler/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Config {
preview_title: String,
watermark_font_family: String,
editor_font_family: String,
highlight_theme: String,
}

impl From<&str> for Config {
Expand Down

0 comments on commit 5c82d48

Please sign in to comment.