Skip to content

Commit df22122

Browse files
Highlight.js -> Hugo's chromastyles (adityatelange#1364)
* remove hljs * rename var --hljs-bg to --code-block-bg * bundle chroma-styles from css/includes/chroma-styles.css * add compatibility fixes for papermod <-> chroma * fix line-num and line padding and set width for line container to 100% * After a lot of experimentation this compatiblity should work well * fix inline line highlights not working * Use catppuccin-macchiato as default theme with highlightStyle 'bg:#474733' - hugo gen chromastyles --style catppuccin-macchiato --highlightStyle 'bg:#474733' > assets/css/includes/chroma-styles.css
1 parent 8773ef8 commit df22122

8 files changed

Lines changed: 122 additions & 132 deletions

File tree

assets/css/common/post-single.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155

156156
.post-content .highlight:not(table) {
157157
margin: 10px auto;
158-
background: var(--hljs-bg) !important;
158+
background: var(--code-block-bg) !important;
159159
border-radius: var(--radius);
160160
direction: ltr;
161161
}
@@ -199,11 +199,11 @@
199199
}
200200

201201
.post-content pre code {
202-
display: block;
202+
display: grid;
203203
margin: auto 0;
204204
padding: 10px;
205205
color: rgb(213, 213, 214);
206-
background: var(--hljs-bg) !important;
206+
background: var(--code-block-bg) !important;
207207
border-radius: var(--radius);
208208
overflow-x: auto;
209209
word-break: break-all;

assets/css/core/theme-vars.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
--secondary: rgb(108, 108, 108);
1313
--tertiary: rgb(214, 214, 214);
1414
--content: rgb(31, 31, 31);
15-
--hljs-bg: rgb(28, 29, 33);
15+
--code-block-bg: rgb(28, 29, 33);
1616
--code-bg: rgb(245, 245, 245);
1717
--border: rgb(238, 238, 238);
1818
}
@@ -24,7 +24,7 @@
2424
--secondary: rgb(155, 156, 157);
2525
--tertiary: rgb(65, 66, 68);
2626
--content: rgb(196, 196, 197);
27-
--hljs-bg: rgb(46, 46, 51);
27+
--code-block-bg: rgb(46, 46, 51);
2828
--code-bg: rgb(55, 56, 62);
2929
--border: rgb(51, 51, 51);
3030
}

assets/css/hljs/an-old-hope.min.css

Lines changed: 0 additions & 63 deletions
This file was deleted.

