vue-plugin icon indicating copy to clipboard operation
vue-plugin copied to clipboard

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

Open fabricepallaud opened this issue 1 year ago • 6 comments

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')

fabricepallaud avatar Feb 04 '24 20:02 fabricepallaud

What languages do you usually see getting chosen?

joshgoebel avatar Feb 10 '24 18:02 joshgoebel

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

fabricepallaud avatar Feb 10 '24 22:02 fabricepallaud

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

joshgoebel avatar Feb 10 '24 22:02 joshgoebel

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

Screenshot_35

fabricepallaud avatar Feb 10 '24 22:02 fabricepallaud

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 🤣

artemonsh avatar Apr 25 '24 19:04 artemonsh

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

joshgoebel avatar Apr 26 '24 23:04 joshgoebel