-
Notifications
You must be signed in to change notification settings - Fork 991
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
Syntax highlighting with CSS classes #913
Conversation
It's been done and I'm currently releasing 0.11 with it. You probably want to cherry-pick your commit on top of current master though. |
I didn't mean to close all the PRs by deleting the branch :( |
Will rebase over the weekend :), thanks for your patience |
Rebased to next branch, i will create the documentation in the next days. |
Hi @Keats I'd like to port at least one Sublime syntax highlight theme to Zola. Do you suggest waiting for this PR to be merged? thanks |
You can do a PR now |
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.
That's a very neat feature!
components/config/src/config.rs
Outdated
@@ -154,6 +172,8 @@ pub struct Config { | |||
/// Which themes to use for code highlighting. See Readme for supported themes | |||
/// Defaults to "base16-ocean-dark" | |||
pub highlight_theme: String, | |||
/// Generate CSS files for Thmes out of syntect |
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.
themes
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.
Also renamed the Vector to generate_themes_css
.
components/rendering/src/markdown.rs
Outdated
@@ -216,6 +230,23 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render | |||
if !context.config.highlight_code { | |||
return Event::Html("<pre><code>".into()); | |||
} | |||
if &context.config.highlight_theme == "css" { | |||
//match &SYNTAX_SET.find_syntax_by_extension(info) { |
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.
can be removed?
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.
yes, that was miss on my side
components/site/src/lib.rs
Outdated
@@ -855,6 +864,21 @@ impl Site { | |||
Ok(()) | |||
} | |||
|
|||
pub fn generate_themes(&self) -> Result<()> { |
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.
generate_highlighting_themes
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.
much better name, thanks!
components/site/src/lib.rs
Outdated
pub fn generate_themes(&self) -> Result<()> { | ||
ensure_directory_exists(&self.output_path)?; | ||
for css_theme in &self.config.generate_theme_css { | ||
println!("Generating CSS: {} for theme: {}", css_theme.file, css_theme.theme); |
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.
No need to print.
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.
Good catch, was in for debugging purposes!
|
||
# If the site uses some of the predefined syntax highlighing schemes as | ||
# CSS, you can let Zola generate the CSS. | ||
generate_theme_css = [ |
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.
Hmmm.
I think the inner part is ok, except maybe file -> filename for clarity.
As for generate_theme_css
, I think highlighting_themes_css
is more consistent.
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.
Yepp, much better
Adjusted to Review comments, many thanks for the Review. Should i also squash my commits into one? |
I've just tried it on my site (https://github.com/Keats/vincentprouillet/) and sadly it panics at that line: https://github.com/trishume/syntect/blob/master/src/parsing/scope.rs#L417
This looks like a bug in syntect, I'll see if I can reproduce it/make a PR with a failing test. |
css_highlighter.parse_html_for_line(&line); | ||
} | ||
// swap out highlighter because of borrowing | ||
let sr_rs = &SYNTAX_SET.find_syntax_by_extension("rs").unwrap(); |
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:
match &SYNTAX_SET.find_syntax_by_extension(info) {
EXAMPLES.md
Outdated
@@ -1,36 +1,36 @@ | |||
# Example sites | |||
|
|||
| Site | Source Code | |
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.
can you revert the changes to that file? I would rather have a link yo your blog source in the docs when talking about dark mode example.
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.
Yes, no problem
Sorry for the delay, i was quite busy. I also build my site with the Syntax highlighting theme you tried without problems. BTW: fixed also a typo inside a new commit. We should squash everything before the merge. |
Tested your site, and got the same panic as you:
will try to debug that . |
I investigated a little bit. the first codeblock failing is the json block in 2014-09-19_finding-trending-things.md. It fails, even if i strip it down to
If i strip it down even more, it works fine. I created a test inside syntect with this json which works fine. So a possible culprit is the loaded SyntaxSet. If the loaded SyntaxSet is changed to the SyntaxSet::load_defaults_newlines(); everything work fine without problems. |
Did you manage to reproduce a failing test for syntect? |
Sorry, i was on vacation, i will try it in the next days. |
@uwearzt any updates on this? Would love to use that for my blog as well. 😊 |
Oops, didn't mean to close that sorry |
This is copied from getzola#913 Co-Authored-By: Uwe Arzt <[email protected]>
I'm still learning about Syntect and Zola, but I don't think that this panic is an issue in either of them. I think it's a problem in the JSON syntax definition within Zola's syntax set. ClassedHTMLGenerator doesn't panic on that JSON snippet for either of the newlines or nonewlines default syntax sets within Syntect, but it does when using the Zola syntax set (which I believe is newlines). The Syntect default JSON syntax doesn't produce any clear or restore stack operations while the one in Zola produces a restore operation on a line that it didn't produce a clear for. There is an unmatched clear from a previous line, though, so if that's supposed to work then I guess there's a problem with the No matter what though, until trishume/syntect#307 is merged, I don't think ClassedHTMLGenerator will work for Zola because of the newlines Syntax set. |
This is copied from getzola#913 Co-Authored-By: Uwe Arzt <[email protected]>
This is copied from getzola#913 Co-Authored-By: Uwe Arzt <[email protected]>
This is copied from getzola#913 Co-Authored-By: Uwe Arzt <[email protected]>
This is copied from getzola#913 Co-Authored-By: Uwe Arzt <[email protected]>
Sorry, was busy doing some other stuff. I will rebase the PR to the newest next branch now. Then i will try to fix the issues. |
There is #1242 now that supersedes this PR I think |
This is copied from getzola#913 Co-Authored-By: Uwe Arzt <[email protected]>
Todo