vue-prism-editor
vue-prism-editor copied to clipboard
"Cannot read property 'rest' of undefined" running code from README
Using the code from the readme I get this error embedding the editor in a nuxt app
Cannot read property 'rest' of undefined
tokenize: function(text, grammar) {
var rest = grammar.rest; // <---------- error here
if (rest) {
for (var token in rest) {
grammar[token] = rest[token];
}
I can see the editor if I adjust the highlighter method to return null, but it looks a bit messed up
any ideas?
the code sample shows up if I adjust prism-core.js like so
tokenize: function(text, grammar) {
if(grammar !== undefined)
{
var rest = grammar.rest;
if (rest) {
for (var token in rest) {
grammar[token] = rest[token];
}
delete grammar.rest;
}
}
but the line numbers don't look great:
For reference I'm running with node v14.17.0
Same issue, doesn't display anything at all
Looking into it, i was getting this error because languages
didn't have the attributes I expected.
e.g. languages.plain isn't an option
Hey! Can you provide an example using codesandbox or stackblitz. Thanks :) i will re-open this issue once you have it.
Hey folks.
These kind of errors appear when you do not wrap your code editor component in <ClientOnly>
.
Check out the nuxtjs example: https://codesandbox.io/s/nuxt-vue-prism-editor-62e06
Hey @surister thanks a lot for the codesandbox link. I will check it and try to fix the issue. I will let you guys know :)