Prefer custom syntax before built-in ones

This commit is contained in:
Vincent Prouillet 2020-12-29 10:20:10 +01:00
parent 2362cf2415
commit 7540ecd58e
3 changed files with 16 additions and 21 deletions

View file

@ -19,6 +19,8 @@ into their typographic forms
content
- Update some highlighting syntaxes and the TS syntax will now be used instead of JS due to issues with it
- Remove `zola serve --watch-only`: since we build the HTML in memory and not on disk, it doesn't make sense anymore
- Update clojure syntax
- Prefer extra syntaxes to the default ones if we have a match for language
## 0.12.2 (2020-09-28)

View file

@ -22,26 +22,20 @@ pub fn get_highlighter(language: Option<&str>, config: &Config) -> (HighlightLin
let mut in_extra = false;
if let Some(ref lang) = language {
let syntax = if let Some(ref extra) = config.markdown.extra_syntax_set {
let s = extra.find_syntax_by_token(lang);
if s.is_some() {
in_extra = true;
}
s
} else {
// 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 };
let syntax = SYNTAX_SET
.find_syntax_by_token(hacked_lang)
.or_else(|| {
if let Some(ref extra) = config.markdown.extra_syntax_set {
let s = extra.find_syntax_by_token(hacked_lang);
if s.is_some() {
in_extra = true;
println!("Found extra syntax");
}
s
} else {
None
}
})
.unwrap_or_else(|| SYNTAX_SET.find_syntax_plain_text());
SYNTAX_SET.find_syntax_by_token(hacked_lang)
}.unwrap_or_else(|| SYNTAX_SET.find_syntax_plain_text());
(HighlightLines::new(syntax, theme), in_extra)
} else {
(HighlightLines::new(SYNTAX_SET.find_syntax_plain_text(), theme), false)

View file

@ -35,7 +35,6 @@ Here is a full list of supported languages and their short names:
- C -> ["c", "h"]
- C# -> ["cs", "csx"]
- C++ -> ["C", "c++", "cc", "cp", "cpp", "cxx", "h", "h++", "hh", "hpp", "hxx", "inl", "ipp"]
- Clojure -> ["clj", "cljc", "cljs", "edn"]
- ClojureC -> ["boot", "clj", "cljc", "cljs", "cljx"]
- CMake -> ["CMakeLists.txt", "cmake"]
- CMake C Header -> ["h.in"]