perf(ui): improve code snippet design

- Apply the new syntax color themes
- Center the text in the code snippet header
- Maintaining space to the left of a 3-digit line number or more
This commit is contained in:
Cotes Chung 2023-09-03 20:03:51 +08:00
parent 2a5c184373
commit 4f86b04a84
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
6 changed files with 369 additions and 198 deletions

View file

@ -2,8 +2,8 @@
* The syntax highlight. * The syntax highlight.
*/ */
@import 'colors/light-syntax'; @import 'colors/syntax-light';
@import 'colors/dark-syntax'; @import 'colors/syntax-dark';
html { html {
@media (prefers-color-scheme: light) { @media (prefers-color-scheme: light) {
@ -55,27 +55,35 @@ html {
} }
overflow: auto; overflow: auto;
padding-top: 0.5rem; padding-bottom: 0.75rem;
padding-bottom: 1rem;
pre { pre {
margin-bottom: 0; margin-bottom: 0;
font-size: $code-font-size; font-size: $code-font-size;
line-height: 1.4rem; line-height: 1.4rem;
word-wrap: normal; /* Fixed Safari overflow-x */ word-wrap: normal; /* Fixed Safari overflow-x */
color: var(--code-snippets-color);
} }
table { table {
td pre { td {
overflow: visible; /* Fixed iOS safari overflow-x */ &:first-child {
word-break: normal; /* Fixed iOS safari linenos code break */ display: inline-block;
margin-left: 1rem;
margin-right: 0.75rem;
}
&:last-child {
padding-right: 2rem !important;
}
pre {
overflow: visible; /* Fixed iOS safari overflow-x */
word-break: normal; /* Fixed iOS safari linenos code break */
}
} }
} }
.lineno { .lineno {
padding-right: 0.5rem;
min-width: 2.2rem;
text-align: right; text-align: right;
color: var(--highlight-lineno-color); color: var(--highlight-lineno-color);
-webkit-user-select: none; -webkit-user-select: none;
@ -90,6 +98,7 @@ code {
-webkit-hyphens: none; -webkit-hyphens: none;
-ms-hyphens: none; -ms-hyphens: none;
hyphens: none; hyphens: none;
color: var(--code-color);
&.highlighter-rouge { &.highlighter-rouge {
font-size: $code-font-size; font-size: $code-font-size;
@ -145,6 +154,11 @@ div[class^='language-'] {
border-radius: 0; border-radius: 0;
} }
.highlight {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
} }
/* Hide line numbers for default, console, and terminal code snippets */ /* Hide line numbers for default, console, and terminal code snippets */
@ -153,12 +167,13 @@ div {
&.language-plaintext, &.language-plaintext,
&.language-console, &.language-console,
&.language-terminal { &.language-terminal {
pre.lineno { td:first-child {
display: none; padding: 0 !important;
} margin-right: 0;
td.rouge-code { .lineno {
padding-left: 1.5rem; display: none;
}
} }
} }
} }
@ -166,21 +181,21 @@ div {
.code-header { .code-header {
@extend %no-cursor; @extend %no-cursor;
$code-header-height: 2.25rem;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
height: $code-header-height; height: $code-header-height;
margin-left: 1rem; margin-left: 0.75rem;
margin-right: 0.5rem; margin-right: 0.5rem;
/* the label block */ /* the label block */
span { span {
line-height: $code-header-height;
/* label icon */ /* label icon */
i { i {
font-size: 1rem; font-size: 1rem;
margin-right: 0.5rem; width: $code-icon-width;
color: var(--code-header-icon-color); color: var(--code-header-icon-color);
&.small { &.small {
@ -252,19 +267,25 @@ div {
.code-header { .code-header {
@include ml-mr(0); @include ml-mr(0);
&::before { $dot-margin: calc($code-header-height / 2);
$dot-size: 0.75rem;
$dot-margin: 0.5rem;
&::before {
content: ''; content: '';
display: inline-block; display: inline-block;
margin-left: 1rem; margin-left: $dot-margin;
width: $dot-size; width: $code-dot-size;
height: $dot-size; height: $code-dot-size;
border-radius: 50%; border-radius: 50%;
background-color: var(--code-header-muted-color); background-color: var(--code-header-muted-color);
box-shadow: ($dot-size + $dot-margin) 0 0 var(--code-header-muted-color), box-shadow: ($code-dot-size + $code-dot-gap) 0 0
($dot-size + $dot-margin) * 2 0 0 var(--code-header-muted-color); var(--code-header-muted-color),
($code-dot-size + $code-dot-gap) * 2 0 0
var(--code-header-muted-color);
}
span {
// center the text of label
margin-left: calc(($dot-margin + $code-dot-size) / 2 * -1);
} }
} }
} }

View file

@ -20,6 +20,10 @@ $base-radius: 0.5rem;
/* syntax highlight */ /* syntax highlight */
$code-font-size: 0.85rem !default; $code-font-size: 0.85rem !default;
$code-header-height: 2.25rem;
$code-dot-size: 0.75rem;
$code-dot-gap: 0.5rem;
$code-icon-width: 1.75rem;
/* fonts */ /* fonts */

View file

@ -1,87 +0,0 @@
/*
* The syntax dark mode styles.
*/
@mixin dark-syntax {
--language-border-color: rgba(84, 83, 83, 0.27);
--highlight-bg-color: #252525;
--highlighter-rouge-color: #ff6e4e;
--highlight-lineno-color: #666666;
--inline-code-bg: #272822;
--code-header-text-color: #6a6a6a;
--code-header-muted-color: rgb(60, 60, 60);
--code-header-icon-color: rgb(86, 86, 86);
--clipboard-checked-color: #2bcc2b;
--filepath-text-color: #cacaca;
--code-snippets-color: #c2c2c2;
.highlight .gp {
color: #87939d;
}
/* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */
.highlight pre { background-color: var(--highlight-bg-color); }
.highlight .hll { background-color: var(--highlight-bg-color); }
.highlight .c { color: #938d75; } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010; } /* Error */
.highlight .k { color: #66d9ef; } /* Keyword */
.highlight .l { color: #ae81ff; } /* Literal */
.highlight .n { color: #f8f8f2; } /* Name */
.highlight .o { color: #ff329c; } /* Operator */
.highlight .p { color: #f8f8f2; } /* Punctuation */
.highlight .cm { color: #938d75; } /* Comment.Multiline */
.highlight .cp { color: #938d75; } /* Comment.Preproc */
.highlight .c1 { color: #938d75; } /* Comment.Single */
.highlight .cs { color: #938d75; } /* Comment.Special */
.highlight .ge { color: inherit; font-style: italic; } /* Generic.Emph */
.highlight .gs { font-weight: bold; } /* Generic.Strong */
.highlight .kc { color: #66d9ef; } /* Keyword.Constant */
.highlight .kd { color: #66d9ef; } /* Keyword.Declaration */
.highlight .kn { color: #ff329c; } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef; } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef; } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef; } /* Keyword.Type */
.highlight .ld { color: #e6db74; } /* Literal.Date */
.highlight .m { color: #ae81ff; } /* Literal.Number */
.highlight .s { color: #e6db74; } /* Literal.String */
.highlight .na { color: #a6e22e; } /* Name.Attribute */
.highlight .nb { color: #f8f8f2; } /* Name.Builtin */
.highlight .nc { color: #a6e22e; } /* Name.Class */
.highlight .no { color: #66d9ef; } /* Name.Constant */
.highlight .nd { color: #a6e22e; } /* Name.Decorator */
.highlight .ni { color: #f8f8f2; } /* Name.Entity */
.highlight .ne { color: #a6e22e; } /* Name.Exception */
.highlight .nf { color: #a6e22e; } /* Name.Function */
.highlight .nl { color: #f8f8f2; } /* Name.Label */
.highlight .nn { color: #f8f8f2; } /* Name.Namespace */
.highlight .nx { color: #a6e22e; } /* Name.Other */
.highlight .py { color: #f8f8f2; } /* Name.Property */
.highlight .nt { color: #ff329c; } /* Name.Tag */
.highlight .nv { color: #f8f8f2; } /* Name.Variable */
.highlight .ow { color: #ff329c; } /* Operator.Word */
.highlight .w { color: #f8f8f2; } /* Text.Whitespace */
.highlight .mf { color: #ae81ff; } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff; } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff; } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff; } /* Literal.Number.Oct */
.highlight .sb { color: #e6db74; } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74; } /* Literal.String.Char */
.highlight .sd { color: #e6db74; } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74; } /* Literal.String.Double */
.highlight .se { color: #ae81ff; } /* Literal.String.Escape */
.highlight .sh { color: #e6db74; } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74; } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74; } /* Literal.String.Other */
.highlight .sr { color: #e6db74; } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74; } /* Literal.String.Single */
.highlight .ss { color: #e6db74; } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2; } /* Name.Builtin.Pseudo */
.highlight .vc { color: #f8f8f2; } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2; } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2; } /* Name.Variable.Instance */
.highlight .il { color: #ae81ff; } /* Literal.Number.Integer.Long */
.highlight .gu { color: #938d75; } /* Generic.Subheading & Diff Unified/Comment? */
.highlight .gd { color: #ff329c; background-color: #561c08; } /* Generic.Deleted & Diff Deleted */
.highlight .gi { color: #a6e22e; background-color: #0b5858; } /* Generic.Inserted & Diff Inserted */
}

View file

@ -1,84 +0,0 @@
/*
* The syntax light mode code snippet colors.
*/
@mixin light-syntax {
/* based on: <https://raw.githubusercontent.com/jwarby/pygments-css/master/github.css> */
.highlight .hll { background-color: #ffffcc; }
.highlight .c { color: #717165; font-style: italic; } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2; } /* Error */
.highlight .k { color: #000000; font-weight: bold; } /* Keyword */
.highlight .o { color: #000000; font-weight: bold; } /* Operator */
.highlight .cm { color: #717165; font-style: italic; } /* Comment.Multiline */
.highlight .cp { color: #707070; font-style: italic; } /* Comment.Preproc */
.highlight .c1 { color: #717165; font-style: italic; } /* Comment.Single */
.highlight .cs { color: #707070; font-weight: bold; font-style: italic; } /* Comment.Special */
.highlight .gd { color: #d01040; background-color: #ffdddd; } /* Generic.Deleted */
.highlight .ge { color: #000000; font-style: italic; } /* Generic.Emph */
.highlight .gr { color: #aa0000; } /* Generic.Error */
.highlight .gh { color: #707070; } /* Generic.Heading */
.highlight .gi { color: #005e5e; background-color: #ddffdd; } /* Generic.Inserted */
.highlight .go { color: #707070; } /* Generic.Output */
.highlight .gp { color: #555555; } /* Generic.Prompt */
.highlight .gs { font-weight: bold; } /* Generic.Strong */
.highlight .gu { color: #aaaaaa; } /* Generic.Subheading */
.highlight .gt { color: #aa0000; } /* Generic.Traceback */
.highlight .kc { color: #000000; font-weight: bold; } /* Keyword.Constant */
.highlight .kd { color: #000000; font-weight: bold; } /* Keyword.Declaration */
.highlight .kn { color: #000000; font-weight: bold; } /* Keyword.Namespace */
.highlight .kp { color: #000000; font-weight: bold; } /* Keyword.Pseudo */
.highlight .kr { color: #000000; font-weight: bold; } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold; } /* Keyword.Type */
.highlight .m { color: #009999; } /* Literal.Number */
.highlight .s { color: #d01040; } /* Literal.String */
.highlight .na { color: #005e5e; } /* Name.Attribute */
.highlight .nb { color: #0078a1; } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold; } /* Name.Class */
.highlight .no { color: #005e5e; } /* Name.Constant */
.highlight .nd { color: #3c5d5d; font-weight: bold; } /* Name.Decorator */
.highlight .ni { color: #800080; } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold; } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold; } /* Name.Function */
.highlight .nl { color: #990000; font-weight: bold; } /* Name.Label */
.highlight .nn { color: #555555; } /* Name.Namespace */
.highlight .nt { color: #000080; } /* Name.Tag */
.highlight .nv { color: #005e5e; } /* Name.Variable */
.highlight .ow { color: #000000; font-weight: bold; } /* Operator.Word */
.highlight .w { color: #bbbbbb; } /* Text.Whitespace */
.highlight .mf { color: #009999; } /* Literal.Number.Float */
.highlight .mh { color: #009999; } /* Literal.Number.Hex */
.highlight .mi { color: #009999; } /* Literal.Number.Integer */
.highlight .mo { color: #009999; } /* Literal.Number.Oct */
.highlight .sb { color: #d01040; } /* Literal.String.Backtick */
.highlight .sc { color: #d01040; } /* Literal.String.Char */
.highlight .sd { color: #d01040; } /* Literal.String.Doc */
.highlight .s2 { color: #d01040; } /* Literal.String.Double */
.highlight .se { color: #d01040; } /* Literal.String.Escape */
.highlight .sh { color: #d01040; } /* Literal.String.Heredoc */
.highlight .si { color: #d01040; } /* Literal.String.Interpol */
.highlight .sx { color: #d01040; } /* Literal.String.Other */
.highlight .sr { color: #009926; } /* Literal.String.Regex */
.highlight .s1 { color: #d01040; } /* Literal.String.Single */
.highlight .ss { color: #990073; } /* Literal.String.Symbol */
.highlight .bp { color: #707070; } /* Name.Builtin.Pseudo */
.highlight .vc { color: #005e5e; } /* Name.Variable.Class */
.highlight .vg { color: #005e5e; } /* Name.Variable.Global */
.highlight .vi { color: #005e5e; } /* Name.Variable.Instance */
.highlight .il { color: #009999; } /* Literal.Number.Integer.Long */
/* --- custom light colors --- */
--language-border-color: rgba(172, 169, 169, 0.2);
--highlight-bg-color: #fcfcfc;
--highlighter-rouge-color: #3f596f;
--highlight-lineno-color: #959595;
--inline-code-bg: #f6f6f7;
--code-header-text-color: #a3a3a3;
--code-header-muted-color: #e2e1e1;
--code-header-icon-color: #c9c8c8;
--clipboard-checked-color: #43c743;
--code-snippets-color: #b01662;
[class^='prompt-'] {
--inline-code-bg: #fbfafa;
}
} /* light-syntax */

View file

@ -0,0 +1,138 @@
/*
* The syntax dark mode styles.
*/
@mixin dark-syntax {
--language-border-color: #2d2d2d;
--highlight-bg-color: #151515;
--highlighter-rouge-color: #ff6e4e;
--highlight-lineno-color: #808080;
--inline-code-bg: #272822;
--code-color: #b0b0b0;
--code-header-text-color: #6a6a6a;
--code-header-muted-color: #353535;
--code-header-icon-color: #565656;
--clipboard-checked-color: #2bcc2b;
--filepath-text-color: #cacaca;
.highlight .gp {
color: #87939d;
}
/* --- Syntax highlight theme from `rougify style base16.dark` --- */
.highlight table td {
padding: 5px;
}
.highlight table pre {
margin: 0;
}
.highlight,
.highlight .w {
color: #d0d0d0;
background-color: #151515;
}
.highlight .err {
color: #151515;
background-color: #ac4142;
}
.highlight .c,
.highlight .ch,
.highlight .cd,
.highlight .cm,
.highlight .cpf,
.highlight .c1,
.highlight .cs {
color: #848484;
}
.highlight .cp {
color: #f4bf75;
}
.highlight .nt {
color: #f4bf75;
}
.highlight .o,
.highlight .ow {
color: #d0d0d0;
}
.highlight .p,
.highlight .pi {
color: #d0d0d0;
}
.highlight .gi {
color: #90a959;
}
.highlight .gd {
color: #f08a8b;
background-color: #320000;
}
.highlight .gh {
color: #6a9fb5;
background-color: #151515;
font-weight: bold;
}
.highlight .k,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kv {
color: #aa759f;
}
.highlight .kc {
color: #d28445;
}
.highlight .kt {
color: #d28445;
}
.highlight .kd {
color: #d28445;
}
.highlight .s,
.highlight .sb,
.highlight .sc,
.highlight .dl,
.highlight .sd,
.highlight .s2,
.highlight .sh,
.highlight .sx,
.highlight .s1 {
color: #90a959;
}
.highlight .sa {
color: #aa759f;
}
.highlight .sr {
color: #75b5aa;
}
.highlight .si {
color: #b76d45;
}
.highlight .se {
color: #b76d45;
}
.highlight .nn {
color: #f4bf75;
}
.highlight .nc {
color: #f4bf75;
}
.highlight .no {
color: #f4bf75;
}
.highlight .na {
color: #6a9fb5;
}
.highlight .m,
.highlight .mb,
.highlight .mf,
.highlight .mh,
.highlight .mi,
.highlight .il,
.highlight .mo,
.highlight .mx {
color: #90a959;
}
.highlight .ss {
color: #90a959;
}
}

View file

@ -0,0 +1,179 @@
/*
* The syntax light mode code snippet colors.
*/
@mixin light-syntax {
/* --- custom light colors --- */
--language-border-color: #ececec;
--highlight-bg-color: #f6f8fa;
--highlighter-rouge-color: #3f596f;
--highlight-lineno-color: #9e9e9e;
--inline-code-bg: #f6f6f7;
--code-color: #3a3a3a;
--code-header-text-color: #a3a3a3;
--code-header-muted-color: #e5e5e5;
--code-header-icon-color: #c9c8c8;
--clipboard-checked-color: #43c743;
[class^='prompt-'] {
--inline-code-bg: #fbfafa;
}
/* --- Syntax highlight theme from `rougify style github` --- */
.highlight table td {
padding: 5px;
}
.highlight table pre {
margin: 0;
}
.highlight,
.highlight .w {
color: #24292f;
background-color: #f6f8fa;
}
.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kt,
.highlight .kv {
color: #cf222e;
}
.highlight .gr {
color: #f6f8fa;
}
.highlight .gd {
color: #82071e;
background-color: #ffebe9;
}
.highlight .nb {
color: #953800;
}
.highlight .nc {
color: #953800;
}
.highlight .no {
color: #953800;
}
.highlight .nn {
color: #953800;
}
.highlight .sr {
color: #116329;
}
.highlight .na {
color: #116329;
}
.highlight .nt {
color: #116329;
}
.highlight .gi {
color: #116329;
background-color: #dafbe1;
}
.highlight .kc {
color: #0550ae;
}
.highlight .l,
.highlight .ld,
.highlight .m,
.highlight .mb,
.highlight .mf,
.highlight .mh,
.highlight .mi,
.highlight .il,
.highlight .mo,
.highlight .mx {
color: #0550ae;
}
.highlight .sb {
color: #0550ae;
}
.highlight .bp {
color: #0550ae;
}
.highlight .ne {
color: #0550ae;
}
.highlight .nl {
color: #0550ae;
}
.highlight .py {
color: #0550ae;
}
.highlight .nv,
.highlight .vc,
.highlight .vg,
.highlight .vi,
.highlight .vm {
color: #0550ae;
}
.highlight .o,
.highlight .ow {
color: #0550ae;
}
.highlight .gh {
color: #0550ae;
font-weight: bold;
}
.highlight .gu {
color: #0550ae;
font-weight: bold;
}
.highlight .s,
.highlight .sa,
.highlight .sc,
.highlight .dl,
.highlight .sd,
.highlight .s2,
.highlight .se,
.highlight .sh,
.highlight .sx,
.highlight .s1,
.highlight .ss {
color: #0a3069;
}
.highlight .nd {
color: #8250df;
}
.highlight .nf,
.highlight .fm {
color: #8250df;
}
.highlight .err {
color: #f6f8fa;
background-color: #82071e;
}
.highlight .c,
.highlight .ch,
.highlight .cd,
.highlight .cm,
.highlight .cp,
.highlight .cpf,
.highlight .c1,
.highlight .cs {
color: #68717a;
}
.highlight .gl {
color: #68717a;
}
.highlight .gt {
color: #68717a;
}
.highlight .ni {
color: #24292f;
}
.highlight .si {
color: #24292f;
}
.highlight .ge {
color: #24292f;
font-style: italic;
}
.highlight .gs {
color: #24292f;
font-weight: bold;
}
} /* light-syntax */