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

Prevent spans crossing line boundaries in class-based code block formatter #2237

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

TheOnlyMrCat
Copy link
Contributor

The class-based code block formatter has bad interactions with other line-based highlighting effects (linenos, hl_lines) because the spans it generates cross multiple lines. This patch copies the scope_to_classes function from syntect and uses it to make each line independent of one another when using class-based highlighting.

The SyntaxHighlighter::finalize method has also been removed in this patch, as it has been rendered unnecessary.

This greatly increases the number of <span> tags generated by the formatter, even in code blocks that don't make use of line-based highlighting effects. I would be happy to implement a mechanism to only split the spans when it would otherwise cause problems, and keep the previous nesting behaviour elsewhere.

Fixes #1942

@Keats
Copy link
Collaborator

Keats commented Jul 4, 2023

Thanks. Can you add some test that would fail before this change?

@Keats Keats mentioned this pull request Jul 6, 2023
@TheOnlyMrCat
Copy link
Contributor Author

I've added two snapshot tests for cases that would have exhibited incorrect behaviour (and extended codeblocks' testing framework to allow classed highlighting). Are there other tests that might suit this change better?

@Keats Keats merged commit 1778707 into getzola:next Jul 10, 2023
@Keats
Copy link
Collaborator

Keats commented Jul 10, 2023

Thanks that looks good!

@TheOnlyMrCat TheOnlyMrCat deleted the line-by-line branch July 13, 2023 22:49
peterprototypes pushed a commit to peterprototypes/zola that referenced this pull request Sep 12, 2023
…atter (getzola#2237)

* Prevent spans crossing line boundaries in class formatter

* Add snapshot tests for classed highlighting
technimad pushed a commit to technimad/zola that referenced this pull request Sep 30, 2023
…atter (getzola#2237)

* Prevent spans crossing line boundaries in class formatter

* Add snapshot tests for classed highlighting
Keats pushed a commit that referenced this pull request Dec 18, 2023
…atter (#2237)

* Prevent spans crossing line boundaries in class formatter

* Add snapshot tests for classed highlighting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants