From 4f86b04a8487ebbf4a6d0d70b0c3ece79e9269f3 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 3 Sep 2023 20:03:51 +0800 Subject: [PATCH] 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 --- _sass/addon/syntax.scss | 75 +++++++++----- _sass/addon/variables.scss | 4 + _sass/colors/dark-syntax.scss | 87 ---------------- _sass/colors/light-syntax.scss | 84 ---------------- _sass/colors/syntax-dark.scss | 138 +++++++++++++++++++++++++ _sass/colors/syntax-light.scss | 179 +++++++++++++++++++++++++++++++++ 6 files changed, 369 insertions(+), 198 deletions(-) delete mode 100644 _sass/colors/dark-syntax.scss delete mode 100644 _sass/colors/light-syntax.scss create mode 100644 _sass/colors/syntax-dark.scss create mode 100644 _sass/colors/syntax-light.scss diff --git a/_sass/addon/syntax.scss b/_sass/addon/syntax.scss index 182b95f..5a58e3f 100644 --- a/_sass/addon/syntax.scss +++ b/_sass/addon/syntax.scss @@ -2,8 +2,8 @@ * The syntax highlight. */ -@import 'colors/light-syntax'; -@import 'colors/dark-syntax'; +@import 'colors/syntax-light'; +@import 'colors/syntax-dark'; html { @media (prefers-color-scheme: light) { @@ -55,27 +55,35 @@ html { } overflow: auto; - padding-top: 0.5rem; - padding-bottom: 1rem; + padding-bottom: 0.75rem; pre { margin-bottom: 0; font-size: $code-font-size; line-height: 1.4rem; word-wrap: normal; /* Fixed Safari overflow-x */ - color: var(--code-snippets-color); } table { - td pre { - overflow: visible; /* Fixed iOS safari overflow-x */ - word-break: normal; /* Fixed iOS safari linenos code break */ + td { + &:first-child { + 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 { - padding-right: 0.5rem; - min-width: 2.2rem; text-align: right; color: var(--highlight-lineno-color); -webkit-user-select: none; @@ -90,6 +98,7 @@ code { -webkit-hyphens: none; -ms-hyphens: none; hyphens: none; + color: var(--code-color); &.highlighter-rouge { font-size: $code-font-size; @@ -145,6 +154,11 @@ div[class^='language-'] { border-radius: 0; } + + .highlight { + border-top-left-radius: 0; + border-top-right-radius: 0; + } } /* Hide line numbers for default, console, and terminal code snippets */ @@ -153,12 +167,13 @@ div { &.language-plaintext, &.language-console, &.language-terminal { - pre.lineno { - display: none; - } + td:first-child { + padding: 0 !important; + margin-right: 0; - td.rouge-code { - padding-left: 1.5rem; + .lineno { + display: none; + } } } } @@ -166,21 +181,21 @@ div { .code-header { @extend %no-cursor; - $code-header-height: 2.25rem; - display: flex; justify-content: space-between; align-items: center; height: $code-header-height; - margin-left: 1rem; + margin-left: 0.75rem; margin-right: 0.5rem; /* the label block */ span { + line-height: $code-header-height; + /* label icon */ i { font-size: 1rem; - margin-right: 0.5rem; + width: $code-icon-width; color: var(--code-header-icon-color); &.small { @@ -252,19 +267,25 @@ div { .code-header { @include ml-mr(0); - &::before { - $dot-size: 0.75rem; - $dot-margin: 0.5rem; + $dot-margin: calc($code-header-height / 2); + &::before { content: ''; display: inline-block; - margin-left: 1rem; - width: $dot-size; - height: $dot-size; + margin-left: $dot-margin; + width: $code-dot-size; + height: $code-dot-size; border-radius: 50%; background-color: var(--code-header-muted-color); - box-shadow: ($dot-size + $dot-margin) 0 0 var(--code-header-muted-color), - ($dot-size + $dot-margin) * 2 0 0 var(--code-header-muted-color); + box-shadow: ($code-dot-size + $code-dot-gap) 0 0 + 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); } } } diff --git a/_sass/addon/variables.scss b/_sass/addon/variables.scss index 0c68281..3d32428 100644 --- a/_sass/addon/variables.scss +++ b/_sass/addon/variables.scss @@ -20,6 +20,10 @@ $base-radius: 0.5rem; /* syntax highlight */ $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 */ diff --git a/_sass/colors/dark-syntax.scss b/_sass/colors/dark-syntax.scss deleted file mode 100644 index f14c520..0000000 --- a/_sass/colors/dark-syntax.scss +++ /dev/null @@ -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 */ -} diff --git a/_sass/colors/light-syntax.scss b/_sass/colors/light-syntax.scss deleted file mode 100644 index e966312..0000000 --- a/_sass/colors/light-syntax.scss +++ /dev/null @@ -1,84 +0,0 @@ -/* - * The syntax light mode code snippet colors. - */ - -@mixin light-syntax { - /* based on: */ - .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 */ diff --git a/_sass/colors/syntax-dark.scss b/_sass/colors/syntax-dark.scss new file mode 100644 index 0000000..b3a1ca5 --- /dev/null +++ b/_sass/colors/syntax-dark.scss @@ -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; + } +} diff --git a/_sass/colors/syntax-light.scss b/_sass/colors/syntax-light.scss new file mode 100644 index 0000000..605689d --- /dev/null +++ b/_sass/colors/syntax-light.scss @@ -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 */