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 content
- Update some highlighting syntaxes and the TS syntax will now be used instead of JS due to issues with it - 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 - 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) ## 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; let mut in_extra = false;
if let Some(ref lang) = language { if let Some(ref lang) = language {
// The JS syntax hangs a lot... the TS syntax is probably better anyway. let syntax = if let Some(ref extra) = config.markdown.extra_syntax_set {
// https://github.com/getzola/zola/issues/1241 let s = extra.find_syntax_by_token(lang);
// https://github.com/getzola/zola/issues/1211 if s.is_some() {
// https://github.com/getzola/zola/issues/1174 in_extra = true;
let hacked_lang = if *lang == "js" || *lang == "javascript" { "ts" } else { lang }; }
let syntax = SYNTAX_SET s
.find_syntax_by_token(hacked_lang) } else {
.or_else(|| { // The JS syntax hangs a lot... the TS syntax is probably better anyway.
if let Some(ref extra) = config.markdown.extra_syntax_set { // https://github.com/getzola/zola/issues/1241
let s = extra.find_syntax_by_token(hacked_lang); // https://github.com/getzola/zola/issues/1211
if s.is_some() { // https://github.com/getzola/zola/issues/1174
in_extra = true; let hacked_lang = if *lang == "js" || *lang == "javascript" { "ts" } else { lang };
println!("Found extra syntax"); SYNTAX_SET.find_syntax_by_token(hacked_lang)
} }.unwrap_or_else(|| SYNTAX_SET.find_syntax_plain_text());
s
} else {
None
}
})
.unwrap_or_else(|| SYNTAX_SET.find_syntax_plain_text());
(HighlightLines::new(syntax, theme), in_extra) (HighlightLines::new(syntax, theme), in_extra)
} else { } else {
(HighlightLines::new(SYNTAX_SET.find_syntax_plain_text(), theme), false) (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 -> ["c", "h"]
- C# -> ["cs", "csx"] - C# -> ["cs", "csx"]
- C++ -> ["C", "c++", "cc", "cp", "cpp", "cxx", "h", "h++", "hh", "hpp", "hxx", "inl", "ipp"] - 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"] - ClojureC -> ["boot", "clj", "cljc", "cljs", "cljx"]
- CMake -> ["CMakeLists.txt", "cmake"] - CMake -> ["CMakeLists.txt", "cmake"]
- CMake C Header -> ["h.in"] - CMake C Header -> ["h.in"]