Comments (6)
Hi @steven-lury, thanks for reporting this! At first glance, this looks like a bug in markdown-it-prism
. However, I will need to investigate to tell you more. Is your code in some repository that I could use to debug this?
I am quite busy at the moment, so please excuse if it takes a little longer until you hear back. I’ll try to investigate as soon as I find the time.
from markdown-it-prism.
@jGleitz Hi. Thanks for your reply. Sure myProjec available.
from markdown-it-prism.
Hi @jGleitz and @steven-lury I've encountered the same problem. Managed to make a workaround as in #28 by adding imports for all languages I need:
import "prismjs/components/prism-bash"
import "prismjs/components/prism-json"
import "prismjs/components/prism-go"
import "prismjs/components/prism-clike"
import "prismjs/components/prism-javascript"
import "prismjs/components/prism-java"
Unfortunately there is still a problem of unimported or unsupported languages. After some googling found this link:
https://youtrack.jetbrains.com/issue/KTOR-1331
stating:
The react-scripts uses webpack 4.44.2 that will wrongly resolve the above path to node_modules/prismjs/components.js instead of node_modules/prismjs/components/index.js because of a bug. Since file components.js does exist, require will return the exported object from that file. We cannot call an object as a function, therefore TypeError.
Hope this helps.
from markdown-it-prism.
@GrimmKull do I understand you correctly, that
- importing the dependent languages in the right order fixes the problem completely for you, and
- if dependent languages are not imported correctly, you get the
TypeError
due to a bug in webpack?
@steven-lury does that help you fix the issue?
from markdown-it-prism.
@jGleitz Not completely. Only if I do not use any other language other than the ones listed and if I do not make a mistake like typing jsn
instead of json
. The problem that _components
resolves to an object which creates the error in line 47 of markdown-it-prism/build/index.js:
(0, _components.default)([lang]);
Tried 2 more things today and this works well enough for me:
- Made sure to explicitly fallback to
clike
for all unimported languages in markdown-it-prism/build/index.js:
if (langObject === undefined) {
// (0, _components.default)([lang]);
// langObject = _prismjs.default.languages[lang];
langObject = _prismjs.default.languages['clike'];
}
- In my code made sure default language is set:
let md = new MarkdownIt().use(MarkdownItPrism, {defaultLanguage: 'clike'})
This takes care of both missing imports and unsupported languages.
from markdown-it-prism.
@GrimmKull the second option is how this plugin is meant to be used if you need a fallback. Hence, I will go ahead and close this issue. Please feel free to open another issue if you have further suggestions for improvement!
from markdown-it-prism.
Related Issues (20)
- The automated release is failing 🚨
- Possible regression in 2.0.0 HOT 2
- It doesn't work with PHP for some reason HOT 1
- Action Required: Fix Renovate Configuration
- `loadPrismLang` doesn't handle dependencies
- Clarify license terms - what is a derived work? HOT 5
- Does Not Work Well With Webpack Applications HOT 5
- markdown-it-prism: after importing Critical dependency issues come out HOT 3
- The automated release is failing 🚨
- Compatibility with markdown-it-attrs HOT 1
- Dependency Dashboard
- v2.0.4 should be a new major release HOT 4
- hope to add types for typescript. HOT 5
- Highlight Inline Code Blocks HOT 7
- The package is not consistent with the npmjs website HOT 1
- Plugins loaded but now working HOT 1
- Cannot use plugins with Vite HOT 2
- If i add languages, everything stop working.
- Not Working In Next.js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-it-prism.