1
0
Fork 0

[Feat] Added support for custom highlight themes

feature/custom-highlight-themes
Marco Kutscha 2024-02-24 12:58:41 +01:00
parent 3b8f8e49d0
commit 5c82d48f44
6 changed files with 17 additions and 1 deletions

View File

@ -63,6 +63,7 @@ There is a default config:
preview_title = "CodeSnap.nvim", -- (Optional) preview page title preview_title = "CodeSnap.nvim", -- (Optional) preview page title
editor_font_family = "CaskaydiaCove Nerd Font", -- (Optional) preview code font family editor_font_family = "CaskaydiaCove Nerd Font", -- (Optional) preview code font family
watermark_font_family = "Pacifico", -- (Optional) watermark font family watermark_font_family = "Pacifico", -- (Optional) watermark font family
highlight_theme = "atom-one-dark", -- (Optional) theme for code highlights
} }
``` ```

View File

@ -8,6 +8,7 @@ return {
preview_title = "CodeSnap.nvim", preview_title = "CodeSnap.nvim",
editor_font_family = "CaskaydiaCove Nerd Font", editor_font_family = "CaskaydiaCove Nerd Font",
watermark_font_family = "Pacifico", watermark_font_family = "Pacifico",
highlight_theme = "atom-one-dark",
auto_load = true, auto_load = true,
}, },
cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))), cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))),

View File

@ -9,6 +9,7 @@ import { getWebsocketHost } from "./utils";
const CODE_EMPTY_PLACEHOLDER = `print "Hello, CodeSnap.nvim!"`; const CODE_EMPTY_PLACEHOLDER = `print "Hello, CodeSnap.nvim!"`;
const WATER_MARK_PLACEHOLDER = "CodeSnap.nvim"; const WATER_MARK_PLACEHOLDER = "CodeSnap.nvim";
const PREVIEW_TITLE_PLACEHOLDER = "CodeSnap.nvim"; const PREVIEW_TITLE_PLACEHOLDER = "CodeSnap.nvim";
const DEFAULT_THEME = "atom-one-dark";
function App() { function App() {
const [socketUrl] = useState(`ws://${getWebsocketHost()}/ws`); const [socketUrl] = useState(`ws://${getWebsocketHost()}/ws`);
@ -69,6 +70,18 @@ function App() {
document.title = config?.preview_title ?? PREVIEW_TITLE_PLACEHOLDER; 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 ( return (
<div className="w-full h-full flex flex-col items-center bg-deep-gray"> <div className="w-full h-full flex flex-col items-center bg-deep-gray">
<p className="rainbow-text text-4xl font-extrabold mt-20"> <p className="rainbow-text text-4xl font-extrabold mt-20">

View File

@ -8,6 +8,7 @@ export interface Config {
preview_title: string; preview_title: string;
watermark_font_family: string; watermark_font_family: string;
editor_font_family: string; editor_font_family: string;
highlight_theme: string;
} }
const CONFIG_STORAGE_KEY = "CONFIG_STORAGE_KEY"; const CONFIG_STORAGE_KEY = "CONFIG_STORAGE_KEY";

View File

@ -1,7 +1,6 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import "./output.css"; import "./output.css";
import "highlight.js/styles/atom-one-dark.css";
import App from "./app"; import App from "./app";
import reportWebVitals from "./reportWebVitals"; import reportWebVitals from "./reportWebVitals";

View File

@ -9,6 +9,7 @@ pub struct Config {
preview_title: String, preview_title: String,
watermark_font_family: String, watermark_font_family: String,
editor_font_family: String, editor_font_family: String,
highlight_theme: String,
} }
impl From<&str> for Config { impl From<&str> for Config {