Skip to content
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

Let extra_syntaxes_and_themes reference builtin syntaxes #2738

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions components/config/src/config/markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use std::{path::Path, sync::Arc};
use libs::syntect::{
highlighting::{Theme, ThemeSet},
html::css_for_theme_with_class_style,
parsing::{SyntaxSet, SyntaxSetBuilder},
parsing::SyntaxSet,
};
use serde::{Deserialize, Serialize};

use errors::{bail, Result};

use crate::highlighting::{CLASS_STYLE, THEME_SET};
use crate::highlighting::CLASS_STYLE;
use crate::highlighting::SYNTAX_SET;
use crate::highlighting::THEME_SET;

pub const DEFAULT_HIGHLIGHT_THEME: &str = "base16-ocean-dark";

Expand Down Expand Up @@ -99,7 +101,7 @@ impl Markdown {
return Ok((None, None));
}

let mut ss = SyntaxSetBuilder::new();
let mut ss = SYNTAX_SET.clone().into_builder();
let mut ts = ThemeSet::new();
for dir in &self.extra_syntaxes_and_themes {
ss.add_from_folder(base_path.join(dir), true)?;
Expand Down
15 changes: 8 additions & 7 deletions components/config/src/highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ pub fn resolve_syntax_and_theme<'config>(
let theme = config.markdown.get_highlight_theme();

if let Some(ref lang) = language {
if let Some(ref extra_syntaxes) = config.markdown.extra_syntax_set {
if let Some(syntax) = extra_syntaxes.find_syntax_by_token(lang) {
// The JS syntax hangs a lot... the TS syntax is probably better anyway.
// https://github.com/getzola/zola/issues/1241
// https://github.com/getzola/zola/issues/1211
// https://github.com/getzola/zola/issues/1174
let hacked_lang = if *lang == "js" || *lang == "javascript" { "ts" } else { lang };
if let Some(extra_syntaxes) = &config.markdown.extra_syntax_set {
if let Some(syntax) = extra_syntaxes.find_syntax_by_token(hacked_lang) {
return SyntaxAndTheme {
syntax,
syntax_set: extra_syntaxes,
Expand All @@ -51,11 +56,7 @@ pub fn resolve_syntax_and_theme<'config>(
};
}
}
// The JS syntax hangs a lot... the TS syntax is probably better anyway.
// https://github.com/getzola/zola/issues/1241
// https://github.com/getzola/zola/issues/1211
// https://github.com/getzola/zola/issues/1174
let hacked_lang = if *lang == "js" || *lang == "javascript" { "ts" } else { lang };

if let Some(syntax) = SYNTAX_SET.find_syntax_by_token(hacked_lang) {
SyntaxAndTheme {
syntax,
Expand Down
Loading