Ver Fonte

Syntax highlighting automatic color scheme switching (#815)

### Prerequisites

Put an `x` into the box(es) that apply:

- [ ] This pull request fixes a bug.
- [x] This pull request adds a feature.
- [ ] This pull request introduces breaking change.

### Description

This PR accomplishes the following:

- Adds GitHub light and dark syntax highlighting styles to the theme as
baseline (since it is already the 'default' style).
- Automatic syntax highlighting color scheme switching according to the
light and dark theme toggle.
- Syntax highlighting is by default no longer broken for users with a
defined Content Security Policy (CSP) since the CSS files are generated
and included with the theme natively rather than being loaded
externally.
- Allows users to set or override with different styles if needed by
removing `noClasses = false` (which defaults to true) and defining a
`style` under `markup.highlight` in `config.toml`. Alternatively, those
who want to use custom styles (or have a CSP) can simply and easily
override `_syntax.scss` and `_syntax_dark.scss` which now already exist
as a base with their own CSS styles, which also works better with the
theme and supports automatic color scheme switching.

### Issues Resolved

This is a very sane implementation of #331 with sensible defaults and a
good base experience for users who have not explicitly defined a `style`
for `markup.highlight`.

### Checklist

Put an `x` into the box(es) that apply:

#### General

- [x] Describe what changes are being made
- [x] Explain why and how the changes were necessary and implemented
respectively
- [x] Reference issue with `#<ISSUE_NO>` if applicable

#### Resources

- [x] If you have changed any SCSS code, run `make release` to
regenerate all CSS files

#### Contributors

- [x] Add yourself to `CONTRIBUTORS.md` if you aren't on it already
Nour Agha há 2 anos atrás
pai
commit
86ed09e0fe

+ 86 - 0
assets/scss/_syntax.scss

@@ -0,0 +1,86 @@
+/* Background */ .bg { background-color: #ffffff; }
+/* PreWrapper */ .chroma { background-color: #ffffff; }
+/* Other */ .chroma .x {  }
+/* Error */ .chroma .err { color: #a61717; background-color: #e3d2d2 }
+/* CodeLine */ .chroma .cl {  }
+/* 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: #ffffcc }
+/* LineNumbersTable */ .chroma .lnt { white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
+/* LineNumbers */ .chroma .ln { white-space: pre; 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: #000000; font-weight: bold }
+/* KeywordConstant */ .chroma .kc { color: #000000; font-weight: bold }
+/* KeywordDeclaration */ .chroma .kd { color: #000000; font-weight: bold }
+/* KeywordNamespace */ .chroma .kn { color: #000000; font-weight: bold }
+/* KeywordPseudo */ .chroma .kp { color: #000000; font-weight: bold }
+/* KeywordReserved */ .chroma .kr { color: #000000; font-weight: bold }
+/* KeywordType */ .chroma .kt { color: #445588; font-weight: bold }
+/* Name */ .chroma .n {  }
+/* NameAttribute */ .chroma .na { color: #008080 }
+/* NameBuiltin */ .chroma .nb { color: #0086b3 }
+/* NameBuiltinPseudo */ .chroma .bp { color: #999999 }
+/* NameClass */ .chroma .nc { color: #445588; font-weight: bold }
+/* NameConstant */ .chroma .no { color: #008080 }
+/* NameDecorator */ .chroma .nd { color: #3c5d5d; font-weight: bold }
+/* NameEntity */ .chroma .ni { color: #800080 }
+/* NameException */ .chroma .ne { color: #990000; font-weight: bold }
+/* NameFunction */ .chroma .nf { color: #990000; font-weight: bold }
+/* NameFunctionMagic */ .chroma .fm {  }
+/* NameLabel */ .chroma .nl { color: #990000; font-weight: bold }
+/* NameNamespace */ .chroma .nn { color: #555555 }
+/* NameOther */ .chroma .nx {  }
+/* NameProperty */ .chroma .py {  }
+/* NameTag */ .chroma .nt { color: #000080 }
+/* NameVariable */ .chroma .nv { color: #008080 }
+/* NameVariableClass */ .chroma .vc { color: #008080 }
+/* NameVariableGlobal */ .chroma .vg { color: #008080 }
+/* NameVariableInstance */ .chroma .vi { color: #008080 }
+/* NameVariableMagic */ .chroma .vm {  }
+/* Literal */ .chroma .l {  }
+/* LiteralDate */ .chroma .ld {  }
+/* LiteralString */ .chroma .s { color: #dd1144 }
+/* LiteralStringAffix */ .chroma .sa { color: #dd1144 }
+/* LiteralStringBacktick */ .chroma .sb { color: #dd1144 }
+/* LiteralStringChar */ .chroma .sc { color: #dd1144 }
+/* LiteralStringDelimiter */ .chroma .dl { color: #dd1144 }
+/* LiteralStringDoc */ .chroma .sd { color: #dd1144 }
+/* LiteralStringDouble */ .chroma .s2 { color: #dd1144 }
+/* LiteralStringEscape */ .chroma .se { color: #dd1144 }
+/* LiteralStringHeredoc */ .chroma .sh { color: #dd1144 }
+/* LiteralStringInterpol */ .chroma .si { color: #dd1144 }
+/* LiteralStringOther */ .chroma .sx { color: #dd1144 }
+/* LiteralStringRegex */ .chroma .sr { color: #009926 }
+/* LiteralStringSingle */ .chroma .s1 { color: #dd1144 }
+/* LiteralStringSymbol */ .chroma .ss { color: #990073 }
+/* LiteralNumber */ .chroma .m { color: #009999 }
+/* LiteralNumberBin */ .chroma .mb { color: #009999 }
+/* LiteralNumberFloat */ .chroma .mf { color: #009999 }
+/* LiteralNumberHex */ .chroma .mh { color: #009999 }
+/* LiteralNumberInteger */ .chroma .mi { color: #009999 }
+/* LiteralNumberIntegerLong */ .chroma .il { color: #009999 }
+/* LiteralNumberOct */ .chroma .mo { color: #009999 }
+/* Operator */ .chroma .o { color: #000000; font-weight: bold }
+/* OperatorWord */ .chroma .ow { color: #000000; font-weight: bold }
+/* Punctuation */ .chroma .p {  }
+/* Comment */ .chroma .c { color: #999988; font-style: italic }
+/* CommentHashbang */ .chroma .ch { color: #999988; font-style: italic }
+/* CommentMultiline */ .chroma .cm { color: #999988; font-style: italic }
+/* CommentSingle */ .chroma .c1 { color: #999988; font-style: italic }
+/* CommentSpecial */ .chroma .cs { color: #999999; font-weight: bold; font-style: italic }
+/* CommentPreproc */ .chroma .cp { color: #999999; font-weight: bold; font-style: italic }
+/* CommentPreprocFile */ .chroma .cpf { color: #999999; font-weight: bold; font-style: italic }
+/* Generic */ .chroma .g {  }
+/* GenericDeleted */ .chroma .gd { color: #000000; background-color: #ffdddd }
+/* GenericEmph */ .chroma .ge { color: #000000; font-style: italic }
+/* GenericError */ .chroma .gr { color: #aa0000 }
+/* GenericHeading */ .chroma .gh { color: #999999 }
+/* GenericInserted */ .chroma .gi { color: #000000; background-color: #ddffdd }
+/* GenericOutput */ .chroma .go { color: #888888 }
+/* GenericPrompt */ .chroma .gp { color: #555555 }
+/* GenericStrong */ .chroma .gs { font-weight: bold }
+/* GenericSubheading */ .chroma .gu { color: #aaaaaa }
+/* GenericTraceback */ .chroma .gt { color: #aa0000 }
+/* GenericUnderline */ .chroma .gl { text-decoration: underline }
+/* TextWhitespace */ .chroma .w { color: #bbbbbb }

+ 98 - 0
assets/scss/_syntax_dark.scss

@@ -0,0 +1,98 @@
+@mixin syntax_dark {
+  /* Background */ .bg { color: #c9d1d9; background-color: #0d1117; }
+  /* PreWrapper */ .chroma { color: #c9d1d9; background-color: #0d1117; }
+  /* Other */ .chroma .x {  }
+  /* Error */ .chroma .err { color: #f85149 }
+  /* CodeLine */ .chroma .cl {  }
+  /* 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: #ffffcc }
+  /* LineNumbersTable */ .chroma .lnt { white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #64686c }
+  /* LineNumbers */ .chroma .ln { white-space: pre; 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 }
+  /* Name */ .chroma .n {  }
+  /* NameAttribute */ .chroma .na {  }
+  /* NameBuiltin */ .chroma .nb {  }
+  /* NameBuiltinPseudo */ .chroma .bp {  }
+  /* 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 }
+  /* NameFunction */ .chroma .nf { color: #d2a8ff; font-weight: bold }
+  /* NameFunctionMagic */ .chroma .fm {  }
+  /* NameLabel */ .chroma .nl { color: #79c0ff; font-weight: bold }
+  /* NameNamespace */ .chroma .nn { color: #ff7b72 }
+  /* NameOther */ .chroma .nx {  }
+  /* NameProperty */ .chroma .py { color: #79c0ff }
+  /* NameTag */ .chroma .nt { color: #7ee787 }
+  /* NameVariable */ .chroma .nv { color: #79c0ff }
+  /* NameVariableClass */ .chroma .vc {  }
+  /* NameVariableGlobal */ .chroma .vg {  }
+  /* NameVariableInstance */ .chroma .vi {  }
+  /* NameVariableMagic */ .chroma .vm {  }
+  /* 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 }
+  /* Punctuation */ .chroma .p {  }
+  /* 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 }
+  /* Generic */ .chroma .g {  }
+  /* 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 }
+}
+
+body.colorscheme-dark {
+  @include syntax_dark();
+}
+
+body.colorscheme-auto {
+  @media (prefers-color-scheme: dark) {
+    @include syntax_dark();
+  }
+}

+ 1 - 0
assets/scss/coder-dark.scss

@@ -7,3 +7,4 @@
 @import "taxonomies_dark";
 @import "footer_dark";
 @import "float_dark";
+@import "syntax_dark";

+ 1 - 0
assets/scss/coder.scss

@@ -10,3 +10,4 @@
 @import "taxonomies";
 @import "footer";
 @import "float";
+@import "syntax";

+ 3 - 3
docs/configurations.md

@@ -74,16 +74,16 @@ Follow [these steps](https://gohugo.io/content-management/comments/#configure-di
 
 ## Syntax Highlight
 
-The theme uses the Goldmark syntax highlight system. To configure it add to your `config.toml`:
+The theme uses the Goldmark syntax highlight system. GitHub light and dark are set as the default styles. To choose a different style, make sure `noClasses` is not set to false (default is true) and add to your `config.toml`:
 
 ```
 [markup.highlight]
-style = "github-dark"
+style = "monokai"
 ```
 
 All `style` are available [here](https://xyproto.github.io/splash/docs/all.html).
 
-It is also possible to use custom styles with generated CSS files. See [here](https://gohugo.io/content-management/syntax-highlighting/#generate-syntax-highlighter-css).
+Alternatively, it is possible to use custom styles with generated CSS files. See [here](https://gohugo.io/content-management/syntax-highlighting/#generate-syntax-highlighter-css).
 
 ## Theme Parameters
 

+ 1 - 5
exampleSite/config.toml

@@ -9,7 +9,7 @@ enableEmoji = true
 # disqusShortname = "yourdiscussshortname"
 
 [markup.highlight]
-style = "github-dark"
+noClasses = false
 
 [params]
 author = "John Doe"
@@ -66,10 +66,6 @@ customRemoteJS = []
 # [params.cloudflare]
 # token = "token"
 
-# If you want to use Baidu Analytics(https://tongji.baidu.com) for analytics, add this section
-# [params.baidu]
-# token = "token"
-
 # If you want to use Matomo(https://matomo.org) for analytics, add this section
 # [params.matomo]
 # siteID = "ABCDE" # Default value is "1", overwrite this if you are cloud-hosting

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
resources/_gen/assets/scss/scss/coder-dark.scss_1fcd9040f1144c65015c77e7b93bc5ac.content


+ 1 - 1
resources/_gen/assets/scss/scss/coder-dark.scss_1fcd9040f1144c65015c77e7b93bc5ac.json

@@ -1 +1 @@
-{"Target":"css/coder-dark.min.75de71d89fefe379cc001b6f6435f9b06dad86408428254718b48a73ea6d9e5e.css","MediaType":"text/css","Data":{"Integrity":"sha256-dd5x2J/v43nMABtvZDX5sG2thkCEKCVHGLSKc+ptnl4="}}
+{"Target":"css/coder-dark.min.a00e6364bacbc8266ad1cc81230774a1397198f8cfb7bcba29b7d6fcb54ce57f.css","MediaType":"text/css","Data":{"Integrity":"sha256-oA5jZLrLyCZq0cyBIwd0oTlxmPjPt7y6KbfW/LVM5X8="}}

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
resources/_gen/assets/scss/scss/coder.scss_5e1eb8e37c42cdfb6215b61e44dcfa5f.content


+ 1 - 1
resources/_gen/assets/scss/scss/coder.scss_5e1eb8e37c42cdfb6215b61e44dcfa5f.json

@@ -1 +1 @@
-{"Target":"css/coder.min.85656f585fe601450b123ec7c9a997f8488faf7f9e2c81913580c9e2f8c72f82.css","MediaType":"text/css","Data":{"Integrity":"sha256-hWVvWF/mAUULEj7HyamX+EiPr3+eLIGRNYDJ4vjHL4I="}}
+{"Target":"css/coder.min.5adbe72fc41dcfb852215b84695288939b6b606db73238bd3ee936469572fc9c.css","MediaType":"text/css","Data":{"Integrity":"sha256-WtvnL8Qdz7hSIVuEaVKIk5trYG23Mji9Puk2RpVy/Jw="}}

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff