Giter Club home page Giter Club logo

Comments (6)

jGleitz avatar jGleitz commented on June 18, 2024

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.

steven-lury avatar steven-lury commented on June 18, 2024

@jGleitz Hi. Thanks for your reply. Sure myProjec available.

from markdown-it-prism.

GrimmKull avatar GrimmKull commented on June 18, 2024

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.

jGleitz avatar jGleitz commented on June 18, 2024

@GrimmKull do I understand you correctly, that

  1. importing the dependent languages in the right order fixes the problem completely for you, and
  2. 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.

GrimmKull avatar GrimmKull commented on June 18, 2024

@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:

  1. 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'];
}
  1. 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.

jGleitz avatar jGleitz commented on June 18, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.