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

Highlight.js Vue Plugin systematically ignores language value passed to it #49

Open
fabricepallaud opened this issue Feb 4, 2024 · 6 comments

Comments

@fabricepallaud
Copy link

fabricepallaud commented Feb 4, 2024

Whether I call the plugin directly from my template section or mount it programmatically and passing to it a language prop value, the language I specify always ends up being ignored by the plugin who instead chooses himself a language.

From template section:

<highlightjs language='javascript' code="var x = 5;" />

From script section (programmatically):

<template>
  <div class="myElement"></div>
</template>

<script setup>
// some code here...

nextTick(() => {
  mount(HighlightPlugin.component, {
    element: document.querySelector('.myElement'),
    props: {
      language: 'javascript',
      code: codeSnippet
    }
  })
})
</script>

Here's how the plugin is imported in my main.js:

import 'highlight.js/styles/github-dark-dimmed.css'
import 'highlight.js/lib/common'
import hljsVuePlugin from '@highlightjs/vue-plugin'
app.use(hljsVuePlugin)

app.mount('#app')
@joshgoebel
Copy link
Member

What languages do you usually see getting chosen?

@fabricepallaud
Copy link
Author

@joshgoebel Javascript and HTML (ideally Vue component too but I don't think that package supports that).

@joshgoebel
Copy link
Member

Maybe add some debugging to output the value of hljs.listLanguages() and see what that returns just to confirm you're loading them all.

@fabricepallaud
Copy link
Author

fabricepallaud commented Feb 10, 2024

Thanks, yep I just console logged that and they do appear to load fine:

Screenshot_35

@artemonsh
Copy link

artemonsh commented Apr 25, 2024

I ran into the same problem

The solution is to pass :autodetect="false" and the language you would like to use language="python"

I found the solution by reading the source code for 1 minute 🤣

@joshgoebel
Copy link
Member

It looks to me (reading source) that setting language should override the autodetect prop, am I missing something?

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

No branches or pull requests

3 participants