assets/css/includes/chroma-mod.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.chroma {
2+
background-color: unset !important;
3+
}
4+
5+
.chroma .hl {
6+
display: flex;
7+
}
8+
9+
.chroma .lnt {
10+
padding: 0 0 0 12px;
11+
}
12+
13+
.highlight pre.chroma code {
14+
padding: 8px 0;
15+
}
16+
17+
.highlight pre.chroma .line .cl,
18+
.chroma .ln {
19+
padding: 0 10px;
20+
}
21+
22+
.chroma .lntd:last-of-type {
23+
width: 100%;
24+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* Background */ .bg { color: #cad3f5; background-color: #24273a; }
2+
/* PreWrapper */ .chroma { color: #cad3f5; background-color: #24273a; }
3+
/* Other */ .chroma .x { }
4+
/* Error */ .chroma .err { color: #ed8796 }
5+
/* CodeLine */ .chroma .cl { }
6+
/* LineLink */ .chroma .lnlinks { outline: none; text-decoration: none; color: inherit }
7+
/* LineTableTD */ .chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; }
8+
/* LineTable */ .chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; }
9+
/* LineHighlight */ .chroma .hl { background-color: #474733 }
10+
/* 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: #8087a2 }
11+
/* 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: #8087a2 }
12+
/* Line */ .chroma .line { display: flex; }
13+
/* Keyword */ .chroma .k { color: #c6a0f6 }
14+
/* KeywordConstant */ .chroma .kc { color: #f5a97f }
15+
/* KeywordDeclaration */ .chroma .kd { color: #ed8796 }
16+
/* KeywordNamespace */ .chroma .kn { color: #8bd5ca }
17+
/* KeywordPseudo */ .chroma .kp { color: #c6a0f6 }
18+
/* KeywordReserved */ .chroma .kr { color: #c6a0f6 }
19+
/* KeywordType */ .chroma .kt { color: #ed8796 }
20+
/* Name */ .chroma .n { }
21+
/* NameAttribute */ .chroma .na { color: #8aadf4 }
22+
/* NameBuiltin */ .chroma .nb { color: #91d7e3 }
23+
/* NameBuiltinPseudo */ .chroma .bp { color: #91d7e3 }
24+
/* NameClass */ .chroma .nc { color: #eed49f }
25+
/* NameConstant */ .chroma .no { color: #eed49f }
26+
/* NameDecorator */ .chroma .nd { color: #8aadf4; font-weight: bold }
27+
/* NameEntity */ .chroma .ni { color: #8bd5ca }
28+
/* NameException */ .chroma .ne { color: #f5a97f }
29+
/* NameFunction */ .chroma .nf { color: #8aadf4 }
30+
/* NameFunctionMagic */ .chroma .fm { color: #8aadf4 }
31+
/* NameLabel */ .chroma .nl { color: #91d7e3 }
32+
/* NameNamespace */ .chroma .nn { color: #f5a97f }
33+
/* NameOther */ .chroma .nx { }
34+
/* NameProperty */ .chroma .py { color: #f5a97f }
35+
/* NameTag */ .chroma .nt { color: #c6a0f6 }
36+
/* NameVariable */ .chroma .nv { color: #f4dbd6 }
37+
/* NameVariableClass */ .chroma .vc { color: #f4dbd6 }
38+
/* NameVariableGlobal */ .chroma .vg { color: #f4dbd6 }
39+
/* NameVariableInstance */ .chroma .vi { color: #f4dbd6 }
40+
/* NameVariableMagic */ .chroma .vm { color: #f4dbd6 }
41+
/* Literal */ .chroma .l { }
42+
/* LiteralDate */ .chroma .ld { }
43+
/* LiteralString */ .chroma .s { color: #a6da95 }
44+
/* LiteralStringAffix */ .chroma .sa { color: #ed8796 }
45+
/* LiteralStringBacktick */ .chroma .sb { color: #a6da95 }
46+
/* LiteralStringChar */ .chroma .sc { color: #a6da95 }
47+
/* LiteralStringDelimiter */ .chroma .dl { color: #8aadf4 }
48+
/* LiteralStringDoc */ .chroma .sd { color: #6e738d }
49+
/* LiteralStringDouble */ .chroma .s2 { color: #a6da95 }
50+
/* LiteralStringEscape */ .chroma .se { color: #8aadf4 }
51+
/* LiteralStringHeredoc */ .chroma .sh { color: #6e738d }
52+
/* LiteralStringInterpol */ .chroma .si { color: #a6da95 }
53+
/* LiteralStringOther */ .chroma .sx { color: #a6da95 }
54+
/* LiteralStringRegex */ .chroma .sr { color: #8bd5ca }
55+
/* LiteralStringSingle */ .chroma .s1 { color: #a6da95 }
56+
/* LiteralStringSymbol */ .chroma .ss { color: #a6da95 }
57+
/* LiteralNumber */ .chroma .m { color: #f5a97f }
58+
/* LiteralNumberBin */ .chroma .mb { color: #f5a97f }
59+
/* LiteralNumberFloat */ .chroma .mf { color: #f5a97f }
60+
/* LiteralNumberHex */ .chroma .mh { color: #f5a97f }
61+
/* LiteralNumberInteger */ .chroma .mi { color: #f5a97f }
62+
/* LiteralNumberIntegerLong */ .chroma .il { color: #f5a97f }
63+
/* LiteralNumberOct */ .chroma .mo { color: #f5a97f }
64+
/* Operator */ .chroma .o { color: #91d7e3; font-weight: bold }
65+
/* OperatorWord */ .chroma .ow { color: #91d7e3; font-weight: bold }
66+
/* Punctuation */ .chroma .p { }
67+
/* Comment */ .chroma .c { color: #6e738d; font-style: italic }
68+
/* CommentHashbang */ .chroma .ch { color: #6e738d; font-style: italic }
69+
/* CommentMultiline */ .chroma .cm { color: #6e738d; font-style: italic }
70+
/* CommentSingle */ .chroma .c1 { color: #6e738d; font-style: italic }
71+
/* CommentSpecial */ .chroma .cs { color: #6e738d; font-style: italic }
72+
/* CommentPreproc */ .chroma .cp { color: #6e738d; font-style: italic }
73+
/* CommentPreprocFile */ .chroma .cpf { color: #6e738d; font-weight: bold; font-style: italic }
74+
/* Generic */ .chroma .g { }
75+
/* GenericDeleted */ .chroma .gd { color: #ed8796; background-color: #363a4f }
76+
/* GenericEmph */ .chroma .ge { font-style: italic }
77+
/* GenericError */ .chroma .gr { color: #ed8796 }
78+
/* GenericHeading */ .chroma .gh { color: #f5a97f; font-weight: bold }
79+
/* GenericInserted */ .chroma .gi { color: #a6da95; background-color: #363a4f }
80+
/* GenericOutput */ .chroma .go { }
81+
/* GenericPrompt */ .chroma .gp { }
82+
/* GenericStrong */ .chroma .gs { font-weight: bold }
83+
/* GenericSubheading */ .chroma .gu { color: #f5a97f; font-weight: bold }
84+
/* GenericTraceback */ .chroma .gt { color: #ed8796 }
85+
/* GenericUnderline */ .chroma .gl { text-decoration: underline }
86+
/* TextWhitespace */ .chroma .w { }

assets/css/includes/scroll-bar.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232

3333
.post-content :not(table) ::-webkit-scrollbar-thumb {
34-
border: 2px solid var(--hljs-bg);
34+
border: 2px solid var(--code-block-bg);
3535
background: rgb(113, 113, 117);
3636
}
3737

@@ -60,4 +60,4 @@
6060
width: 19px;
6161
height: 11px;
6262
}
63-
}
63+
}

assets/js/highlight.min.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

layouts/partials/head.html

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
{{- $license_css := (resources.Get "css/core/license.css") }}
5656
{{- $common := (resources.Match "css/common/*.css") | resources.Concat "assets/css/common.css" }}
5757

58-
{{- /* include `an-old-hope` if hljs is on */}}
59-
{{- $isHLJSdisabled := (site.Params.assets.disableHLJS | default false) }}
60-
{{- $hljs := (cond ($isHLJSdisabled) (".chroma { background-color: unset !important;}" | resources.FromString "assets/css/hljs-blank.css") (resources.Get "css/hljs/an-old-hope.min.css")) }}
58+
{{- /* markup.highlight.noClasses should be set to `false` */}}
59+
{{- $chroma_styles := (resources.Get "css/includes/chroma-styles.css") }}
60+
{{- $chroma_mod := (resources.Get "css/includes/chroma-mod.css") }}
6161

6262
{{- /* order is important */}}
63-
{{- $core := (slice $theme_vars $reset $common $hljs $includes_all $media) | resources.Concat "assets/css/core.css" | resources.Minify }}
63+
{{- $core := (slice $theme_vars $reset $common $chroma_styles $chroma_mod $includes_all $media) | resources.Concat "assets/css/core.css" | resources.Minify }}
6464
{{- $extended := (resources.Match "css/extended/*.css") | resources.Concat "assets/css/extended.css" | resources.Minify }}
6565

6666
{{- /* bundle all required css */}}
@@ -89,19 +89,6 @@
8989
{{- end }}
9090
{{- end -}}
9191

92-
{{- /* Highlight.js */}}
93-
{{- $isHLJSdisabled := (site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
94-
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
95-
{{- if not site.Params.assets.disableFingerprinting }}
96-
{{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | fingerprint }}
97-
<script defer crossorigin="anonymous" src="{{ $highlight.RelPermalink }}" integrity="{{ $highlight.Data.Integrity }}"
98-
onload="hljs.initHighlightingOnLoad();"></script>
99-
{{- else }}
100-
{{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" }}
101-
<script defer crossorigin="anonymous" src="{{ $highlight.RelPermalink }}" onload="hljs.initHighlightingOnLoad();"></script>
102-
{{- end }}
103-
{{- end }}
104-
10592
{{- /* Favicons */}}
10693
<link rel="icon" href="{{ site.Params.assets.favicon | default "favicon.ico" | absURL }}">
10794
<link rel="icon" type="image/png" sizes="16x16" href="{{ site.Params.assets.favicon16x16 | default "favicon-16x16.png" | absURL }}">
@@ -137,7 +124,7 @@
137124
--secondary: rgb(155, 156, 157);
138125
--tertiary: rgb(65, 66, 68);
139126
--content: rgb(196, 196, 197);
140-
--hljs-bg: rgb(46, 46, 51);
127+
--code-block-bg: rgb(46, 46, 51);
141128
--code-bg: rgb(55, 56, 62);
142129
--border: rgb(51, 51, 51);
143130
}

0 commit comments

Comments
 (0)