diff options
| author | mo khan <mo@mokhan.ca> | 2026-01-30 20:27:55 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2026-01-30 20:27:55 -0700 |
| commit | 94476e4f0e154677d6fd536a3103379e5d51e2f6 (patch) | |
| tree | 585e042d6443572a829ed07cfdabe1fd696eaffb /internal | |
| parent | f51476f56bd40660d51aea9df6f5f31d36fa59dc (diff) | |
feat: add command to generate css files
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/generator/css.go | 26 | ||||
| -rw-r--r-- | internal/templates/css/syntax_dark.css | 81 | ||||
| -rw-r--r-- | internal/templates/css/syntax_light.css | 76 | ||||
| -rw-r--r-- | internal/templates/templates.go | 6 |
4 files changed, 165 insertions, 24 deletions
diff --git a/internal/generator/css.go b/internal/generator/css.go index 99efa3f..9925d2a 100644 --- a/internal/generator/css.go +++ b/internal/generator/css.go @@ -3,10 +3,6 @@ package generator import ( "os" "path/filepath" - "strings" - - "github.com/alecthomas/chroma/v2/formatters/html" - "github.com/alecthomas/chroma/v2/styles" "mokhan.ca/antonmedv/gitmal/internal/templates" ) @@ -45,29 +41,11 @@ func writeMarkdownCSS(cssDir string) error { } func writeSyntaxCSS(cssDir string) error { - formatter := html.New( - html.WithLineNumbers(true), - html.WithLinkableLineNumbers(true, "L"), - html.WithClasses(true), - html.WithCSSComments(false), - ) - lightStyle := styles.Get("github") - darkStyle := styles.Get("github-dark") - - var light, dark strings.Builder - _ = formatter.WriteCSS(&light, lightStyle) - _ = formatter.WriteCSS(&dark, darkStyle) - - diffCSS := ".chroma .gi { display: block; }\n.chroma .gd { display: block; }\n" - css := "@media (prefers-color-scheme: light) {\n" + - light.String() + - diffCSS + + templates.CSSSyntaxLight + "\n}\n" + "@media (prefers-color-scheme: dark) {\n" + - dark.String() + - diffCSS + + templates.CSSSyntaxDark + "\n}" - return os.WriteFile(filepath.Join(cssDir, "syntax.css"), []byte(css), 0o644) } diff --git a/internal/templates/css/syntax_dark.css b/internal/templates/css/syntax_dark.css new file mode 100644 index 0000000..036102c --- /dev/null +++ b/internal/templates/css/syntax_dark.css @@ -0,0 +1,81 @@ +/* Background */ .bg { color: #e6edf3; background-color: #0d1117; } +/* PreWrapper */ .chroma { color: #e6edf3; background-color: #0d1117; } +/* LineNumbers targeted by URL anchor */ .chroma .ln:target { color: #e6edf3; background-color: #6e7681 } +/* LineNumbersTable targeted by URL anchor */ .chroma .lnt:target { color: #e6edf3; background-color: #6e7681 } +/* Error */ .chroma .err { color: #f85149 } +/* LineLink */ .chroma .lnlinks { outline: none; text-decoration: none; color: inherit } +/* LineTableTD */ .chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; } +/* LineTable */ .chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; } +/* LineHighlight */ .chroma .hl { background-color: #6e7681 } +/* LineNumbersTable */ .chroma .lnt { white-space: pre; -webkit-user-select: none; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #737679 } +/* LineNumbers */ .chroma .ln { white-space: pre; -webkit-user-select: none; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #6e7681 } +/* Line */ .chroma .line { display: flex; } +/* Keyword */ .chroma .k { color: #ff7b72 } +/* KeywordConstant */ .chroma .kc { color: #79c0ff } +/* KeywordDeclaration */ .chroma .kd { color: #ff7b72 } +/* KeywordNamespace */ .chroma .kn { color: #ff7b72 } +/* KeywordPseudo */ .chroma .kp { color: #79c0ff } +/* KeywordReserved */ .chroma .kr { color: #ff7b72 } +/* KeywordType */ .chroma .kt { color: #ff7b72 } +/* NameClass */ .chroma .nc { color: #f0883e; font-weight: bold } +/* NameConstant */ .chroma .no { color: #79c0ff; font-weight: bold } +/* NameDecorator */ .chroma .nd { color: #d2a8ff; font-weight: bold } +/* NameEntity */ .chroma .ni { color: #ffa657 } +/* NameException */ .chroma .ne { color: #f0883e; font-weight: bold } +/* NameLabel */ .chroma .nl { color: #79c0ff; font-weight: bold } +/* NameNamespace */ .chroma .nn { color: #ff7b72 } +/* NameProperty */ .chroma .py { color: #79c0ff } +/* NameTag */ .chroma .nt { color: #7ee787 } +/* NameVariable */ .chroma .nv { color: #79c0ff } +/* NameVariableClass */ .chroma .vc { color: #79c0ff } +/* NameVariableGlobal */ .chroma .vg { color: #79c0ff } +/* NameVariableInstance */ .chroma .vi { color: #79c0ff } +/* NameVariableMagic */ .chroma .vm { color: #79c0ff } +/* NameFunction */ .chroma .nf { color: #d2a8ff; font-weight: bold } +/* NameFunctionMagic */ .chroma .fm { color: #d2a8ff; font-weight: bold } +/* Literal */ .chroma .l { color: #a5d6ff } +/* LiteralDate */ .chroma .ld { color: #79c0ff } +/* LiteralString */ .chroma .s { color: #a5d6ff } +/* LiteralStringAffix */ .chroma .sa { color: #79c0ff } +/* LiteralStringBacktick */ .chroma .sb { color: #a5d6ff } +/* LiteralStringChar */ .chroma .sc { color: #a5d6ff } +/* LiteralStringDelimiter */ .chroma .dl { color: #79c0ff } +/* LiteralStringDoc */ .chroma .sd { color: #a5d6ff } +/* LiteralStringDouble */ .chroma .s2 { color: #a5d6ff } +/* LiteralStringEscape */ .chroma .se { color: #79c0ff } +/* LiteralStringHeredoc */ .chroma .sh { color: #79c0ff } +/* LiteralStringInterpol */ .chroma .si { color: #a5d6ff } +/* LiteralStringOther */ .chroma .sx { color: #a5d6ff } +/* LiteralStringRegex */ .chroma .sr { color: #79c0ff } +/* LiteralStringSingle */ .chroma .s1 { color: #a5d6ff } +/* LiteralStringSymbol */ .chroma .ss { color: #a5d6ff } +/* LiteralNumber */ .chroma .m { color: #a5d6ff } +/* LiteralNumberBin */ .chroma .mb { color: #a5d6ff } +/* LiteralNumberFloat */ .chroma .mf { color: #a5d6ff } +/* LiteralNumberHex */ .chroma .mh { color: #a5d6ff } +/* LiteralNumberInteger */ .chroma .mi { color: #a5d6ff } +/* LiteralNumberIntegerLong */ .chroma .il { color: #a5d6ff } +/* LiteralNumberOct */ .chroma .mo { color: #a5d6ff } +/* Operator */ .chroma .o { color: #ff7b72; font-weight: bold } +/* OperatorWord */ .chroma .ow { color: #ff7b72; font-weight: bold } +/* Comment */ .chroma .c { color: #8b949e; font-style: italic } +/* CommentHashbang */ .chroma .ch { color: #8b949e; font-style: italic } +/* CommentMultiline */ .chroma .cm { color: #8b949e; font-style: italic } +/* CommentSingle */ .chroma .c1 { color: #8b949e; font-style: italic } +/* CommentSpecial */ .chroma .cs { color: #8b949e; font-weight: bold; font-style: italic } +/* CommentPreproc */ .chroma .cp { color: #8b949e; font-weight: bold; font-style: italic } +/* CommentPreprocFile */ .chroma .cpf { color: #8b949e; font-weight: bold; font-style: italic } +/* GenericDeleted */ .chroma .gd { color: #ffa198; background-color: #490202 } +/* GenericEmph */ .chroma .ge { font-style: italic } +/* GenericError */ .chroma .gr { color: #ffa198 } +/* GenericHeading */ .chroma .gh { color: #79c0ff; font-weight: bold } +/* GenericInserted */ .chroma .gi { color: #56d364; background-color: #0f5323 } +/* GenericOutput */ .chroma .go { color: #8b949e } +/* GenericPrompt */ .chroma .gp { color: #8b949e } +/* GenericStrong */ .chroma .gs { font-weight: bold } +/* GenericSubheading */ .chroma .gu { color: #79c0ff } +/* GenericTraceback */ .chroma .gt { color: #ff7b72 } +/* GenericUnderline */ .chroma .gl { text-decoration: underline } +/* TextWhitespace */ .chroma .w { color: #6e7681 } +.chroma .gi { display: block; } +.chroma .gd { display: block; } diff --git a/internal/templates/css/syntax_light.css b/internal/templates/css/syntax_light.css new file mode 100644 index 0000000..74c411e --- /dev/null +++ b/internal/templates/css/syntax_light.css @@ -0,0 +1,76 @@ +/* Background */ .bg { background-color: #ffffff; } +/* PreWrapper */ .chroma { background-color: #ffffff; } +/* LineNumbers targeted by URL anchor */ .chroma .ln:target { background-color: #e5e5e5 } +/* LineNumbersTable targeted by URL anchor */ .chroma .lnt:target { background-color: #e5e5e5 } +/* Error */ .chroma .err { color: #f6f8fa; background-color: #82071e } +/* LineLink */ .chroma .lnlinks { outline: none; text-decoration: none; color: inherit } +/* LineTableTD */ .chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; } +/* LineTable */ .chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; } +/* LineHighlight */ .chroma .hl { background-color: #e5e5e5 } +/* LineNumbersTable */ .chroma .lnt { white-space: pre; -webkit-user-select: none; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f } +/* LineNumbers */ .chroma .ln { white-space: pre; -webkit-user-select: none; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f } +/* Line */ .chroma .line { display: flex; } +/* Keyword */ .chroma .k { color: #cf222e } +/* KeywordConstant */ .chroma .kc { color: #cf222e } +/* KeywordDeclaration */ .chroma .kd { color: #cf222e } +/* KeywordNamespace */ .chroma .kn { color: #cf222e } +/* KeywordPseudo */ .chroma .kp { color: #cf222e } +/* KeywordReserved */ .chroma .kr { color: #cf222e } +/* KeywordType */ .chroma .kt { color: #cf222e } +/* NameAttribute */ .chroma .na { color: #1f2328 } +/* NameClass */ .chroma .nc { color: #1f2328 } +/* NameConstant */ .chroma .no { color: #0550ae } +/* NameDecorator */ .chroma .nd { color: #0550ae } +/* NameEntity */ .chroma .ni { color: #6639ba } +/* NameLabel */ .chroma .nl { color: #990000; font-weight: bold } +/* NameNamespace */ .chroma .nn { color: #24292e } +/* NameOther */ .chroma .nx { color: #1f2328 } +/* NameTag */ .chroma .nt { color: #0550ae } +/* NameBuiltin */ .chroma .nb { color: #6639ba } +/* NameBuiltinPseudo */ .chroma .bp { color: #6a737d } +/* NameVariable */ .chroma .nv { color: #953800 } +/* NameVariableClass */ .chroma .vc { color: #953800 } +/* NameVariableGlobal */ .chroma .vg { color: #953800 } +/* NameVariableInstance */ .chroma .vi { color: #953800 } +/* NameVariableMagic */ .chroma .vm { color: #953800 } +/* NameFunction */ .chroma .nf { color: #6639ba } +/* NameFunctionMagic */ .chroma .fm { color: #6639ba } +/* LiteralString */ .chroma .s { color: #0a3069 } +/* LiteralStringAffix */ .chroma .sa { color: #0a3069 } +/* LiteralStringBacktick */ .chroma .sb { color: #0a3069 } +/* LiteralStringChar */ .chroma .sc { color: #0a3069 } +/* LiteralStringDelimiter */ .chroma .dl { color: #0a3069 } +/* LiteralStringDoc */ .chroma .sd { color: #0a3069 } +/* LiteralStringDouble */ .chroma .s2 { color: #0a3069 } +/* LiteralStringEscape */ .chroma .se { color: #0a3069 } +/* LiteralStringHeredoc */ .chroma .sh { color: #0a3069 } +/* LiteralStringInterpol */ .chroma .si { color: #0a3069 } +/* LiteralStringOther */ .chroma .sx { color: #0a3069 } +/* LiteralStringRegex */ .chroma .sr { color: #0a3069 } +/* LiteralStringSingle */ .chroma .s1 { color: #0a3069 } +/* LiteralStringSymbol */ .chroma .ss { color: #032f62 } +/* LiteralNumber */ .chroma .m { color: #0550ae } +/* LiteralNumberBin */ .chroma .mb { color: #0550ae } +/* LiteralNumberFloat */ .chroma .mf { color: #0550ae } +/* LiteralNumberHex */ .chroma .mh { color: #0550ae } +/* LiteralNumberInteger */ .chroma .mi { color: #0550ae } +/* LiteralNumberIntegerLong */ .chroma .il { color: #0550ae } +/* LiteralNumberOct */ .chroma .mo { color: #0550ae } +/* Operator */ .chroma .o { color: #0550ae } +/* OperatorWord */ .chroma .ow { color: #0550ae } +/* Punctuation */ .chroma .p { color: #1f2328 } +/* Comment */ .chroma .c { color: #57606a } +/* CommentHashbang */ .chroma .ch { color: #57606a } +/* CommentMultiline */ .chroma .cm { color: #57606a } +/* CommentSingle */ .chroma .c1 { color: #57606a } +/* CommentSpecial */ .chroma .cs { color: #57606a } +/* CommentPreproc */ .chroma .cp { color: #57606a } +/* CommentPreprocFile */ .chroma .cpf { color: #57606a } +/* GenericDeleted */ .chroma .gd { color: #82071e; background-color: #ffebe9 } +/* GenericEmph */ .chroma .ge { color: #1f2328 } +/* GenericInserted */ .chroma .gi { color: #116329; background-color: #dafbe1 } +/* GenericOutput */ .chroma .go { color: #1f2328 } +/* GenericUnderline */ .chroma .gl { text-decoration: underline } +/* TextWhitespace */ .chroma .w { color: #ffffff } +.chroma .gi { display: block; } +.chroma .gd { display: block; } diff --git a/internal/templates/templates.go b/internal/templates/templates.go index 92b19ee..b5c29d5 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -32,6 +32,12 @@ var CSSMarkdownLight string //go:embed css/markdown_dark.css var CSSMarkdownDark string +//go:embed css/syntax_light.css +var CSSSyntaxLight string + +//go:embed css/syntax_dark.css +var CSSSyntaxDark string + //go:embed layout.gohtml header.gohtml file_tree.gohtml svg.gohtml var layoutContent embed.FS var layout = Must(New("layout").Funcs(funcs).ParseFS(layoutContent, "*.gohtml")) |
