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

directly using injection grammars not working with shiki lazy loading #4341

Closed
4 tasks done
Sun-ZhenXing opened this issue Nov 6, 2024 · 5 comments
Closed
4 tasks done
Labels
has-workaround Has workaround, low priority wont fix

Comments

@Sun-ZhenXing
Copy link

Describe the bug

Cannot render jinja-html:

The language 'jinja-html' is not loaded, falling back to 'txt' for syntax highlighting.

Reproduction

markdown:

```jinja-html
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
  <li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
```

Expected behavior

No warning.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 39.10 GB / 63.69 GB
  Binaries:
    Node: 20.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.4.1 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.3 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.1.28 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Additional context

Use this config dose not work, but the warning disappeared:

import jinjaHtml from 'shiki/dist/langs/jinja-html.mjs'

export default {
  markdown: {
    languages: [
      ...jinjaHtml,
    ],
  },
}

Validations

@Sun-ZhenXing Sun-ZhenXing added the bug: pending triage Maybe a bug, waiting for confirmation label Nov 6, 2024
@brc-dd brc-dd added bug: pending triage Maybe a bug, waiting for confirmation and removed bug: pending triage Maybe a bug, waiting for confirmation labels Nov 6, 2024
@brc-dd
Copy link
Member

brc-dd commented Nov 6, 2024

Hmm, weird, jinja-html grammar is there but it's not part of shikis' bundledLanguages 👀

@brc-dd brc-dd added bug Something isn't working and removed bug: pending triage Maybe a bug, waiting for confirmation labels Nov 6, 2024
@brc-dd brc-dd changed the title Missing many shiki languages when updated to v1.5.0 grammar injections not working with shiki lazy loading Nov 6, 2024
@brc-dd brc-dd added needs more discussion and removed bug Something isn't working labels Nov 6, 2024
@brc-dd
Copy link
Member

brc-dd commented Nov 6, 2024

I don't think injections are even supposed to be used directly. (https://github.com/shikijs/textmate-grammars-themes/blob/main/packages/tm-grammars/README.md#injections)

Why not use just jinja?

@brc-dd brc-dd changed the title grammar injections not working with shiki lazy loading directly using injection grammars not working with shiki lazy loading Nov 6, 2024
@Sun-ZhenXing
Copy link
Author

Sun-ZhenXing commented Nov 7, 2024

I've been using jinja-html without any problems, and it's only with the recent update that I encounter this problem.

Is it possible to have some way of injecting the language that avoids going directly to creating shiki obj?

@brc-dd
Copy link
Member

brc-dd commented Nov 7, 2024

The issue is it was never supposed to work. Those are internal languages. Only top-level languages are meant to be used directly. That's why if you visit https://shiki.style/ you will only see jinja. There is no jinja-html.

It's recommended that you use jinja instead. You can easily find and replace across your project. But if you want to still use jinja-html, you can explicitly load jinja:

import { defineConfig } from 'vitepress'

export default defineConfig({
  markdown: {
    async shikiSetup(highlighter) {
      await highlighter.loadLanguage('jinja')
    }
  }
})

@brc-dd brc-dd added has-workaround Has workaround, low priority wont fix and removed needs more discussion labels Nov 7, 2024
@Sun-ZhenXing
Copy link
Author

Thank you, it worked well.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has-workaround Has workaround, low priority wont fix
Projects
None yet
Development

No branches or pull requests

2 participants