zola
zola copied to clipboard
Extra syntaxes embedding built-in syntaxes fail
Bug Report
Environment
Zola version: 0.41.1
Expected Behavior
I would expect custom syntaxes defined using the extra_syntaxes
system would be able to embed built-in syntaxes as Sublime can.
Current Behavior
Extra syntaxes which embed built-in syntaxes cause Syntect, and in turn Zola, to panic.
Building site...
thread '<unnamed>' panicked at 'Can only call resolve on linked references: ByScope { scope: <source.js>, sub_context: None }', /build/.cargo/registry/src/github.com-1ecc6299db9ec823/syntect-4.6.0/src/parsing/syntax_definition.rs:191:18
Step to reproduce
A minimal reproducing example site can be found here. The key offending lines are the embed references here. Clone this repo and zola serve
to panic.
Discussion
The panic is set off upstream in Syntect here, caused when markup.rs
loads the custom syntaxes.
My understanding is this could be fixed fairly easily, but it may cost a performance hit as the highlighting.rs
's SYNTAX_SET
is precomputed and fixing this would require modifying that approach with one of a few possibilities like:
- Simply have
resolve_syntax_and_theme
convertSYNTAX_SET
back into a builder and load the extra syntaxes there - Modify
SYNTAX_SET
and its precomputation scheme so it only precomputes aSyntaxSetBuilder
, then inresolve_syntax_and_theme
add the extra syntaxes to it and then build at runtime.
It's easy to imagine this could be a costly fix for a fairly niche use-case.
I was able to find a workaround, which is to simply copy the referred-to .sublime-syntax
files from Zola or Sublime's source into my site's custom syntax directories. If this workaround is considered acceptable in the long-term, I think a fine fix would to be simply document this limitation and workaround in the relevant docs.