Skip to content

Extra syntaxes embedding built-in syntaxes fail #1678

@ajyoon

Description

@ajyoon

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/git.832008.xyz-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 convert SYNTAX_SET back into a builder and load the extra syntaxes there
  • Modify SYNTAX_SET and its precomputation scheme so it only precomputes a SyntaxSetBuilder, then in resolve_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions