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

Code block highlighting is not as expected #7083

Open
Flrande opened this issue May 17, 2024 · 1 comment
Open

Code block highlighting is not as expected #7083

Flrande opened this issue May 17, 2024 · 1 comment
Assignees
Labels
mod:code Module: related to code block type:bug Something isn't working

Comments

@Flrande
Copy link
Member

Flrande commented May 17, 2024

For the following code, the code block highlighting is not as expected.

const a = html`
  <span class="affine-latex" data-selected=${this.selected}
      ><span class="latex-container"></span
      ><v-text .str=${ZERO_WIDTH_NON_JOINER}></v-text
  ></span>
`;
image

The possible reason is that now each delta in the code block is parsed separately. We need to parse them together while maintaining lazy loading for syntax highlighting.

tokens = highlighter.codeToTokensBase(this.delta.insert, {
lang,
theme: mode === 'dark' ? DARK_THEME : LIGHT_THEME,
})[0];
highlightCache.set(cacheKey, tokens);

@Flrande Flrande added type:bug Something isn't working mod:code Module: related to code block labels May 17, 2024
@golok727
Copy link
Contributor

golok727 commented May 22, 2024

Hey @Flrande, I believe storing the ruleStack in a state and passing it to the tokenizer could be a viable solution within our current setup. However, it appears that Shiki doesn't currently support that functionality.

PS: Apologies for the premature closure; my phone glitched.

@golok727 golok727 reopened this May 22, 2024
@Flrande Flrande assigned Flrande and unassigned golok727 May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod:code Module: related to code block type:bug Something isn't working
Projects
Development

No branches or pull requests

2 participants