-
Notifications
You must be signed in to change notification settings - Fork 1k
Syntax highlighting with CSS classes #913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
docs/content/documentation/content/css-syntax-highlighting.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
+++ | ||
title = "CSS Syntax Highlighting" | ||
weight = 80 | ||
+++ | ||
|
||
If you use a highlighting scheme like | ||
|
||
```toml | ||
highlight_theme = "base16-ocean-dark" | ||
``` | ||
|
||
for a code block like | ||
|
||
````md | ||
```rs | ||
let highlight = true; | ||
``` | ||
```` | ||
|
||
you get the colors directly encoded in the html file | ||
|
||
```html | ||
<pre style="background-color:#2b303b;"> | ||
<code> | ||
<span style="color:#b48ead;">let</span> | ||
<span style="color:#c0c5ce;"> highlight = </span> | ||
<span style="color:#d08770;">true</span> | ||
<span style="color:#c0c5ce;">; | ||
</span> | ||
</code> | ||
</pre> | ||
``` | ||
|
||
this is nice, because if everything is inside one file, you get fast | ||
page loadings. But if you would like to have the user choose a theme from a | ||
list, or different color schemes for dark/light color schemes, ou need a | ||
different solution. | ||
|
||
If you use the special color scheme | ||
|
||
```toml | ||
highlight_theme = "css" | ||
``` | ||
|
||
you get CSS class definitions | ||
|
||
```html | ||
<pre class="code"> | ||
<code class="code"> | ||
<span class="source rust"> | ||
<span class="storage type rust">let</span> highlight | ||
<span class="keyword operator assignment rust">=</span> | ||
<span class="constant language rust">true</span> | ||
<span class="punctuation terminator rust">;</span> | ||
</span> | ||
</code> | ||
</pre> | ||
``` | ||
|
||
now you can generate and use CSS either manually or with Zola | ||
|
||
```toml | ||
highlighting_themes_css = [ | ||
{ theme = "base16-ocean-dark", filename = "syntax-theme-dark.css" }, | ||
{ theme = "base16-ocean-light", filename = "syntax-theme-light.css" }, | ||
] | ||
``` | ||
|
||
```css | ||
@import url("syntax-theme-dark.css") (prefers-color-scheme: dark); | ||
@import url("syntax-theme-light.css") (prefers-color-scheme: light); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this only highlighting rust..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the panic is because of that? It's trying to parse a different language than it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point i only need a unused syntax highlighter for swapping it out before calling finalize (We discussed that before).
The highlighter which is used to do the actual highlighting is created in line 239 with the correct syntax set from the codeblock: