diff --git a/app/modules/rehype-momiji/buildCodeBlockHTML.ts b/app/modules/rehype-momiji/buildCodeBlockHTML.ts index eaf41e7..d744c7b 100644 --- a/app/modules/rehype-momiji/buildCodeBlockHTML.ts +++ b/app/modules/rehype-momiji/buildCodeBlockHTML.ts @@ -6,13 +6,20 @@ import { COLOR_SHIRONERI, COLOR_HAI } from "./colors"; import { visit } from "unist-util-visit"; const defaultHighlighter = await getHighlighter({ themes: bundledThemes, langs: bundledLanguages }); -const defaultFilenameUIColor = `color: ${COLOR_SHIRONERI}; background-color: ${COLOR_HAI};`; -const buildCodeBlockHTML = (rawCode: string, lang: string, filename: string, theme: BundledTheme) => { +const buildCodeBlockHTML = ( + rawCode: string, + lang: string, + theme: BundledTheme, + filename: string, + filenameBGColor?: string, + filenameTextColor?: string, +) => { const hast = defaultHighlighter.codeToHast(rawCode, { lang: lang, theme: theme, }); + const filenameColorStyle = `background-color: ${filenameBGColor ?? COLOR_HAI}; color: ${filenameTextColor ?? COLOR_SHIRONERI};`; // Add filename to the code block if it exists if (filename === "") { @@ -36,7 +43,7 @@ const buildCodeBlockHTML = (rawCode: string, lang: string, filename: string, the type: "element", tagName: "div", properties: { - style: `width: fit-content; margin-bottom: 16px; padding: 4px 8px; font-size: 14px; border-radius: 0 0 4px 4px; ${defaultFilenameUIColor};`, + style: `width: fit-content; margin-bottom: 16px; padding: 4px 8px; font-size: 14px; border-radius: 0 0 4px 4px; ${filenameColorStyle}`, }, children: [ { diff --git a/app/modules/rehype-momiji/rehypeMomiji.ts b/app/modules/rehype-momiji/rehypeMomiji.ts index 63ad1c4..a3544ab 100644 --- a/app/modules/rehype-momiji/rehypeMomiji.ts +++ b/app/modules/rehype-momiji/rehypeMomiji.ts @@ -7,13 +7,18 @@ import { parser } from "./parser"; import { isArray, isObject, isString } from "./utils/checkTypeOfOperandValue"; import { buildCodeBlockHTML } from "./buildCodeBlockHTML"; -type Options = { theme: BundledTheme; fallbackLang?: BundledLanguage }; +type Options = { + theme?: BundledTheme; + fallbackLang?: BundledLanguage; + filenameBGColor?: string; + filenameTextColor?: string; +}; const defaultHighlighter = await getHighlighter({ themes: bundledThemes, langs: bundledLanguages }); -const rehypeMomiji: Plugin = (options: Options = { theme: "github-dark-default", fallbackLang: "c" }) => { +const rehypeMomiji: Plugin = (options: Options = {}) => { const langs = defaultHighlighter.getLoadedLanguages(); - const { theme, fallbackLang } = options; + const { theme = "github-dark-default", fallbackLang = "c", filenameBGColor, filenameTextColor } = options; const parseLanguage = (classNames: string[]): string | undefined => { for (const className of classNames) { @@ -65,7 +70,14 @@ const rehypeMomiji: Plugin = (options: Options = { theme: "github-dark-default", const filename = (codeElem.properties["data-remark-code-filename"] as string) ?? ""; - const highlightCode = buildCodeBlockHTML(rawCode, supportedLang, filename, theme); + const highlightCode = buildCodeBlockHTML( + rawCode, + supportedLang, + theme, + filename, + filenameBGColor, + filenameTextColor, + ); const container = `