empress / ember-showdown-prism

https://ember-showdown-prism.netlify.app/
MIT License
11 stars 3 forks source link

Installed in empress-blog app and got `Cannot read property 'rest' of undefined` #1

Closed knownasilya closed 4 years ago

knownasilya commented 4 years ago
There was an error running your app in fastboot. More info about the error: 
 TypeError: Cannot read property 'rest' of undefined
    at Object.tokenize (/var/folders/hq/m0d3mb8s5gd1wdbn_gsk55000000gn/T/broccoli-1217196D9K9wF9ddM/out-363-broccoli_merge_trees/assets/vendor/prismjs/prism.js:340:1)
    at Object.highlight (/var/folders/hq/m0d3mb8s5gd1wdbn_gsk55000000gn/T/broccoli-1217196D9K9wF9ddM/out-363-broccoli_merge_trees/assets/vendor/prismjs/prism.js:334:1)
    at /var/folders/hq/m0d3mb8s5gd1wdbn_gsk55000000gn/T/broccoli-1217196D9K9wF9ddM/out-363-broccoli_merge_trees/assets/addon-tree-output/ember-showdown-prism/initializers/showdown-extension.js:53:1
Screen Shot 2020-05-24 at 3 50 43 PM
knownasilya commented 4 years ago

Looks like highlightedCodeBlock = Prism.highlight(codeblock, Prism.languages[language], language) + end; specifically Prism.languages[language] returns undefined when language is 'hbs'. But the index.js seems to specify the defaults and handlebars is included.

BTW Prism.languages doesn't have 'handlebars' either.

knownasilya commented 4 years ago

So I just pasted the defaults from index.js to my ember-cli-build.js and used 'handlebars' and it works. Not sure why the defaults don't come over.

nickschot commented 4 years ago

Prism does not seem to add/support shorthand aliases by default. handlebars and javascript should work (if their respective components are configured to be enabled) while hbs and js do not.

I've created a PR #5 which makes it clearer that something is not supported instead of having it throw this vague error. It also falls back to non-highlighted code if a language is not found.

I might try integrating it with tests so people can also easily see this when they author a blog just on github for example.

nickschot commented 4 years ago

The above PR has been merged and released as 2.1.0

mansona commented 4 years ago

Hey @knownasilya did you get a chance to test this with the latest version? We're pretty sure that we have fixed it and we have confirmed that it's working on the working branch of the new Ember blog https://deploy-preview-7--ember-blog-legacy.netlify.app/the-emberjs-times-issue-49/

I'm going to close this for now but if you still have the problem please let me know and we can open it again 👍