-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby-remark-prismjs failed to highlight cpp code #1917
Comments
I investigated the issue, and here are some info: What Causes the Problem?
gatsby/packages/gatsby-remark-prismjs/src/highlight-code.js Lines 6 to 12 in 9379cbb
but for language Prism.languages.cpp = Prism.languages.extend('c', {
// ....
}) And the extend: function (id, redef) {
// id is 'c', but it is not added to `_.languages` yet,
// so the variable `lang` will be undefined
var lang = _.util.clone(_.languages[id]);
for (var key in redef) {
// Throw an `Cannot read property 'keyword' of undefined` Error!!
lang[key] = redef[key];
}
return lang;
} It throw an How to FixFor
That is: So before loading language component, we should load the extended language component first. But how can we know the language components dependencies? There exist a components.js file in prism, it has the language components dependencies, We can use it. languages: {
// ...
"cpp": {
"title": "C++",
"require": "c",
"owner": "zeitgeist87"
},
// ...
} The fixes won't be hard, I'll send a pull request if you agree with the above. 🤗 |
Ooooo… prism has more layers. Nice! Would love a PR adding support for the extended language stuff! |
@KyleAMathews Oops, It seem the components.js file is only for interval use. It doesn't have a Maybe we can have a copy of the language part? (But we need to keep in sync if prism changes it) |
Copying it in sounds fine. Could you add a make.js script that downloads the file and add the module.exports etc? That way when there is updates it'll be trivial to update the components module. |
Yeah, of course. |
Problem
gatsby-remark-prismjs
failed to highlight the following markdown with cpp code:The result:
and the generated js file:
Env
The text was updated successfully, but these errors were encountered: